wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction #36481

Open
achow101 wants to merge 3 commits from manual-rebroadcast into master AGit
achow101 commented 2026-10-08 21:41:06 +00:00 (Migrated from github.com)

From the discussion in #36403, it is clear that there needs to be a way for users to rebroadcast a transaction. Currently, the way to do so requires getting the raw transaction, getting the hex, and using sendrawtransaction. This PR adds rebroadcastwallettx RPC that takes a txid to attempt to rebroadcast that single transaction. An action is also added to the GUI menu for each transaction to do the same.

From the discussion in #36403, it is clear that there needs to be a way for users to rebroadcast a transaction. Currently, the way to do so requires getting the raw transaction, getting the hex, and using `sendrawtransaction`. This PR adds `rebroadcastwallettx` RPC that takes a txid to attempt to rebroadcast that single transaction. An action is also added to the GUI menu for each transaction to do the same.
DrahtBot commented 2026-10-08 21:41:15 +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 vasild
Concept ACK mzumsande, murchandamus, jpk68, fametrano, polespinasa, rkrux, psychemist
Approach ACK pseudoramdom

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:

  • #36897 (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101)
  • #36482 (wallet: Only broadcast resubmitted transactions that were added to the mempool by achow101)
  • #36380 (wallet: extend -walletbroadcast to allow initial send only by vasild)

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/36481 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36481.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36481#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 | [vasild](https://github.com/bitcoin/bitcoin/pull/36481#pullrequestreview-5859038370) | | Concept ACK | [mzumsande](https://github.com/bitcoin/bitcoin/pull/36481#pullrequestreview-5472173546), [murchandamus](https://github.com/bitcoin/bitcoin/pull/36481#issuecomment-6324896461), [jpk68](https://github.com/bitcoin/bitcoin/pull/36481#issuecomment-6329654439), [fametrano](https://github.com/bitcoin/bitcoin/pull/36481#pullrequestreview-5642981631), [polespinasa](https://github.com/bitcoin/bitcoin/pull/36481#issuecomment-6851160119), [rkrux](https://github.com/bitcoin/bitcoin/pull/36481#issuecomment-7164046301), [psychemist](https://github.com/bitcoin/bitcoin/pull/36481#issuecomment-7191509802) | | Approach ACK | [pseudoramdom](https://github.com/bitcoin/bitcoin/pull/36481#pullrequestreview-5831164432) | 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: * [#36897](https://github.com/bitcoin/bitcoin/pull/36897) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36897.svg"></sub> (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101) * [#36482](https://github.com/bitcoin/bitcoin/pull/36482) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36482.svg"></sub> (wallet: Only broadcast resubmitted transactions that were added to the mempool by achow101) * [#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) 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-->
First-time contributor

5 additional verified findings in the full report.

🟠 Minor · Rebroadcast slot indexes a selection that can be empty

If the selected row disappears while the context menu is open, triggering Rebroadcast reads past an empty list and can crash the GUI.

Location: src/qt/transactionview.cpp:403 (head).

🟠 Minor · Some rebroadcast failures return an empty error message

Fee-cap rejection or an unprocessed confirmation can produce RPC_MISC_ERROR with an empty message, or an empty "Rebroadcast Failed" dialog.

Location: src/wallet/wallet.cpp:1844 (head).

🟠 Minor · rebroadcastwallettx checks eligibility before syncing wallet notifications

Queued block notifications can make the RPC reject an eligible transaction as confirmed or report a confusing failure for a newly confirmed transaction.

Location: src/wallet/rpc/transactions.cpp:1103 (head).

🔵 Suggestion · Manual rebroadcast bypasses the periodic sync-readiness guard

During reindex, import or IBD, manual rebroadcast can announce old wallet transactions that only appear unconfirmed, unlike periodic resend.

Location: src/wallet/wallet.cpp:1838 (head).

🔵 Suggestion · GUI rebroadcast omits the RPC's privacy warning

The GUI queues ordinary peer relay for sent or received transactions without showing the sender/receiver privacy warning included in RPC help.

Location: src/qt/transactionview.cpp:407 (head).

🔵 Suggestion · Manual rebroadcast always uses ordinary relay, even with -privatebroadcast

Users switching from sendrawtransaction with -privatebroadcast to the new RPC or GUI action change relay modes without an explicit notice in either entry point.

Location: src/wallet/wallet.cpp:1843 (head).

Review coverage was incomplete.


Reviewed: e27218f7ad34 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:055d1cd96b176486294e0a3d052a7e506a00c1f0c7c35fbf579b09cfe6d615cd:237cc81563f53f26a84ba90acce49f0597b0e28b0a77aa425401db6e90431c0b --> <!-- ralph-base:5bf3bc5e263407a252c14a17afe04fc3bf24a889 --> <!-- ralph-head:e27218f7ad3482b46ea5e3f278393e68eb870b93 --> <!-- ralph-case:6feb81d8b80efefc275fb1f603b9028029936fa5f07009118ae70eecb9de6638 --> [5 additional verified findings in the full report](<https://review.fish.foo/traces/36481-e27218f7ad3482b46ea5e3f278393e68eb870b93-2343-10.html>). **🟠 Minor · Rebroadcast slot indexes a selection that can be empty** If the selected row disappears while the context menu is open, triggering Rebroadcast reads past an empty list and can crash the GUI. Location: [`src/qt/transactionview.cpp:403`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/qt/transactionview.cpp#L403>) (head). **🟠 Minor · Some rebroadcast failures return an empty error message** Fee-cap rejection or an unprocessed confirmation can produce RPC_MISC_ERROR with an empty message, or an empty "Rebroadcast Failed" dialog. Location: [`src/wallet/wallet.cpp:1844`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/wallet/wallet.cpp#L1844>) (head). **🟠 Minor · rebroadcastwallettx checks eligibility before syncing wallet notifications** Queued block notifications can make the RPC reject an eligible transaction as confirmed or report a confusing failure for a newly confirmed transaction. Location: [`src/wallet/rpc/transactions.cpp:1103`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/wallet/rpc/transactions.cpp#L1103>) (head). **🔵 Suggestion · Manual rebroadcast bypasses the periodic sync-readiness guard** During reindex, import or IBD, manual rebroadcast can announce old wallet transactions that only appear unconfirmed, unlike periodic resend. Location: [`src/wallet/wallet.cpp:1838`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/wallet/wallet.cpp#L1838>) (head). **🔵 Suggestion · GUI rebroadcast omits the RPC's privacy warning** The GUI queues ordinary peer relay for sent or received transactions without showing the sender/receiver privacy warning included in RPC help. Location: [`src/qt/transactionview.cpp:407`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/qt/transactionview.cpp#L407>) (head). **🔵 Suggestion · Manual rebroadcast always uses ordinary relay, even with -privatebroadcast** Users switching from sendrawtransaction with -privatebroadcast to the new RPC or GUI action change relay modes without an explicit notice in either entry point. Location: [`src/wallet/wallet.cpp:1843`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93/src/wallet/wallet.cpp#L1843>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`e27218f7ad34`](<https://git.fish.foo/bitcoin/bitcoin/commit/e27218f7ad3482b46ea5e3f278393e68eb870b93>) · [Full review report](<https://review.fish.foo/traces/36481-e27218f7ad3482b46ea5e3f278393e68eb870b93-2343-10.html>) · [Previous reports](<https://review.fish.foo/traces/36481/>) [permalink](<https://review.fish.foo/traces/36481-e27218f7ad3482b46ea5e3f278393e68eb870b93-2343-10.html>)
DrahtBot commented 2026-10-08 22:06:55 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/37848508934/job/113555303677
LLM reason (✨ experimental): CI failed because clang-tidy flagged an ignored return value from rebroadcastTransaction() in qt/transactionview.cpp:408 (warnings treated as errors).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `tidy`: https://github.com/bitcoin/bitcoin/actions/runs/37848508934/job/113555303677</sub> <sub>LLM reason (✨ experimental): CI failed because clang-tidy flagged an ignored return value from `rebroadcastTransaction()` in `qt/transactionview.cpp:408` (warnings treated as errors).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
polespinasa commented 2026-10-08 22:24:55 +00:00 (Migrated from github.com)

concept ACK

concept ACK
mzumsande (Migrated from github.com) reviewed 2026-10-09 15:36:08 +00:00
mzumsande (Migrated from github.com) left a comment

Concept ACK

Whatever the solution of the existing issues with rebroadcast will be, giving the users the option to rebroadcast transactions is useful in all of these scenarios.

Concept ACK Whatever the solution of the existing issues with rebroadcast will be, giving the users the option to rebroadcast transactions is useful in all of these scenarios.
murchandamus commented 2026-10-21 19:39:55 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
jpk68 commented 2026-10-22 00:27:13 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
fametrano (Migrated from github.com) reviewed 2026-10-25 11:35:15 +00:00
fametrano (Migrated from github.com) left a comment

Concept ACK

One issue should be fixed before merge: rebroadcastwallettx fails with code -1 and an empty message when the transaction is out of the mempool and its feerate is above the wallet's -maxfeerate.

I ran the RPC on regtest at 648450039a. Other mempool rejections keep their reason, such as "bad-txns-inputs-missingorspent" for a child whose parent expired. The empty message shows up when a user lowers -maxfeerate to 20 sat/vB and restarts without mempool.dat. Our own 50 sat/vB child of an incoming payment then stays out of the mempool, and the RPC returns {"code": -1, "message": ""}. For the same transaction, sendrawtransaction with maxfeerate=0.0002 returns -25 "Fee rate exceeds maximum configured by user (maxfeerate)".

The cause is that Chain::broadcastTransaction returns only a bool, and BroadcastTransaction sets no error string for MAX_FEE_EXCEEDED or MAX_FEE_RATE_EXCEEDED. sendrawtransaction falls back to TransactionErrorString in that case. The wallet's other callers only log the string or drop it, so this RPC is the first to show it to a user. The same fallback inside the Chain::broadcastTransaction wrapper would fix it, and the GUI action will need that message once it shows the result. I can share the probe script.

Concept ACK One issue should be fixed before merge: `rebroadcastwallettx` fails with code -1 and an empty message when the transaction is out of the mempool and its feerate is above the wallet's `-maxfeerate`. I ran the RPC on regtest at 648450039a. Other mempool rejections keep their reason, such as "bad-txns-inputs-missingorspent" for a child whose parent expired. The empty message shows up when a user lowers `-maxfeerate` to 20 sat/vB and restarts without mempool.dat. Our own 50 sat/vB child of an incoming payment then stays out of the mempool, and the RPC returns `{"code": -1, "message": ""}`. For the same transaction, `sendrawtransaction` with `maxfeerate=0.0002` returns -25 "Fee rate exceeds maximum configured by user (maxfeerate)". The cause is that `Chain::broadcastTransaction` returns only a bool, and `BroadcastTransaction` sets no error string for `MAX_FEE_EXCEEDED` or `MAX_FEE_RATE_EXCEEDED`. `sendrawtransaction` falls back to `TransactionErrorString` in that case. The wallet's other callers only log the string or drop it, so this RPC is the first to show it to a user. The same fallback inside the `Chain::broadcastTransaction` wrapper would fix it, and the GUI action will need that message once it shows the result. I can share the probe script.
vasild (Migrated from github.com) reviewed 2026-10-27 14:03:41 +00:00
vasild (Migrated from github.com) left a comment

Approach ACK 648450039a

Approach ACK 648450039ab1c93f5e0001e0829f094ca41d2bae
vasild (Migrated from github.com) commented 2026-10-27 10:41:28 +00:00
    //! Return whether transaction can be broadcast.
```suggestion //! Return whether transaction can be broadcast. ```
vasild (Migrated from github.com) commented 2026-10-27 10:41:59 +00:00
    //! Rebroadcast a transaction.
```suggestion //! Rebroadcast a transaction. ```
vasild (Migrated from github.com) commented 2026-10-27 10:45:45 +00:00

What is the & in Re&broadcast? It is also in A&bandon.

What is the `&` in `Re&broadcast`? It is also in `A&bandon`.
vasild (Migrated from github.com) commented 2026-10-27 10:48:52 +00:00
    if (!transactionView || !transactionView->selectionModel())
        return;

also, the return should be either on the same line as if or there should be { and }.

```suggestion if (!transactionView || !transactionView->selectionModel()) return; ``` also, the `return` should be either on the same line as `if` or there should be `{` and `}`.
vasild (Migrated from github.com) commented 2026-10-27 10:50:00 +00:00
    // Rebroadcast the wallet transaction over the walletModel
```suggestion // Rebroadcast the wallet transaction over the walletModel ```
vasild (Migrated from github.com) commented 2026-10-27 13:45:04 +00:00

I think it would be useful to add the sentence Use the listtransactions RPC to see the wallet transactions here.

I think it would be useful to add the sentence `Use the listtransactions RPC to see the wallet transactions` here.
vasild (Migrated from github.com) commented 2026-10-27 13:43:39 +00:00

Should we not throw here? UniValue::VNULL is for "If rebroadcast is successfully initiated".

-            if (!wallet) return UniValue::VNULL;
+            if (!wallet) {
+                throw JSONRPCError(RPC_WALLET_ERROR, "no wallet");
+            }
Should we not throw here? `UniValue::VNULL` is for "If rebroadcast is successfully initiated". ```diff - if (!wallet) return UniValue::VNULL; + if (!wallet) { + throw JSONRPCError(RPC_WALLET_ERROR, "no wallet"); + } ```
Lines 1839-1840
vasild (Migrated from github.com) commented 2026-10-27 13:38:05 +00:00

If the wallet broadcast is disabled (-walletbroadcast=0), then the "is not eligible to be rebroadcast" will be misleading because it implies that there is something specific about this transaction that makes it not eligible.

Consider extending TransactionCanBeBroadcast() to return the reason why the transaction can not be broadcast:

[patch] TransactionCanBeBroadcast() with a reason
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 29460e3ba2..dcd571b684 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1832,51 +1832,64 @@ util::Expected<void, WalletError> CWallet::RebroadcastSingleTransaction(const Tx
 {
     LOCK(cs_wallet);
     auto it = mapWallet.find(txid);
     if (it == mapWallet.end()) {
         return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}};
     }
-    if (!TransactionCanBeBroadcast(it->second)) {
-        return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast"), txid.ToString())}};
-    }
     std::string err;
+    if (!TransactionCanBeBroadcast(it->second, err)) {
+        return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("can not rebroadcast %s: %s"), txid.ToString(), err)}};
+    }
     if (!SubmitTxMemoryPoolAndRelay(it->second, err, node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL)) {
         return util::Unexpected{WalletError{WalletErrorCode::MiscError, Untranslated(err)}};
     }
     return {};
 }
 
-bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const
+bool CWallet::TransactionCanBeBroadcast(const Txid& txid, std::string& reason) const
 {
     LOCK(cs_wallet);
     const CWalletTx* wtx = GetWalletTx(txid);
-    return wtx && TransactionCanBeBroadcast(*wtx);
+    return wtx && TransactionCanBeBroadcast(*wtx, reason);
 }
 
-bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx) const
+bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx, std::string& reason) const
 {
     AssertLockHeld(cs_wallet);
     // Can't relay if wallet is not broadcasting
-    if (!GetBroadcastTransactions()) return false;
+    if (!GetBroadcastTransactions()) {
+        reason = "the wallet is configured to not broadcast transactions";
+        return false;
+    }
     // Don't relay abandoned transactions
-    if (wtx.isAbandoned()) return false;
+    if (wtx.isAbandoned()) {
+        reason = "the transaction is abandoned";
+        return false;
+    }
     // Don't try to submit coinbase transactions. These would fail anyway but would
     // cause log spam.
-    if (wtx.IsCoinBase()) return false;
+    if (wtx.IsCoinBase()) {
+        reason = "the transaction is a coinbase transaction";
+        return false;
+    }
     // Don't try to submit conflicted or confirmed transactions.
-    if (GetTxDepthInMainChain(wtx) != 0) return false;
+    if (GetTxDepthInMainChain(wtx) != 0) {
+        reason = "the transaction is already confirmed or is conflicted";
+        return false;
+    }
     return true;
 }
 
 bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx,
                                          std::string& err_string,
                                          node::TxBroadcast broadcast_method) const
 {
     AssertLockHeld(cs_wallet);
 
-    if (!TransactionCanBeBroadcast(wtx)) return false;
+    std::string reason;
+    if (!TransactionCanBeBroadcast(wtx, reason)) return false;
 
     const char* what{""};
     switch (broadcast_method) {
     case node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL:
         what = "to mempool and for broadcast to peers";
         break;
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 8d7c72f4d7..0b64d62571 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -443,13 +443,13 @@ private:
     // Update last block processed in memory only
     void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
 
     //! Update mempool conflicts for TRUC sibling transactions
     void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
 
-    bool TransactionCanBeBroadcast(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
+    bool TransactionCanBeBroadcast(const CWalletTx& wtx, std::string& reason) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
 
 public:
     /**
      * Main wallet lock.
      * This lock protects all the fields added by CWallet.
      */
@@ -635,13 +635,13 @@ public:
     void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) override;
     /** Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average. */
     void SetNextResend() { m_next_resend = GetDefaultNextResend(); }
     /** Return true if all conditions for periodically resending transactions are met. */
     bool ShouldResend() const;
     void ResubmitWalletTransactions(node::TxBroadcast broadcast_method, bool force);
-    bool TransactionCanBeBroadcast(const Txid& txid) const;
+    bool TransactionCanBeBroadcast(const Txid& txid, std::string& reason) const;
     util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid);
 
     OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const;
 
     /** Fetch the inputs and sign with SIGHASH_ALL. */
     bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp
index 78139f635d..1759680b02 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -283,13 +283,17 @@ public:
     bool transactionCanBeAbandoned(const Txid& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
     bool abandonTransaction(const Txid& txid) override
     {
         LOCK(m_wallet->cs_wallet);
         return m_wallet->AbandonTransaction(txid);
     }
-    bool transactionCanBeBroadcast(const Txid& txid) override { return m_wallet->TransactionCanBeBroadcast(txid); }
+    bool transactionCanBeBroadcast(const Txid& txid) override
+    {
+        std::string reason;
+        return m_wallet->TransactionCanBeBroadcast(txid, reason);
+    }
     util::Expected<void, WalletError> rebroadcastTransaction(const Txid& txid) override
     {
         LOCK(m_wallet->cs_wallet);
         return m_wallet->RebroadcastSingleTransaction(txid);
     }
     bool transactionCanBeBumped(const Txid& txid) override
If the wallet broadcast is disabled (`-walletbroadcast=0`), then the "is not eligible to be rebroadcast" will be misleading because it implies that there is something specific about this transaction that makes it not eligible. Consider extending `TransactionCanBeBroadcast()` to return the reason why the transaction can not be broadcast: <details> <summary>[patch] TransactionCanBeBroadcast() with a reason</summary> ```diff diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 29460e3ba2..dcd571b684 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1832,51 +1832,64 @@ util::Expected<void, WalletError> CWallet::RebroadcastSingleTransaction(const Tx { LOCK(cs_wallet); auto it = mapWallet.find(txid); if (it == mapWallet.end()) { return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}}; } - if (!TransactionCanBeBroadcast(it->second)) { - return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast"), txid.ToString())}}; - } std::string err; + if (!TransactionCanBeBroadcast(it->second, err)) { + return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("can not rebroadcast %s: %s"), txid.ToString(), err)}}; + } if (!SubmitTxMemoryPoolAndRelay(it->second, err, node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL)) { return util::Unexpected{WalletError{WalletErrorCode::MiscError, Untranslated(err)}}; } return {}; } -bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const +bool CWallet::TransactionCanBeBroadcast(const Txid& txid, std::string& reason) const { LOCK(cs_wallet); const CWalletTx* wtx = GetWalletTx(txid); - return wtx && TransactionCanBeBroadcast(*wtx); + return wtx && TransactionCanBeBroadcast(*wtx, reason); } -bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx) const +bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx, std::string& reason) const { AssertLockHeld(cs_wallet); // Can't relay if wallet is not broadcasting - if (!GetBroadcastTransactions()) return false; + if (!GetBroadcastTransactions()) { + reason = "the wallet is configured to not broadcast transactions"; + return false; + } // Don't relay abandoned transactions - if (wtx.isAbandoned()) return false; + if (wtx.isAbandoned()) { + reason = "the transaction is abandoned"; + return false; + } // Don't try to submit coinbase transactions. These would fail anyway but would // cause log spam. - if (wtx.IsCoinBase()) return false; + if (wtx.IsCoinBase()) { + reason = "the transaction is a coinbase transaction"; + return false; + } // Don't try to submit conflicted or confirmed transactions. - if (GetTxDepthInMainChain(wtx) != 0) return false; + if (GetTxDepthInMainChain(wtx) != 0) { + reason = "the transaction is already confirmed or is conflicted"; + return false; + } return true; } bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, node::TxBroadcast broadcast_method) const { AssertLockHeld(cs_wallet); - if (!TransactionCanBeBroadcast(wtx)) return false; + std::string reason; + if (!TransactionCanBeBroadcast(wtx, reason)) return false; const char* what{""}; switch (broadcast_method) { case node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL: what = "to mempool and for broadcast to peers"; break; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8d7c72f4d7..0b64d62571 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -443,13 +443,13 @@ private: // Update last block processed in memory only void SetLastBlockProcessedInMem(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); //! Update mempool conflicts for TRUC sibling transactions void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - bool TransactionCanBeBroadcast(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + bool TransactionCanBeBroadcast(const CWalletTx& wtx, std::string& reason) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); public: /** * Main wallet lock. * This lock protects all the fields added by CWallet. */ @@ -635,13 +635,13 @@ public: void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) override; /** Set the next time this wallet should resend transactions to 12-36 hours from now, ~1 day on average. */ void SetNextResend() { m_next_resend = GetDefaultNextResend(); } /** Return true if all conditions for periodically resending transactions are met. */ bool ShouldResend() const; void ResubmitWalletTransactions(node::TxBroadcast broadcast_method, bool force); - bool TransactionCanBeBroadcast(const Txid& txid) const; + bool TransactionCanBeBroadcast(const Txid& txid, std::string& reason) const; util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid); OutputType TransactionChangeType(const std::optional<OutputType>& change_type, const std::vector<CRecipient>& vecSend) const; /** Fetch the inputs and sign with SIGHASH_ALL. */ bool SignTransaction(CMutableTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 78139f635d..1759680b02 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -283,13 +283,17 @@ public: bool transactionCanBeAbandoned(const Txid& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); } bool abandonTransaction(const Txid& txid) override { LOCK(m_wallet->cs_wallet); return m_wallet->AbandonTransaction(txid); } - bool transactionCanBeBroadcast(const Txid& txid) override { return m_wallet->TransactionCanBeBroadcast(txid); } + bool transactionCanBeBroadcast(const Txid& txid) override + { + std::string reason; + return m_wallet->TransactionCanBeBroadcast(txid, reason); + } util::Expected<void, WalletError> rebroadcastTransaction(const Txid& txid) override { LOCK(m_wallet->cs_wallet); return m_wallet->RebroadcastSingleTransaction(txid); } bool transactionCanBeBumped(const Txid& txid) override ``` </details>
achow101 (Migrated from github.com) reviewed 2026-11-05 01:07:28 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:07:28 +00:00

It specifies the previous character as a shortcut key. With this menu open, the user can do ctrl + e to trigger this action rather than needing to move the mouse to it and clicking.

It specifies the previous character as a shortcut key. With this menu open, the user can do `ctrl + e` to trigger this action rather than needing to move the mouse to it and clicking.
achow101 (Migrated from github.com) reviewed 2026-11-05 01:16:48 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:16:48 +00:00

Done

Done
achow101 (Migrated from github.com) reviewed 2026-11-05 01:16:54 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:16:54 +00:00

Done

Done
achow101 (Migrated from github.com) reviewed 2026-11-05 01:17:21 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:17:21 +00:00

Done

Done
achow101 (Migrated from github.com) reviewed 2026-11-05 01:17:28 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:17:28 +00:00

Done

Done
achow101 (Migrated from github.com) reviewed 2026-11-05 01:17:39 +00:00
Lines 1839-1840
achow101 (Migrated from github.com) commented 2026-11-05 01:17:39 +00:00

Added a commit for this

Added a commit for this
achow101 (Migrated from github.com) reviewed 2026-11-05 01:18:49 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:18:49 +00:00

GetWalletForJSONRPCRequest never returns nullptr, this should really be a Assume return a reference. But this is the pattern that we currently use for all of the wallet RPCs.

`GetWalletForJSONRPCRequest` never returns nullptr, this should really be a `Assume` return a reference. But this is the pattern that we currently use for all of the wallet RPCs.
achow101 (Migrated from github.com) reviewed 2026-11-05 01:18:54 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 01:18:54 +00:00

Done

Done
ryanofsky (Migrated from github.com) reviewed 2026-11-05 13:46:41 +00:00
ryanofsky (Migrated from github.com) commented 2026-11-05 13:35:48 +00:00

In commit "gui: Add rebroadcast tx menu action" (96c0e43277)

Could this (and RebroadcastSingleTransaction) return util::Result<void> instead of util::Expected<void, wallet::WalletError>? That would make the interface say what it returns: an error message, with no codes callers are expected to handle.

WalletError can hold any of six codes, but this method only returns two, InvalidParameter and MiscError, and callers can't tell that from the declaration. None of them handles the codes differently either: the GUI shows the message, and the RPC only uses the code to pick an RPC error number. The WalletErrorCode documentation asks for a specific code only "when callers need to handle the condition differently", and GenericError otherwise (github.com/bitcoin/bitcoin@0e38ad26af/src/wallet/types.h (L63-L65)).

util::Result is meant for this case, functions reporting error strings to end users, and displayAddress() above already returns util::Result<void>. TransactionCanBeBroadcast could return it too, instead of util::Expected<void, bilingual_str>. The RPC could then throw RPC_WALLET_ERROR for failures. It would also stop "Wallet broadcast is disabled" from being reported as an invalid parameter. If the RPC should report an unknown txid the way gettransaction does (RPC_INVALID_ADDRESS_OR_KEY), it could check mapWallet itself before calling, without a wallet-wide code. Since rebroadcastwallettx is new, no client depends on its error codes yet.

Using util::Expected<void, bilingual_str> instead of util::Result<void> would be fine too. My main concern is the signature saying the function can return error codes that it never returns and no caller handles.

In commit "gui: Add rebroadcast tx menu action" (96c0e432770d5396294034618d35260510211bff) Could this (and `RebroadcastSingleTransaction`) return `util::Result<void>` instead of `util::Expected<void, wallet::WalletError>`? That would make the interface say what it returns: an error message, with no codes callers are expected to handle. `WalletError` can hold any of six codes, but this method only returns two, `InvalidParameter` and `MiscError`, and callers can't tell that from the declaration. None of them handles the codes differently either: the GUI shows the message, and the RPC only uses the code to pick an RPC error number. The `WalletErrorCode` documentation asks for a specific code only "when callers need to handle the condition differently", and `GenericError` otherwise (https://github.com/bitcoin/bitcoin/blob/0e38ad26af922abdc0fc36c9379e17efd2a72b80/src/wallet/types.h#L63-L65). `util::Result` is meant for this case, functions reporting error strings to end users, and `displayAddress()` above already returns `util::Result<void>`. `TransactionCanBeBroadcast` could return it too, instead of `util::Expected<void, bilingual_str>`. The RPC could then throw `RPC_WALLET_ERROR` for failures. It would also stop "Wallet broadcast is disabled" from being reported as an invalid parameter. If the RPC should report an unknown txid the way `gettransaction` does (`RPC_INVALID_ADDRESS_OR_KEY`), it could check `mapWallet` itself before calling, without a wallet-wide code. Since `rebroadcastwallettx` is new, no client depends on its error codes yet. Using `util::Expected<void, bilingual_str>` instead of `util::Result<void>` would be fine too. My main concern is the signature saying the function can return error codes that it never returns and no caller handles.
achow101 (Migrated from github.com) reviewed 2026-11-05 20:36:18 +00:00
achow101 (Migrated from github.com) commented 2026-11-05 20:36:18 +00:00

My understanding is that for the QML GUI, they generally want error codes as some errors may be handled differently. While the GUI as I have implemented it currently does not use these codes, that does not preclude the future GUI work from using them either, and I'd prefer to avoid needing another interface change at that time as well. cc @pseudoramdom

Even for the new RPC, I think it makes sense to get the codes so that we can give reasonable RPC error codes. I think it is incorrect to return RPC_WALLET_ERROR for things that are clearly the user providing a transaction that cannot be broadcast, hence using InvalidParameter so that it can return RPC_INVALID_PARAMETER.

Furthermore, I agree that it is strange that "Wallet broadcast is disabled" is InvalidParameter, but I don't think the solution is to drop the error codes from the wallet, but rather that TransactionCanBeBroadcast should use util::Expected<void, WalletError> as well, which I've done.

My understanding is that for the QML GUI, they generally want error codes as some errors may be handled differently. While the GUI as I have implemented it currently does not use these codes, that does not preclude the future GUI work from using them either, and I'd prefer to avoid needing another interface change at that time as well. cc @pseudoramdom Even for the new RPC, I think it makes sense to get the codes so that we can give reasonable RPC error codes. I think it is incorrect to return RPC_WALLET_ERROR for things that are clearly the user providing a transaction that cannot be broadcast, hence using InvalidParameter so that it can return RPC_INVALID_PARAMETER. Furthermore, I agree that it is strange that "Wallet broadcast is disabled" is InvalidParameter, but I don't think the solution is to drop the error codes from the wallet, but rather that `TransactionCanBeBroadcast` should use `util::Expected<void, WalletError>` as well, which I've done.
DrahtBot commented 2026-11-06 00:16:55 +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).
polespinasa (Migrated from github.com) reviewed 2026-11-06 10:52:45 +00:00
polespinasa (Migrated from github.com) left a comment

This will need a release note.

Also might be worth taking a look at ralph comments, specially the GUI crash, the blocks sync and the empty error messages :)

This will need a release note. Also might be worth taking a look at ralph comments, specially the GUI crash, the blocks sync and the empty error messages :)
polespinasa (Migrated from github.com) commented 2026-11-06 10:41:50 +00:00

in eba7a572f8 wallet, rpc: Add rebroadcastwallettx

nit: missing empty space or line jump after "receiver in the transaction."

$ ./build/bin/bitcoin-cli -regtest rebroadcastwallettx
error code: -1
error message:
rebroadcastwallettx "txid"

Rebroadcast the specified wallet transaction.
Note that rebroadcasting a transaction may reveal that your node is involved as either a sender or receiver in the transaction.Use listrawtransactions to see the wallet's transactions


in eba7a572f8832fa355f943f005708e4f20a1b5eb wallet, rpc: Add rebroadcastwallettx nit: missing empty space or line jump after "receiver in the transaction." ```sh $ ./build/bin/bitcoin-cli -regtest rebroadcastwallettx error code: -1 error message: rebroadcastwallettx "txid" Rebroadcast the specified wallet transaction. Note that rebroadcasting a transaction may reveal that your node is involved as either a sender or receiver in the transaction.Use listrawtransactions to see the wallet's transactions ```
Lines 1837-1839
polespinasa (Migrated from github.com) commented 2026-11-06 09:43:39 +00:00

in eba7a572f8 wallet, rpc: Add rebroadcastwallettx

small nit, feel free to ignore

This check is duplicated, it is already done inside TransactionCanBeBroadcast. Not criticla and i guess you need the find function to call SubmitTxMemoryPoolAndRelay.

I tried to refactor it so TransactionCanBeBroadcast returns a CWalletTx instead of a Void in the next commit, but I think is not worth the work.

Mentioning in case you come with a better idea :)

in eba7a572f8832fa355f943f005708e4f20a1b5eb wallet, rpc: Add rebroadcastwallettx small nit, feel free to ignore This check is duplicated, it is already done inside `TransactionCanBeBroadcast`. Not criticla and i guess you need the find function to call `SubmitTxMemoryPoolAndRelay`. I tried to refactor it so `TransactionCanBeBroadcast` returns a CWalletTx instead of a Void in the next commit, but I think is not worth the work. Mentioning in case you come with a better idea :)
Lines 1853-1858
polespinasa (Migrated from github.com) commented 2026-11-06 08:36:56 +00:00

in eba7a572f8 wallet, rpc: Add rebroadcastwallettx

Why do we need two separate functions?
This first one only adds one check, and because of the second one being private, they are never called independently outside the class.

Can't we add the if wtx check inside the private function and make it take a txid? A caller knowing the CWalletTx can always know a txid.

suggested diff
$ git diff
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index cf0c45a1b4..c420be2f5f 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1835,7 +1835,7 @@ util::Expected<void, WalletError> CWallet::RebroadcastSingleTransaction(const Tx
     if (it == mapWallet.end()) {
         return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}};
     }
-    if (!TransactionCanBeBroadcast(it->second)) {
+    if (!TransactionCanBeBroadcast(it->first)) {
         return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast"), txid.ToString())}};
     }
     std::string err;
@@ -1849,21 +1849,17 @@ bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const
 {
     LOCK(cs_wallet);
     const CWalletTx* wtx = GetWalletTx(txid);
-    return wtx && TransactionCanBeBroadcast(*wtx);
-}
-
-bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx) const
-{
-    AssertLockHeld(cs_wallet);
+    // Transaction is not in the wallet
+    if (!wtx) return false;
     // Can't relay if wallet is not broadcasting
     if (!GetBroadcastTransactions()) return false;
     // Don't relay abandoned transactions
-    if (wtx.isAbandoned()) return false;
+    if (wtx->isAbandoned()) return false;
     // Don't try to submit coinbase transactions. These would fail anyway but would
     // cause log spam.
-    if (wtx.IsCoinBase()) return false;
+    if (wtx->IsCoinBase()) return false;
     // Don't try to submit conflicted or confirmed transactions.
-    if (GetTxDepthInMainChain(wtx) != 0) return false;
+    if (GetTxDepthInMainChain(*wtx) != 0) return false;
     return true;
 }
 
@@ -1873,7 +1869,7 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx,
 {
     AssertLockHeld(cs_wallet);
 
-    if (!TransactionCanBeBroadcast(wtx)) return false;
+    if (!TransactionCanBeBroadcast(wtx.GetHash())) return false;
 
     const char* what{""};
     switch (broadcast_method) {
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 0633e928e1..c64e53e0f5 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -446,8 +446,6 @@ private:
     //! Update mempool conflicts for TRUC sibling transactions
     void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
 
-    bool TransactionCanBeBroadcast(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
-
 public:
     /**
      * Main wallet lock.

in eba7a572f8832fa355f943f005708e4f20a1b5eb wallet, rpc: Add rebroadcastwallettx Why do we need two separate functions? This first one only adds one check, and because of the second one being private, they are never called independently outside the class. Can't we add the if `wtx` check inside the private function and make it take a txid? A caller knowing the `CWalletTx` can always know a `txid`. <details> <summary>suggested diff</summary> ```diff $ git diff diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index cf0c45a1b4..c420be2f5f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1835,7 +1835,7 @@ util::Expected<void, WalletError> CWallet::RebroadcastSingleTransaction(const Tx if (it == mapWallet.end()) { return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}}; } - if (!TransactionCanBeBroadcast(it->second)) { + if (!TransactionCanBeBroadcast(it->first)) { return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast"), txid.ToString())}}; } std::string err; @@ -1849,21 +1849,17 @@ bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const { LOCK(cs_wallet); const CWalletTx* wtx = GetWalletTx(txid); - return wtx && TransactionCanBeBroadcast(*wtx); -} - -bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx) const -{ - AssertLockHeld(cs_wallet); + // Transaction is not in the wallet + if (!wtx) return false; // Can't relay if wallet is not broadcasting if (!GetBroadcastTransactions()) return false; // Don't relay abandoned transactions - if (wtx.isAbandoned()) return false; + if (wtx->isAbandoned()) return false; // Don't try to submit coinbase transactions. These would fail anyway but would // cause log spam. - if (wtx.IsCoinBase()) return false; + if (wtx->IsCoinBase()) return false; // Don't try to submit conflicted or confirmed transactions. - if (GetTxDepthInMainChain(wtx) != 0) return false; + if (GetTxDepthInMainChain(*wtx) != 0) return false; return true; } @@ -1873,7 +1869,7 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, { AssertLockHeld(cs_wallet); - if (!TransactionCanBeBroadcast(wtx)) return false; + if (!TransactionCanBeBroadcast(wtx.GetHash())) return false; const char* what{""}; switch (broadcast_method) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0633e928e1..c64e53e0f5 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -446,8 +446,6 @@ private: //! Update mempool conflicts for TRUC sibling transactions void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - bool TransactionCanBeBroadcast(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - public: /** * Main wallet lock. ``` </details>
polespinasa (Migrated from github.com) commented 2026-11-06 10:46:14 +00:00

in 592e7465b4 wallet: Return specific error messages from TransactionCanBeBroadcast

nit: there are two ; here? I am surprised this does compile with one or two.

fun fact

Am I the only one who did not know that you can put as many semicolons as you want and still being correct?
This does compile:

$ git diff
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 5de55db7fa..c104bbe409 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1860,7 +1860,7 @@ util::Expected<void, WalletError> CWallet::TransactionCanBeBroadcast(const CWall
 {
     AssertLockHeld(cs_wallet);
     // Can't relay if wallet is not broadcasting
-    if (!GetBroadcastTransactions()) return util::Unexpected{WalletError{WalletErrorCode::MiscError, _("Wallet broadcast is disabled")}};;
+    if (!GetBroadcastTransactions()) return util::Unexpected{WalletError{WalletErrorCode::MiscError, _("Wallet broadcast is disabled")}};;;;;;;;;;;;;;;;;;;
     // Don't relay abandoned transactions
     if (wtx.isAbandoned()) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is abandoned"), wtx.GetHash().ToString())}};
     // Don't try to submit coinbase transactions. These would fail anyway but would
@@ -1869,7 +1869,7 @@ util::Expected<void, WalletError> CWallet::TransactionCanBeBroadcast(const CWall
     // Don't try to submit conflicted or confirmed transactions.
     if (GetTxDepthInMainChain(wtx) > 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is confirmed"), wtx.GetHash().ToString())}};
     if (GetTxDepthInMainChain(wtx) < 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is conflicted"), wtx.GetHash().ToString())}};
-    return {};
+    return {};;;;;;;;;;;;;;;
 }

in 592e7465b475fa6a6e5af846e694b84990505878 wallet: Return specific error messages from TransactionCanBeBroadcast nit: there are two `;` here? I am surprised this does compile with one or two. <details> <summary>fun fact</summary> Am I the only one who did not know that you can put as many semicolons as you want and still being correct? This does compile: ```diff $ git diff diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5de55db7fa..c104bbe409 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1860,7 +1860,7 @@ util::Expected<void, WalletError> CWallet::TransactionCanBeBroadcast(const CWall { AssertLockHeld(cs_wallet); // Can't relay if wallet is not broadcasting - if (!GetBroadcastTransactions()) return util::Unexpected{WalletError{WalletErrorCode::MiscError, _("Wallet broadcast is disabled")}};; + if (!GetBroadcastTransactions()) return util::Unexpected{WalletError{WalletErrorCode::MiscError, _("Wallet broadcast is disabled")}};;;;;;;;;;;;;;;;;;; // Don't relay abandoned transactions if (wtx.isAbandoned()) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is abandoned"), wtx.GetHash().ToString())}}; // Don't try to submit coinbase transactions. These would fail anyway but would @@ -1869,7 +1869,7 @@ util::Expected<void, WalletError> CWallet::TransactionCanBeBroadcast(const CWall // Don't try to submit conflicted or confirmed transactions. if (GetTxDepthInMainChain(wtx) > 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is confirmed"), wtx.GetHash().ToString())}}; if (GetTxDepthInMainChain(wtx) < 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is conflicted"), wtx.GetHash().ToString())}}; - return {}; + return {};;;;;;;;;;;;;;; } ``` </details>
polespinasa (Migrated from github.com) commented 2026-11-06 08:43:41 +00:00

in eba7a572f8 wallet, rpc: Add rebroadcastwallettx

Why not use wtx.isBlockConflicted()?

Also random and unrelated question. Why IsUnconfirmed() checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state...

in eba7a572f8832fa355f943f005708e4f20a1b5eb wallet, rpc: Add rebroadcastwallettx Why not use `wtx.isBlockConflicted()`? Also random and unrelated question. Why `IsUnconfirmed()` checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state...
achow101 (Migrated from github.com) reviewed 2026-11-06 23:22:14 +00:00
Lines 1853-1858
achow101 (Migrated from github.com) commented 2026-11-06 23:22:14 +00:00

To avoid needing to do another mapWallet lookup for callers that already have a CWalletTx.

To avoid needing to do another `mapWallet` lookup for callers that already have a `CWalletTx`.
achow101 (Migrated from github.com) reviewed 2026-11-06 23:29:11 +00:00
achow101 (Migrated from github.com) commented 2026-11-06 23:29:11 +00:00

Why not use wtx.isBlockConflicted()?

This is moved code.

Also random and unrelated question. Why IsUnconfirmed() checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state...

Same reason it checks isAbandoned() and isConflicted - unconfirmed in this context means that this transaction is unconfirmed, and we want/expect it to become confirmed. If the transaction is abandoned or has a conflict already in the mempool, we either do not want it to become confirmed, or it cannot become confirmed.

> Why not use `wtx.isBlockConflicted()`? This is moved code. > Also random and unrelated question. Why `IsUnconfirmed()` checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state... Same reason it checks `isAbandoned()` and `isConflicted` - unconfirmed in this context means that this transaction is unconfirmed, and we want/expect it to become confirmed. If the transaction is abandoned or has a conflict already in the mempool, we either do not want it to become confirmed, or it cannot become confirmed.
achow101 commented 2026-11-06 23:37:04 +00:00 (Migrated from github.com)

Also might be worth taking a look at ralph comments, specially the GUI crash, the blocks sync and the empty error messages :)

None of these are relevant or things we care about at all.

> Also might be worth taking a look at ralph comments, specially the GUI crash, the blocks sync and the empty error messages :) None of these are relevant or things we care about at all.
achow101 (Migrated from github.com) reviewed 2026-11-06 23:40:37 +00:00
achow101 (Migrated from github.com) commented 2026-11-06 23:40:37 +00:00

DOe

DOe
achow101 (Migrated from github.com) reviewed 2026-11-06 23:41:03 +00:00
achow101 (Migrated from github.com) commented 2026-11-06 23:41:03 +00:00

Fixed

Fixed
pseudoramdom (Migrated from github.com) reviewed 2026-11-09 20:02:22 +00:00
pseudoramdom (Migrated from github.com) left a comment

Approach ACK. v small nits

Approach ACK. v small nits
pseudoramdom (Migrated from github.com) commented 2026-11-09 19:13:50 +00:00

In gui: Add rebroadcast tx menu action

nit: canBroadcastTransaction reads a little better to me, though transactionCanBeBroadcast follows the existing transactionCanBeBumped and transactionCanBeAbandoned naming pattern.

In gui: Add rebroadcast tx menu action nit: `canBroadcastTransaction` reads a little better to me, though transactionCanBeBroadcast follows the existing transactionCanBeBumped and transactionCanBeAbandoned naming pattern.
pseudoramdom (Migrated from github.com) commented 2026-11-09 19:17:00 +00:00

In gui: Add rebroadcast tx menu action

RebroadcastSingleTransaction already takes cs_wallet internally, so this lock looks redundant?

In gui: Add rebroadcast tx menu action `RebroadcastSingleTransaction` already takes `cs_wallet` internally, so this lock looks redundant?
pseudoramdom (Migrated from github.com) commented 2026-11-09 19:07:46 +00:00

In "wallet: Return specific error messages from TransactionCanBeBroadcast"

nit: it's odd that a function that reads like a bool but it now returns Expected<void, WalletError>
How about CheckTransactionForBroadcast?

In "wallet: Return specific error messages from TransactionCanBeBroadcast" nit: it's odd that a function that reads like a `bool` but it now returns `Expected<void, WalletError>` How about `CheckTransactionForBroadcast`?
pseudoramdom (Migrated from github.com) commented 2026-11-09 19:25:59 +00:00

Should we calculate the depth once and store in a local
const int depth{GetTxDepthInMainChain(wtx)};

Should we calculate the depth once and store in a local `const int depth{GetTxDepthInMainChain(wtx)};`
vasild (Migrated from github.com) reviewed 2026-11-11 12:54:12 +00:00
vasild (Migrated from github.com) commented 2026-11-11 12:54:12 +00:00

Indeed. Redundant/unnecessary locking is confusing and makes it somewhat more difficult to assess the code. It will have to be removed if/when some day we try to change cs_wallet from RecursiveMutex to Mutex.

I checked that just removing this LOCK(m_wallet->cs_wallet); line compiles without any clang warnings. Further, adding this in src/wallet/wallet.h:

-    util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid);
+    util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);

would be even better :)

Indeed. Redundant/unnecessary locking is confusing and makes it somewhat more difficult to assess the code. It will have to be removed if/when some day we try to change `cs_wallet` from `RecursiveMutex` to `Mutex`. I checked that just removing this `LOCK(m_wallet->cs_wallet);` line compiles without any clang warnings. Further, adding this in `src/wallet/wallet.h`: ```diff - util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid); + util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet); ``` would be even better :)
vasild (Migrated from github.com) approved these changes 2026-11-11 12:55:20 +00:00
vasild (Migrated from github.com) left a comment

ACK e27218f7ad

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK e27218f7ad3482b46ea5e3f278393e68eb870b93
-----BEGIN PGP SIGNATURE-----

iQRPBAEBCAA5FiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmr0ZZ0bFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwzAAoJEFTfBvZLVcu/nbUgAKQ4Isiaio0I9nYuKixL
epeEkpcJ8VkbwqH5r2d5J4mVEDDwoNkh5Y6moQDmSMgKdWtIFTP3sEGTEpCWWrSR
FeTO3/9ci++TMkI2pc2lt4dpKswvvT7TW6f4ujRH+dalHQuxJx2LwGt/CJx5NGxf
EIjOM4fKNg8/98OJDWxaICLAkSVlBmZ+lkpl1EYf7u8S8laCtwERK1EuDCI/Tozs
t5R7UWp9TmDpJ1ZEti1BAJNzpoxdX96uBAbeRHEHO618IOj1G3N31LwRry4eVwmL
QM0/TEZCpE/XGS5ykR9bOaZFi+FTiCNegwAqVyyP5qRRNcQimfcynaSxhdlQoeGH
gdUCLfbY5ET2sOZTfA9thNLyyLtqHjhfGzAmDazznIR48u0xkuQ7xDle41LC/5Ga
bw1fADFJcx8ldfycI+N9YJN2CAJJxpNNwdMlFEOegIOvxeQI6LuljVjk/uAhmJaf
+/J8AiuZ8iAwDiN21C/qVu8TWzjwwz68JP4MHL6M7x6WdG7i8vH2gpI6HCfoapxY
iy2TNQiFV9odAEQXDVcPEC0Z62i2Tp356c3Pxaa6DE0qFErBGiEGWtKpXb7yIHyp
Rxg6mB2Y4Jxy+gAlMaA/oNTlU/XPLAxlXjHG8HeQfJbq2CUFQxFdUY/LIzZX0NWp
/YmzSQYBhNR2R11nL0aGt2WKvMSCyVoNjHz6OHHby6QPetVY27+3Hz62numIpnJW
DihiPf7+ip/Muf0efXLOj4xvAc3u7g/viH/ZEdHmf57fBUT3/IQJBcPJ4WkbrAVn
M3Xo8wwSNG1DGWwub4ukt/JrRTHjD3NpfPwwZNdzBTDaOBZx/iCHVfPtO39E/Mmb
AZp3L/nktPqZLvuFB7LOSBDsSVKSrBKe4rbjdLV9xLzg2K6bBr3zswDLVyB6+BMz
w8vsYFKkpTIgWEDVos22Y5XaWikCHR9dIeX/XaDcQl/1+fixOhS9tBhodeLO48q6
RtnrECErMMbmDkgQJ+pZLaYiuGj3Oe5Cvs46TKqYliWc7oT47vYTBvK66s2GvuiA
KZyHX/A6iMkyQJwfLKsDLlEAdqvpE9cKYh8tiq7EqvQX2aOISpV1EYEa4+Tb8VjJ
teb6rYmfHa+kXUw1aKP1LJKEgrdiRhAHpdsU2nLeL8I//KqaxUL48tptLMM9YIXR
TcAwp33wTimvhud57vI+W3pL6CqF+QaoR6dz6oyvlgdLoW5z5zsslkF/6P29xT0s
8XbGffthHeqnfUjvQ1h1LQTbJnRqtV8BwAg8+bFiSy+mWJUWyiG0uNaHUO0cuJFK
2PoGvuDveTQXu33q1k2CXRKTj/oPahumfG94SUDsyy9rNc3BsqHIhmcawPtbDXvS
lTA=
=+Pad
-----END PGP SIGNATURE-----

vasild's public key is on openpgp.org

ACK e27218f7ad3482b46ea5e3f278393e68eb870b93 <details> <summary>Show Signature</summary> ``` -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 ACK e27218f7ad3482b46ea5e3f278393e68eb870b93 -----BEGIN PGP SIGNATURE----- iQRPBAEBCAA5FiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmr0ZZ0bFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMiwzAAoJEFTfBvZLVcu/nbUgAKQ4Isiaio0I9nYuKixL epeEkpcJ8VkbwqH5r2d5J4mVEDDwoNkh5Y6moQDmSMgKdWtIFTP3sEGTEpCWWrSR FeTO3/9ci++TMkI2pc2lt4dpKswvvT7TW6f4ujRH+dalHQuxJx2LwGt/CJx5NGxf EIjOM4fKNg8/98OJDWxaICLAkSVlBmZ+lkpl1EYf7u8S8laCtwERK1EuDCI/Tozs t5R7UWp9TmDpJ1ZEti1BAJNzpoxdX96uBAbeRHEHO618IOj1G3N31LwRry4eVwmL QM0/TEZCpE/XGS5ykR9bOaZFi+FTiCNegwAqVyyP5qRRNcQimfcynaSxhdlQoeGH gdUCLfbY5ET2sOZTfA9thNLyyLtqHjhfGzAmDazznIR48u0xkuQ7xDle41LC/5Ga bw1fADFJcx8ldfycI+N9YJN2CAJJxpNNwdMlFEOegIOvxeQI6LuljVjk/uAhmJaf +/J8AiuZ8iAwDiN21C/qVu8TWzjwwz68JP4MHL6M7x6WdG7i8vH2gpI6HCfoapxY iy2TNQiFV9odAEQXDVcPEC0Z62i2Tp356c3Pxaa6DE0qFErBGiEGWtKpXb7yIHyp Rxg6mB2Y4Jxy+gAlMaA/oNTlU/XPLAxlXjHG8HeQfJbq2CUFQxFdUY/LIzZX0NWp /YmzSQYBhNR2R11nL0aGt2WKvMSCyVoNjHz6OHHby6QPetVY27+3Hz62numIpnJW DihiPf7+ip/Muf0efXLOj4xvAc3u7g/viH/ZEdHmf57fBUT3/IQJBcPJ4WkbrAVn M3Xo8wwSNG1DGWwub4ukt/JrRTHjD3NpfPwwZNdzBTDaOBZx/iCHVfPtO39E/Mmb AZp3L/nktPqZLvuFB7LOSBDsSVKSrBKe4rbjdLV9xLzg2K6bBr3zswDLVyB6+BMz w8vsYFKkpTIgWEDVos22Y5XaWikCHR9dIeX/XaDcQl/1+fixOhS9tBhodeLO48q6 RtnrECErMMbmDkgQJ+pZLaYiuGj3Oe5Cvs46TKqYliWc7oT47vYTBvK66s2GvuiA KZyHX/A6iMkyQJwfLKsDLlEAdqvpE9cKYh8tiq7EqvQX2aOISpV1EYEa4+Tb8VjJ teb6rYmfHa+kXUw1aKP1LJKEgrdiRhAHpdsU2nLeL8I//KqaxUL48tptLMM9YIXR TcAwp33wTimvhud57vI+W3pL6CqF+QaoR6dz6oyvlgdLoW5z5zsslkF/6P29xT0s 8XbGffthHeqnfUjvQ1h1LQTbJnRqtV8BwAg8+bFiSy+mWJUWyiG0uNaHUO0cuJFK 2PoGvuDveTQXu33q1k2CXRKTj/oPahumfG94SUDsyy9rNc3BsqHIhmcawPtbDXvS lTA= =+Pad -----END PGP SIGNATURE----- ``` vasild's public key is [on openpgp.org](https://keys.openpgp.org/vks/v1/by-fingerprint/850E138BA9C0923881DFD55FCE712013582E2230) </details>
polespinasa commented 2026-11-13 11:12:52 +00:00 (Migrated from github.com)

reviewed e27218f7ad

I don't have much to add I think last two nits reported by ram would be nice to have, will ACK after they are resolved.

reviewed e27218f7ad3482b46ea5e3f278393e68eb870b93 I don't have much to add I think last two nits reported by ram would be nice to have, will ACK after they are resolved.
vasild commented 2026-11-18 16:31:55 +00:00 (Migrated from github.com)
The QML part of this in https://github.com/bitcoin-core/gui-qml/pull/1143
rkrux commented 2026-11-25 13:37:21 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
psychemist commented 2026-11-26 12:03:25 +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!36481
No description provided.