mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:29:39 +00:00
wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction #36481
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36481
Loading…
Reference in a new issue
No description provided.
Delete branch "manual-rebroadcast"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 addsrebroadcastwallettxRPC 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.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.
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:
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.
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 reportspermalink
🚧 At least one of the CI tasks failed.
Task
tidy: https://github.com/bitcoin/bitcoin/actions/runs/37848508934/job/113555303677LLM reason (✨ experimental): CI failed because clang-tidy flagged an ignored return value from
rebroadcastTransaction()inqt/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.
concept ACK
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
Concept ACK
Concept ACK
One issue should be fixed before merge:
rebroadcastwallettxfails 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-maxfeerateto 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,sendrawtransactionwithmaxfeerate=0.0002returns -25 "Fee rate exceeds maximum configured by user (maxfeerate)".The cause is that
Chain::broadcastTransactionreturns only a bool, andBroadcastTransactionsets no error string forMAX_FEE_EXCEEDEDorMAX_FEE_RATE_EXCEEDED.sendrawtransactionfalls back toTransactionErrorStringin 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 theChain::broadcastTransactionwrapper would fix it, and the GUI action will need that message once it shows the result. I can share the probe script.Approach ACK
648450039aWhat is the
&inRe&broadcast? It is also inA&bandon.also, the
returnshould be either on the same line asifor there should be{and}.I think it would be useful to add the sentence
Use the listtransactions RPC to see the wallet transactionshere.Should we not throw here?
UniValue::VNULLis for "If rebroadcast is successfully initiated".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
It specifies the previous character as a shortcut key. With this menu open, the user can do
ctrl + eto trigger this action rather than needing to move the mouse to it and clicking.Done
Done
Done
Done
Added a commit for this
GetWalletForJSONRPCRequestnever returns nullptr, this should really be aAssumereturn a reference. But this is the pattern that we currently use for all of the wallet RPCs.Done
In commit "gui: Add rebroadcast tx menu action" (
96c0e43277)Could this (and
RebroadcastSingleTransaction) returnutil::Result<void>instead ofutil::Expected<void, wallet::WalletError>? That would make the interface say what it returns: an error message, with no codes callers are expected to handle.WalletErrorcan hold any of six codes, but this method only returns two,InvalidParameterandMiscError, 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. TheWalletErrorCodedocumentation asks for a specific code only "when callers need to handle the condition differently", andGenericErrorotherwise (github.com/bitcoin/bitcoin@0e38ad26af/src/wallet/types.h (L63-L65)).util::Resultis meant for this case, functions reporting error strings to end users, anddisplayAddress()above already returnsutil::Result<void>.TransactionCanBeBroadcastcould return it too, instead ofutil::Expected<void, bilingual_str>. The RPC could then throwRPC_WALLET_ERRORfor 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 waygettransactiondoes (RPC_INVALID_ADDRESS_OR_KEY), it could checkmapWalletitself before calling, without a wallet-wide code. Sincerebroadcastwallettxis new, no client depends on its error codes yet.Using
util::Expected<void, bilingual_str>instead ofutil::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.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
TransactionCanBeBroadcastshould useutil::Expected<void, WalletError>as well, which I've done.🐙 This pull request conflicts with the target branch and needs rebase.
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 :)
in
eba7a572f8wallet, rpc: Add rebroadcastwallettxnit: missing empty space or line jump after "receiver in the transaction."
in
eba7a572f8wallet, rpc: Add rebroadcastwallettxsmall 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 callSubmitTxMemoryPoolAndRelay.I tried to refactor it so
TransactionCanBeBroadcastreturns 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
eba7a572f8wallet, rpc: Add rebroadcastwallettxWhy 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
wtxcheck inside the private function and make it take a txid? A caller knowing theCWalletTxcan always know atxid.suggested diff
in
592e7465b4wallet: Return specific error messages from TransactionCanBeBroadcastnit: 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:
in
eba7a572f8wallet, rpc: Add rebroadcastwallettxWhy 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...To avoid needing to do another
mapWalletlookup for callers that already have aCWalletTx.This is moved code.
Same reason it checks
isAbandoned()andisConflicted- 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.None of these are relevant or things we care about at all.
DOe
Fixed
Approach ACK. v small nits
In gui: Add rebroadcast tx menu action
nit:
canBroadcastTransactionreads a little better to me, though transactionCanBeBroadcast follows the existing transactionCanBeBumped and transactionCanBeAbandoned naming pattern.In gui: Add rebroadcast tx menu action
RebroadcastSingleTransactionalready takescs_walletinternally, so this lock looks redundant?In "wallet: Return specific error messages from TransactionCanBeBroadcast"
nit: it's odd that a function that reads like a
boolbut it now returnsExpected<void, WalletError>How about
CheckTransactionForBroadcast?Should we calculate the depth once and store in a local
const int depth{GetTxDepthInMainChain(wtx)};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_walletfromRecursiveMutextoMutex.I checked that just removing this
LOCK(m_wallet->cs_wallet);line compiles without any clang warnings. Further, adding this insrc/wallet/wallet.h:would be even better :)
ACK
e27218f7adShow Signature
vasild's public key is on openpgp.org
reviewed
e27218f7adI 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.
The QML part of this in https://github.com/bitcoin-core/gui-qml/pull/1143
Concept ACK
concept ACK