mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
wallet: Only broadcast resubmitted transactions that were added to the mempool #36482
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!36482
Loading…
Reference in a new issue
No description provided.
Delete branch "broadcasttx-if-new"
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?
As discussed in #36403, one of the issues with current rebroadcast behavior is that the rebroadcast begins an unconditional relay of a transaction to peers. While this is broadcast is limited to peers that have not previously been inv'd the transaction, there is still a privacy leak in this double relay of a transaction, especially so for transactions that are still in nodes' mempools.
This PR changes the rebroadcast to only rebroadcast transactions if the transaction was not already present in our mempool. This provides some additional privacy while retaining intended rebroadcast behavior as transactions that have likely fallen out of nodes' mempools are the ones that actually need to be rebroadcast.
The wallet rebroadcast tests are additionally refactored for isolation so that their behaviors can still be tested after this change. Additionally, a test for the loading resubmission was added, as well as a test for the new behavior.
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.
Base:
a773e1e33b349dc819b5a0edc1c7a4839dc73b48Head:
4dbd27f37b52e49a8d392bd2ee6713ae7dcf23dfFindings
Major
Startup can prevent later automatic relay of wallet transactions (src/wallet/wallet.cpp:1972, head)
With wallet broadcasting enabled,
postInitProcess()submits unconfirmed wallet transactions usingMEMPOOL_NO_BROADCAST. This can put a transaction in the mempool without adding it to the unbroadcast set. The periodic path usesMEMPOOL_AND_BROADCAST_ADDED, which does not relay a transaction already in the mempool, andReattemptInitialBroadcasthas no unbroadcast entry to retry. Thus, a transaction reinserted locally during load or import can remain unannounced by the automatic wallet relay paths while it stays in the local mempool, including after a restart with-persistmempool=0.Minor
Wait for wallet resubmission before checking mempool membership (test/functional/wallet_resendwallettransactions.py:117, head)
After
mockscheduler(60), the assertion can run before the asynchronously scheduled wallet callback re-adds the evicted transaction.MockForwardadjusts queued deadlines and notifies the scheduler, but the RPC does not wait for the wallet scheduler callback. Move the mempool assertion after the broadcast wait or explicitly wait for the transaction to reappear; otherwise, the test can fail intermittently despite correct production behavior.Design and approach
Concept and approach. Clarify whether periodic wallet rebroadcast should recover transactions that remain in the local mempool but may have disappeared from peers. Local mempool presence does not answer whether relay is still needed, so if recovery is expected, use a signal distinct from local mempool presence; the frequency of this situation is not established. Source
Alternatives
User-triggered wallet rebroadcast. Keep routine periodic rebroadcast privacy-conservative while offering an explicit wallet RPC or GUI action to retry relay when a user believes a transaction needs recovery. Benefit: Provides a recovery route without automatically repeating relay on the periodic schedule. Trade-off: Recovery depends on the user noticing the problem and taking action; this is not equivalent to automatic recovery. Unresolved: Whether user intervention is an acceptable substitute for automatic recovery. Source 1
Review coverage was incomplete.
Review limitations
Full review report
concept ACK
This replacement pattern with
indep_utxois just the mechanism that an attacker could do to probe for which nodes a given address belong to, so this doesn't appear to completely solve the receiver issue from #3828.ralph referenced this pull request2026-10-21 17:40:03 +00:00
This PR introduces the new
MEMPOOL_AND_BROADCAST_ADDEDTxBroadcast case, and uses it when the wallet resubmits transactions to the node’s mempool instead of the transaction being rebroadcast to all peers that it hadn’t been inventoried. The tests check that the rebroadcast happens when the transaction is added to the mempool and doesn’t happen when the transaction was already present. This is an obvious privacy improvement.The only open question I have at the moment is whether the combination of using
MEMPOOL_NO_BROADCASTon wallet loading and thenMEMPOOL_AND_BROADCAST_ADDEDon the wallet’s rebroadcast could prevent a transaction from being resubmitted to the network. E.g., if a wallet submits a low-feerate transaction, then the node is turned off for some period during which a feerate spike causes most of the network to drop the transaction, then the node is turned back on, wouldn’t this mean that the wallet’s transaction is not rebroadcast at all?Also, I’m not sure whether using
MEMPOOL_AND_BROADCAST_ADDEDduring wallet loading would fix that, if the node still had the transaction in its mempool from before going offline.After a restart, this branch does not announce a wallet transaction that peers already received while our own mempool keeps it, so the answer to murch's question is yes.
I built
4dbd27f37band its basef739c7876band ran a regtest script that connects a fresh P2PInterface peer, moves mocktime 36 hours ahead so that MaybeResendWalletTxs runs, and sends an unrelated transaction as a barrier. A wallet transaction still in the mempool is announced on base and not on the branch, as intended. One that expired and was accepted again is announced on both. One rejected as non-final is announced on neither.With -persistmempool=0, the load-time resubmission puts the transaction back without broadcast. With mempool.dat, it comes back already out of the unbroadcast set, because a peer requested it before shutdown. The branch announced nothing in either case, and with -persistmempool=0 nothing over two periodic resubmissions and six ReattemptInitialBroadcast windows; base announced it at each resubmission. The same holds whenever our mempool keeps a transaction that peers dropped, until it expires from our mempool (two weeks by default). A node offline for days now takes its own mempool as a proxy for everyone else's. test_resubmit_on_load stops before the first periodic resubmission; extending it would pin whichever behaviour is intended.
Smaller: the comment above ResubmitWalletTransactions still names MEMPOOL_AND_BROADCAST_TO_ALL for the periodic path, and "resubmit N unconfirmed transactions" now counts transactions not relayed. I can share the script as a gist.
in
4446226ea9node: Add option to relay txs only if they are added to mempoolin
858be1c447test: Test wallet unconfirmed resubmission on loadThis asserts are wrong, in invs we have wtxid so they will never fail.
Easy way to test it is changing
txid1ortxid2withbroadcast_txidit will pass anyway, but if you usebroadcast_wtxidthe test will fail.ACK
4dbd27f37bmodulo https://github.com/bitcoin/bitcoin/pull/36482#discussion_r4567017959As for the @murchandamus scenario:
https://github.com/bitcoin/bitcoin/pull/36481 would help in that case to manually rebroadcast the transaction.
Some non-blocker comments below.
Show Signature
vasild's public key is on openpgp.org
The newly added
wait_for_single_broadcast()is almost identical to the existentwait_for_broadcast(). I wonder if the existent function can be modified to use>=instead of==when comparing the sets. This would allow the input list of txids to be a subset of thetx_invs_received.Or if that is going to break something then take a parameter to control whether to use
==or>=.This assumes that the transaction to be evicted, the one that spends
conflict_utxo, has a fee rate less than30. That is a bit obscure and fragile.Consider getting the feerate of the transaction to be evicted and using a higher value than that (plus two more asserts - that the to-be-evicted transaction is in the mempool when the function starts and is absent at the end):
Consider also adding:
because neither txid nor wtxid should be in
peer_secondand both txid wtxid could end in the result ofget_invs():github.com/bitcoin/bitcoin@079437cca7/test/functional/test_framework/p2p.py (L991-L994)(hint from https://github.com/bitcoin/bitcoin/pull/36482#discussion_r4567017959)
For me it fails with both
broadcast_txidandbroadcast_wtxid. They are equal. Here is some debug output:output:
I think it is more robust and easier to reason about if we test that neither one of the transaction id or witness transaction id are in the
invs[].Concept ACK.
Worth noting that a node with a small mempool can still resubmit and rebroadcast a tx while others have it and won't relay it, so it still has the same leak even with this change. Adding a separate option to disable rebroadcast, ideally off by default, would be useful. That way, it's opt-in for advanced users who need it.
Post-Coredev, I discussed the issue with a few others in BRW, and made a post about what I understand thus far. https://delvingbitcoin.org/t/exploiting-wallet-rebroadcast-to-link-addresses-to-node-ips-and-more/3123