wallet: handle MiniMiner bump fee calculation failures #34698

Open
shuv-amp wants to merge 1 commit from fix-wallet-bump-fee-error into master AGit
shuv-amp commented 2026-02-28 09:12:00 +00:00 (Migrated from github.com)

Fixes #29711.

When MiniMiner cannot calculate individual bump fees, wallet funding can
index missing bump-fee entries and return map::at to users.

Treat an empty bump-fee map for non-empty requested outpoints as a
calculation failure. Make AvailableCoins return
util::Result<CoinsResult> so transaction creation and sendall can
propagate the wallet error instead of leaking an internal exception.

Add a functional regression test in wallet_spend_unconfirmed.py
covering the large unconfirmed set scenario from #29711. The test checks
auto-selected inputs, manually selected inputs, and sendall, and verifies
that spending succeeds again after mining a block.

Tested:

  • cmake --build build
  • build/bin/test_bitcoin --catch_system_errors=no
  • build/bin/test_bitcoin --run_test=miniminer_tests --catch_system_errors=no
  • build/bin/test_bitcoin --run_test=spend_tests --catch_system_errors=no
  • build/bin/test_bitcoin --run_test=coinselector_tests/bump_fee_test --catch_system_errors=no
  • build/bin/test_bitcoin --run_test=wallet_tests/ListCoinsTest --catch_system_errors=no
  • build/bin/test_bitcoin --run_test=wallet_tests/BasicOutputTypesTest --catch_system_errors=no
  • python3 build/test/functional/test_runner.py wallet_spend_unconfirmed.py wallet_sendall.py wallet_send.py wallet_fundrawtransaction.py wallet_bumpfee.py wallet_create_tx.py wallet_basic.py
  • build/bin/bench_bitcoin -filter='WalletAvailableCoins|WalletCreateTxUseOnlyPresetInputs|WalletCreateTxUsePresetInputsAndCoinSelection' -sanity-check
Fixes #29711. When MiniMiner cannot calculate individual bump fees, wallet funding can index missing bump-fee entries and return `map::at` to users. Treat an empty bump-fee map for non-empty requested outpoints as a calculation failure. Make `AvailableCoins` return `util::Result<CoinsResult>` so transaction creation and `sendall` can propagate the wallet error instead of leaking an internal exception. Add a functional regression test in `wallet_spend_unconfirmed.py` covering the large unconfirmed set scenario from #29711. The test checks auto-selected inputs, manually selected inputs, and `sendall`, and verifies that spending succeeds again after mining a block. Tested: - `cmake --build build` - `build/bin/test_bitcoin --catch_system_errors=no` - `build/bin/test_bitcoin --run_test=miniminer_tests --catch_system_errors=no` - `build/bin/test_bitcoin --run_test=spend_tests --catch_system_errors=no` - `build/bin/test_bitcoin --run_test=coinselector_tests/bump_fee_test --catch_system_errors=no` - `build/bin/test_bitcoin --run_test=wallet_tests/ListCoinsTest --catch_system_errors=no` - `build/bin/test_bitcoin --run_test=wallet_tests/BasicOutputTypesTest --catch_system_errors=no` - `python3 build/test/functional/test_runner.py wallet_spend_unconfirmed.py wallet_sendall.py wallet_send.py wallet_fundrawtransaction.py wallet_bumpfee.py wallet_create_tx.py wallet_basic.py` - `build/bin/bench_bitcoin -filter='WalletAvailableCoins|WalletCreateTxUseOnlyPresetInputs|WalletCreateTxUsePresetInputsAndCoinSelection' -sanity-check`
DrahtBot commented 2026-02-28 09:12:36 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK achow101
Approach ACK laxmanacharya8

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35302 (Silent Payments: Sending (take 2) by Eunovo)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/34698 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/34698.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/34698#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [achow101](https://github.com/bitcoin/bitcoin/pull/34698#issuecomment-5961247592) | | Approach ACK | [laxmanacharya8](https://github.com/bitcoin/bitcoin/pull/34698#issuecomment-7319241363) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
achow101 (Migrated from github.com) reviewed 2026-03-24 22:44:33 +00:00
achow101 (Migrated from github.com) commented 2026-03-24 22:43:57 +00:00

Changing this to be std::optional seems a bit unnecessary to me as it's equivalently easy to check for !empty(). That probably reduces the diff by half.

Changing this to be `std::optional` seems a bit unnecessary to me as it's equivalently easy to check for `!empty()`. That probably reduces the diff by half.
shuv-amp (Migrated from github.com) reviewed 2026-03-25 02:05:26 +00:00
shuv-amp (Migrated from github.com) commented 2026-03-25 02:05:26 +00:00

Makes sense. I'll simplify this by keeping the map return type and detecting failure based on whether entries were produced for all requested outpoints, rather than changing the interface to return std::optional.

Makes sense. I'll simplify this by keeping the map return type and detecting failure based on whether entries were produced for all requested outpoints, rather than changing the interface to return `std::optional`.
achow101 (Migrated from github.com) reviewed 2026-04-30 21:32:41 +00:00
achow101 (Migrated from github.com) commented 2026-04-30 21:32:41 +00:00

I don't think this is the right way to propagate errors out of AvailableCoins. This is already returning CoinsResult which can be extended to include error codes/states, a la ValidationState. Or this could return a util::Result<CoinsResult> to contain the error message on error.

I don't think this is the right way to propagate errors out of `AvailableCoins`. This is already returning `CoinsResult` which can be extended to include error codes/states, a la `ValidationState`. Or this could return a `util::Result<CoinsResult>` to contain the error message on error.
shuv-amp (Migrated from github.com) reviewed 2026-08-19 21:26:32 +00:00
shuv-amp (Migrated from github.com) commented 2026-08-19 21:26:32 +00:00

Took the second option, AvailableCoins now returns util::Result<CoinsResult>

Took the second option, `AvailableCoins` now returns `util::Result<CoinsResult>`
shuv-amp commented 2026-08-19 21:30:02 +00:00 (Migrated from github.com)

Rebased on master.

Changes since the last round of review:

  • AvailableCoins returns util::Result<CoinsResult> rather than reporting through an
    out-parameter, so the error travels with the result.
  • CreateTransactionInternal moves the CoinsResult instead of copying it.
  • Added a comment at both call sites for why an empty bump-fee map means the calculation
    gave up, and comments in the functional test for the cluster limit the scenario relies on.
Rebased on master. Changes since the last round of review: - `AvailableCoins` returns `util::Result<CoinsResult>` rather than reporting through an out-parameter, so the error travels with the result. - `CreateTransactionInternal` moves the `CoinsResult` instead of copying it. - Added a comment at both call sites for why an empty bump-fee map means the calculation gave up, and comments in the functional test for the cluster limit the scenario relies on.
First-time contributor

Base: a829aeaac1aff6cb786aab7d2514b49eb233334b
Head: a34afcd4366dd49b74922486bbce8a3fbd71ed83

Design and approach

Should fee-calculation failure block spends using confirmed coins? (src/wallet/spend.cpp:521, head)

AvailableCoins gathers bump fees for all eligible outpoints before SelectCoins runs. If the combined gathered set exceeds 500 transactions, including across multiple clusters, GatherClusters returns no result and prevents the transaction from proceeding even when coin selection could use confirmed inputs. Could the wallet calculate fees per independent cluster or otherwise keep confirmed coins available when fee calculation for unconfirmed coins fails? This would require additional handling or calculation work, but would avoid blocking otherwise fundable spends. Please clarify whether blocking the entire funding request until the unconfirmed set shrinks is intentional.

Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete. The design review did not complete.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `a829aeaac1aff6cb786aab7d2514b49eb233334b` Head: `a34afcd4366dd49b74922486bbce8a3fbd71ed83` ##### Design and approach **Should fee-calculation failure block spends using confirmed coins?** (src/wallet/spend.cpp:521, head) `AvailableCoins` gathers bump fees for all eligible outpoints before `SelectCoins` runs. If the combined gathered set exceeds 500 transactions, including across multiple clusters, `GatherClusters` returns no result and prevents the transaction from proceeding even when coin selection could use confirmed inputs. Could the wallet calculate fees per independent cluster or otherwise keep confirmed coins available when fee calculation for unconfirmed coins fails? This would require additional handling or calculation work, but would avoid blocking otherwise fundable spends. Please clarify whether blocking the entire funding request until the unconfirmed set shrinks is intentional. Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete. The design review did not complete. [Full review report](<https://review.fish.foo/traces/34698-a34afcd4366dd49b74922486bbce8a3fbd71ed83-277-1.html>)
achow101 commented 2026-10-02 20:48:58 +00:00 (Migrated from github.com)
ACK a34afcd4366dd49b74922486bbce8a3fbd71ed83
DevaanshPathak commented 2026-10-09 06:45:15 +00:00 (Migrated from github.com)

Independent reproduce + review notes

Reproduced on pristine master (Debug) and on v30.2:

  • send #501 ok (mempool size 501)
  • send #502 → error code: -1 / map::at
  • mine 1 block → subsequent send succeeds

Root cause matches the PR: GatherClusters returns empty when size > 500 → MiniMiner not ready → CalculateBumpFees returns empty map → wallet .at() throws. Combined bump-fee path already fails with a descriptive error (nullopt); this PR correctly aligns the individual path via util::Result<CoinsResult>.

Suggestions (non-blocking)

  1. Please keep documenting (or asserting) that MiniMiner returns either a full map or empty — never partial — so empty() && !outpoints.empty() stays a sound failure detector.
  2. Confirm send maps the new util::Error to RPC_WALLET_ERROR (not -1), same as the sendall path in this PR.
  3. The 500+ sequential send functional path is a good end-to-end check; if CI time bites, the new miniminer_tests cluster-501 case already covers the MiniMiner contract tightly.

Approach LGTM relative to achow101's earlier feedback (util::Result + keep map return type). Happy to help with rebase/test-runtime follow-ups if useful.

## Independent reproduce + review notes Reproduced on pristine **master (Debug)** and on **v30.2**: - send #501 ok (mempool size 501) - send #502 → `error code: -1` / `map::at` - mine 1 block → subsequent send succeeds Root cause matches the PR: `GatherClusters` returns empty when size > 500 → `MiniMiner` not ready → `CalculateBumpFees` returns empty map → wallet `.at()` throws. Combined bump-fee path already fails with a descriptive error (`nullopt`); this PR correctly aligns the individual path via `util::Result<CoinsResult>`. ### Suggestions (non-blocking) 1. Please keep documenting (or asserting) that MiniMiner returns either a **full** map or **empty** — never partial — so `empty() && !outpoints.empty()` stays a sound failure detector. 2. Confirm `send` maps the new `util::Error` to `RPC_WALLET_ERROR` (not `-1`), same as the `sendall` path in this PR. 3. The 500+ sequential `send` functional path is a good end-to-end check; if CI time bites, the new `miniminer_tests` cluster-501 case already covers the MiniMiner contract tightly. Approach LGTM relative to achow101's earlier feedback (`util::Result` + keep map return type). Happy to help with rebase/test-runtime follow-ups if useful.
laxmanacharya8 commented 2026-12-01 17:24:09 +00:00 (Migrated from github.com)

Approach ACK

Approach ACK
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!34698
No description provided.