wallet: return broadcast errors from CommitTransaction #36597

Open
pseudoramdom wants to merge 4 commits from commit-transaction-interface into master AGit
pseudoramdom commented 2026-10-21 21:54:15 +00:00 (Migrated from github.com)

Part of https://github.com/bitcoin-core/gui-qml/issues/1008.

The QML GUI shows "Transaction sent" even when the node rejected the transaction, because CWallet::CommitTransaction() only logs the rejection and returns void.
This PR bubbles up the submission result through interfaces::Wallet::commitTransaction() so the GUI can report it.

Key changes

  • Introduce TransactionBroadcastError, holding a TransactionError code and an untranslated message.
  • Commit/Broadcast functions returns Expected<void, TransactionBroadcastError>.
    • Remove TransactionError::OK, a success value in an error enum.
  • Add a SUBMISSION_SKIPPED code for when the wallet doesn't submit the transaction (broadcasting disabled, abandoned, coinbase, confirmed or conflicted). SubmitTxMemoryPoolAndRelay() previously returned false in these cases.

Note

  • Existing callers (wallet RPCs, Qt widgets, fee bumper) ignore the new result, so their behavior and RPC responses don't change.
  • commitBumpTransaction() similarly reports success for a rejected replacement. This will be addressed in a follow-up PR.
  • gui-qml will need to update its interfaces::Wallet mock for the new commitTransaction() signature.
Part of https://github.com/bitcoin-core/gui-qml/issues/1008. The QML GUI shows "Transaction sent" even when the node rejected the transaction, because `CWallet::CommitTransaction()` only logs the rejection and returns `void`. This PR bubbles up the submission result through `interfaces::Wallet::commitTransaction()` so the GUI can report it. #### Key changes - Introduce `TransactionBroadcastError`, holding a `TransactionError` code and an untranslated message. - Commit/Broadcast functions returns `Expected<void, TransactionBroadcastError>`. - Remove `TransactionError::OK`, a success value in an error enum. - Add a `SUBMISSION_SKIPPED` code for when the wallet doesn't submit the transaction (broadcasting disabled, abandoned, coinbase, confirmed or conflicted). `SubmitTxMemoryPoolAndRelay()` previously returned `false` in these cases. #### Note - Existing callers (wallet RPCs, Qt widgets, fee bumper) ignore the new result, so their behavior and RPC responses don't change. - `commitBumpTransaction()` similarly reports success for a rejected replacement. This will be addressed in a follow-up PR. - gui-qml will need to update its `interfaces::Wallet` mock for the new `commitTransaction()` signature.
DrahtBot commented 2026-10-21 21:54:26 +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
Concept ACK w0xlt, Naomi-Gift

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:

  • #36566 (private broadcast: wait synchronously for mempool acceptance by andrewtoth)
  • #36520 (interfaces: Avoid node crashes from invalid Chain IPC calls by ryanofsky)
  • #36481 (wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction by achow101)
  • #36429 ([RFC] Delayed transaction broadcast, minimal by optout21)
  • #36380 (wallet: extend -walletbroadcast to allow initial send only by vasild)
  • #36070 (wallet: Add deriveHDKey interface by PraneethGunas)
  • #36002 (txindex: allow running in pruned mode by andrewtoth)
  • #35786 (wallet: drop spent parents redundant cache invalidation and notification by furszy)
  • #35728 (rpc: Properly throw on internal I/O errors in GetTransaction by maflcko)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #33117 (Interfaces: Expose UTXO Snapshot Loading and Add Progress Notifications by D33r-Gee)

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/36597 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36597.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36597#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 | | ---- | --------- | | Concept ACK | [w0xlt](https://github.com/bitcoin/bitcoin/pull/36597#issuecomment-6327592527), [Naomi-Gift](https://github.com/bitcoin/bitcoin/pull/36597#issuecomment-6342169509) | 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: * [#36566](https://github.com/bitcoin/bitcoin/pull/36566) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36566.svg"></sub> (private broadcast: wait synchronously for mempool acceptance by andrewtoth) * [#36520](https://github.com/bitcoin/bitcoin/pull/36520) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36520.svg"></sub> (interfaces: Avoid node crashes from invalid Chain IPC calls by ryanofsky) * [#36481](https://github.com/bitcoin/bitcoin/pull/36481) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36481.svg"></sub> (wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction by achow101) * [#36429](https://github.com/bitcoin/bitcoin/pull/36429) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36429.svg"></sub> ([RFC] Delayed transaction broadcast, minimal by optout21) * [#36380](https://github.com/bitcoin/bitcoin/pull/36380) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36380.svg"></sub> (wallet: extend -walletbroadcast to allow initial send only by vasild) * [#36070](https://github.com/bitcoin/bitcoin/pull/36070) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36070.svg"></sub> (wallet: Add deriveHDKey interface by PraneethGunas) * [#36002](https://github.com/bitcoin/bitcoin/pull/36002) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36002.svg"></sub> (txindex: allow running in pruned mode by andrewtoth) * [#35786](https://github.com/bitcoin/bitcoin/pull/35786) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35786.svg"></sub> (wallet: drop spent parents redundant cache invalidation and notification by furszy) * [#35728](https://github.com/bitcoin/bitcoin/pull/35728) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35728.svg"></sub> (rpc: Properly throw on internal I/O errors in GetTransaction by maflcko) * [#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) * [#33117](https://github.com/bitcoin/bitcoin/pull/33117) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33117.svg"></sub> (Interfaces: Expose UTXO Snapshot Loading and Add Progress Notifications by D33r-Gee) 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-->
w0xlt commented 2026-10-21 22:06:16 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
First-time contributor

🔵 Suggestion · A failed commit can leave the transaction pending and its inputs reserved

If a caller presents a non-skipped commit error as a failed send, the user may resend while the original transaction remains reserved and can later be rebroadcast; whether gui-qml does this is unverified.

Location: src/interfaces/wallet.h:159 (head).

🔵 Suggestion · Show the detailed rejection reason for PSBT broadcasts

psbtoperationsdialog.cpp:131 still shows only TransactionErrorString(code). It omits result.error().message, which for mempool failures carries the validation reason (e.g. 'mempool min fee not met'). The base discarded err_string the same way, so this is a pre-existing optional improvement.

Location: src/qt/psbtoperationsdialog.cpp:129 (head).

Review coverage was incomplete.


Reviewed: 4e3d16755971 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:7ba49ca38b129bc35f71e566efbd136b17ae87b582376d9eebd04f18959e8274:9b5e0237a3fe9e1d05225291551198f07780ddb92e41e55ade9e98c2687fc127 --> <!-- ralph-base:43a33e513c4044dc01d92e77da76f2e98faaedb5 --> <!-- ralph-head:4e3d1675597173075a7efd9b3905c928b2be8de5 --> <!-- ralph-case:dde1bde19690464c8b594bea3784dbb1933fe234b68d6eeea7a9bd869c1e19f1 --> **🔵 Suggestion · A failed commit can leave the transaction pending and its inputs reserved** If a caller presents a non-skipped commit error as a failed send, the user may resend while the original transaction remains reserved and can later be rebroadcast; whether gui-qml does this is unverified. Location: [`src/interfaces/wallet.h:159`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4e3d1675597173075a7efd9b3905c928b2be8de5/src/interfaces/wallet.h#L159>) (head). **🔵 Suggestion · Show the detailed rejection reason for PSBT broadcasts** psbtoperationsdialog.cpp:131 still shows only TransactionErrorString(code). It omits result.error().message, which for mempool failures carries the validation reason (e.g. 'mempool min fee not met'). The base discarded err_string the same way, so this is a pre-existing optional improvement. Location: [`src/qt/psbtoperationsdialog.cpp:129`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4e3d1675597173075a7efd9b3905c928b2be8de5/src/qt/psbtoperationsdialog.cpp#L129>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`4e3d16755971`](<https://git.fish.foo/bitcoin/bitcoin/commit/4e3d1675597173075a7efd9b3905c928b2be8de5>) · [Full review report](<https://review.fish.foo/traces/36597-4e3d1675597173075a7efd9b3905c928b2be8de5-1821-5.html>) · [Previous reports](<https://review.fish.foo/traces/36597/>) [permalink](<https://review.fish.foo/traces/36597-4e3d1675597173075a7efd9b3905c928b2be8de5-1821-5.html>)
Naomi-Gift commented 2026-10-22 13:38:44 +00:00 (Migrated from github.com)

Concept ACK 4e3d167559

With -walletbroadcast=0, commitTransaction now returns an error (SUBMISSION_SKIPPED), even though the user chose not to broadcast. Will the QML GUI treat that as "saved, not broadcast" rather than as a failure?

Concept ACK 4e3d1675597173075a7efd9b3905c928b2be8de5 With -walletbroadcast=0, commitTransaction now returns an error (SUBMISSION_SKIPPED), even though the user chose not to broadcast. Will the QML GUI treat that as "saved, not broadcast" rather than as a failure?
pseudoramdom commented 2026-10-22 17:44:50 +00:00 (Migrated from github.com)

Concept ACK 4e3d167

With -walletbroadcast=0, commitTransaction now returns an error (SUBMISSION_SKIPPED), even though the user chose not to broadcast. Will the QML GUI treat that as "saved, not broadcast" rather than as a failure?

Yes, that's the intent. SUBMISSION_SKIPPED is a separate code precisely so a caller can differentiate between "the wallet didn't submit it" and "the node rejected it" and act accordingly.

> Concept ACK [4e3d167](https://github.com/bitcoin/bitcoin/commit/4e3d1675597173075a7efd9b3905c928b2be8de5) > > With -walletbroadcast=0, commitTransaction now returns an error (SUBMISSION_SKIPPED), even though the user chose not to broadcast. Will the QML GUI treat that as "saved, not broadcast" rather than as a failure? Yes, that's the intent. `SUBMISSION_SKIPPED` is a separate code precisely so a caller can differentiate between "the wallet didn't submit it" and "the node rejected it" and act accordingly.
maflcko commented 2026-10-23 15:35:31 +00:00 (Migrated from github.com)

Can you explain why this would be needed? If the wallet creates a consensus-invalid (permanently invalid) transaction, that seems like a severe bug that should be fixed instead. If the wallet creates a tx which permanently fails the mempool policy, that seems like an equally severe bug that should be fixed instead. If the wallet creates a tx that undershoots the fee, that seems irrelevant and can equally happen when the tx was accepted to the mempool, but then dropped? If the mempool min fee is 0.677 sat/vB, but the user explicitly asked for a tx at 0.1, it seems like a case that the GUI should not allow or display a warning while creating the tx. Some feedback directly after the tx was created seems misplaced? If this was needed, the feedback could be done async?

Can you explain why this would be needed? If the wallet creates a consensus-invalid (permanently invalid) transaction, that seems like a severe bug that should be fixed instead. If the wallet creates a tx which permanently fails the mempool policy, that seems like an equally severe bug that should be fixed instead. If the wallet creates a tx that undershoots the fee, that seems irrelevant and can equally happen when the tx was accepted to the mempool, but then dropped? If the mempool min fee is 0.677 sat/vB, but the user explicitly asked for a tx at `0.1`, it seems like a case that the GUI should not allow or display a warning while creating the tx. Some feedback directly after the tx was created seems misplaced? If this was needed, the feedback could be done async?
pseudoramdom commented 2026-10-23 18:01:13 +00:00 (Migrated from github.com)

If the wallet creates a consensus-invalid (permanently invalid) transaction, that seems like a severe bug that should be fixed instead. If the wallet creates a tx which permanently fails the mempool policy, that seems like an equally severe bug that should be fixed instead.

The GUI can import a PSBT that spends the wallet's coins, sign it with the wallet and commit it. Its inputs and fee were chosen elsewhere and none of createTransaction()'s checks ran, so a rejection (fee above -maxtxfee, a non-standard output, a mempool conflict) isn't a wallet bug and can't be caught at creation. An early rejection with the reason at commitTransaction() time seems useful.

If the wallet creates a tx that undershoots the fee, that seems irrelevant and can equally happen when the tx was accepted to the mempool, but then dropped? If the mempool min fee is 0.677 sat/vB, but the user explicitly asked for a tx at 0.1, it seems like a case that the GUI should not allow or display a warning while creating the tx.

Partially agree. The GUI should catch this before the user confirms. Currently, it looks like GetMinimumFeeRate() only checks -mintxfee/-minrelaytxfee when the user has set the fee rate manually. Maybe GUI should also check for mempool minimum.

Some feedback directly after the tx was created seems misplaced? If this was needed, the feedback could be done async?

A synchronous error when submission fails right away seems more useful than returning void, which is what we do today.
Async feedback sounds like a good idea. Something the GUI can subscribe to and be notified about (a later eviction). I see it as complementing the sync error rather than replacing it.

> If the wallet creates a consensus-invalid (permanently invalid) transaction, that seems like a severe bug that should be fixed instead. If the wallet creates a tx which permanently fails the mempool policy, that seems like an equally severe bug that should be fixed instead. The GUI can import a PSBT that spends the wallet's coins, sign it with the wallet and commit it. Its inputs and fee were chosen elsewhere and none of `createTransaction()`'s checks ran, so a rejection (fee above `-maxtxfee`, a non-standard output, a mempool conflict) isn't a wallet bug and can't be caught at creation. An early rejection with the reason at `commitTransaction()` time seems useful. > If the wallet creates a tx that undershoots the fee, that seems irrelevant and can equally happen when the tx was accepted to the mempool, but then dropped? If the mempool min fee is 0.677 sat/vB, but the user explicitly asked for a tx at 0.1, it seems like a case that the GUI should not allow or display a warning while creating the tx. Partially agree. The GUI should catch this before the user confirms. Currently, it looks like `GetMinimumFeeRate()` only checks `-mintxfee`/`-minrelaytxfee` when the user has set the fee rate manually. Maybe GUI should also check for mempool minimum. > Some feedback directly after the tx was created seems misplaced? If this was needed, the feedback could be done async? A synchronous error when submission fails right away seems more useful than returning `void`, which is what we do today. Async feedback sounds like a good idea. Something the GUI can subscribe to and be notified about (a later eviction). I see it as complementing the sync error rather than replacing it.
ViniciusCestarii commented 2026-10-23 18:56:56 +00:00 (Migrated from github.com)

I ran some mutation testing on the changed files. One surviving mutant seems relevant here:

Surviving mutant

wallet/interfaces.cpp: returning success on MEMPOOL_REJECTED survives. CommitTransactionErrors covers the rejection on CWallet, but the interface test commit_transaction (the path gui-qml#1008 uses) only covers SUBMISSION_SKIPPED and success.

-        return m_wallet->CommitTransaction(std::move(tx), /*replaces_txid=*/std::nullopt, /*comment=*/std::nullopt, /*comment_to=*/std::nullopt, messages);
+        auto result{m_wallet->CommitTransaction(std::move(tx), /*replaces_txid=*/std::nullopt, /*comment=*/std::nullopt, /*comment_to=*/std::nullopt, messages)};
+        // A transaction rejected by the mempool is still stored in the wallet and will be resubmitted later.
+        if (!result && result.error().code == node::TransactionError::MEMPOOL_REJECTED) return {};
+        return result;
I ran some mutation testing on the changed files. One surviving mutant seems relevant here: <details> <summary>Surviving mutant</summary> `wallet/interfaces.cpp`: returning success on `MEMPOOL_REJECTED` survives. `CommitTransactionErrors` covers the rejection on `CWallet`, but the interface test `commit_transaction` (the path gui-qml#1008 uses) only covers `SUBMISSION_SKIPPED` and success. ```diff - return m_wallet->CommitTransaction(std::move(tx), /*replaces_txid=*/std::nullopt, /*comment=*/std::nullopt, /*comment_to=*/std::nullopt, messages); + auto result{m_wallet->CommitTransaction(std::move(tx), /*replaces_txid=*/std::nullopt, /*comment=*/std::nullopt, /*comment_to=*/std::nullopt, messages)}; + // A transaction rejected by the mempool is still stored in the wallet and will be resubmitted later. + if (!result && result.error().code == node::TransactionError::MEMPOOL_REJECTED) return {}; + return result; ``` </details>
DrahtBot commented 2026-11-03 18:56:16 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
achow101 commented 2026-11-04 23:42:52 +00:00 (Migrated from github.com)

Concept ACK

Concept 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!36597
No description provided.