mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 15:08:38 +00:00
[RFC] Scheduled transaction broadcast, minimal #36429
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!36429
Loading…
Reference in a new issue
No description provided.
Delete branch "2610-delayed-broadcast1"
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?
Minimal implementation for "Scheduled Transaction Broadcast" new feature.
Goal: Allow a user to submit a transaction to be broadcast later, at a specified time (block height). This can be done for convenience, or to hide the exact time of the transaction creation (for increased privacy).
Goal in this PR: Extend the
sendrawtransactionRPC with an option to schedule the broadcast at a later time, determined by the lock time of the transaction.Use case details, with the limitations of the current changeset:
sendrawtransactionhas an optional parameter,delay_after_lock_timedelay_after_lock_timeis set to 0, thenLockTimeof the transaction determines the scheduled broadcast time (in the future).delay_after_lock_timeis set to a positive number, the broadcast time will be the sum of the transactionnLockTimeand the parameter value.getprivatebroadcastinfoRPC.abortprivatebroadcastRPC can be used to cancel a pending transaction submission.delay_after_lock_timewith a positive value can be used to distance the submission time from the lock time.Solution Details:
m_transactionscollection.ReattemptPrivateBroadcast). Alternative: triggered by new blocks.Further improvements:
delay_after_lock_timein 10-minute units if time-based lock is used.ProcessTransactionandAcceptToMemoryPool).Related issue: #34118
EDIT (Nov-03): Reworked, see https://github.com/bitcoin/bitcoin/pull/36429#issuecomment-6315408546
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.
A summary of reviews will appear here.
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 · An early non-final copy cancels a scheduled broadcast
A rejected incoming transaction can erase a held private-broadcast schedule before validation, leaving nothing to release later.
Location:
src/private_broadcast.cpp:71(head).🟠 Minor · Due transactions become sendable before release-time validation
An in-flight private-broadcast handshake can select a due transaction before revalidation, disclosing an entry later dropped and consuming a connection intended for another queued transaction.
Location:
src/private_broadcast.cpp:96(head).🟠 Minor · Abort can subtract requests that have not been added
src/private_broadcast.cpp:58: Remove() counts a just-released entry's three planned sends as already requested before NumToOpenAdd runs. A concurrent abortprivatebroadcast then subtracts requests that were never added, and if validation rejects the entry, other queued broadcasts lose them.
Location:
src/private_broadcast.cpp:55(head).🟠 Minor · Delayed mempool rebroadcasts fail the release check
src/node/transaction.cpp:67: a txid already in the mempool skips test_accept but is still scheduled when nLockTime + delay_after_lock_time is above the tip. At release, test_accept returns txn-already-in-mempool and the entry is removed unsent, although the RPC succeeded.
Location:
src/node/transaction.cpp:54(head).🔵 Suggestion · The release height does not account for relative locks or coinbase maturity
A future schedule can accept a premature spend but permanently drop it if a relative lock or coinbase maturity is still unsatisfied at the chosen height.
Location:
src/net_processing.cpp:1800(head).🔵 Suggestion · Release timing has no per-transaction randomization
The release scheduler adds shared polling jitter, not independent transaction delays, so entries targeting the same height become eligible together.
Location:
src/net_processing.cpp:1816(head).Review coverage was incomplete.
Reviewed:
8960630481d3· Full review report · Previous reportspermalink
Minor test lint fix (assert)
Rebased. #36277 got merged, which caused the first commit to be substantially changed, but behavior is the same.
Putting the current block height in
nLockTimewhen the transaction is created defeats delaying its broadcast:github.com/bitcoin/bitcoin@acaf322fc4/src/wallet/spend.cpp (L1020-L1030)So an artificial delay must be combined with a non-default
nLockTimein order to be effective. External wallets that use the RPC and use othernLockTimemight benefit more from this.Delaying in order to make linking transactions (that are otherwise unrelated) by creation time harder makes sense if private broadcast is used. If send-to-all broadcast is used, then the otherwise unrelated transactions can be linked as coming from the same node.
The delay does not play nice with node restart (unbroadcast transactions would be lost).
Hmm?
Nit, from the OP:
probably you meant "submitted but not yet broadcast".
@vasild, thanks for the general remarks!
The Core wallet could be enhanced, to use matching nLockTime if using delyed broadcast (in a followup). Also, delayed broadcast could check and warn on nLockTime (closer to submission time than broadcast time, or too much in the future). Even better, nLockTime could be used to set/extend the requested broadcast time. (The time-based option should be there nonetheless, as it makes the feature more accessible.)
True, but delayed broadcast is available only in conjunction with private broadcast.
Persisting the queue is an important feature, should be added (but I thing a followup is fine).
Undo/Cancel support: that's a mistake in the description, removed (originally was not planned, but it came 'free' with existing private broadcast infrastructure).
Typo, fixed.
Applied a fix to the new functional test. One CI run failed, and it turned out to be a timing issue in the test. Note that the failing run was a no wallet run, but the sporadic failure is not specific to the no-wallet config. Pre-#36277 the test was correct, but now it had to be adapted.
Hmm, I am tending towards concept ~0, As I mentioned here https://github.com/bitcoin/bitcoin/issues/34118, the delay itself seems like something a client can already do: sleep for a random time, then call sendrawtransaction on a node running with -privatebroadcast. I had Claude write a ~30 line shell script that reproduces the algorithm here.
But the shell script has downsides, the client/shell process has to stay running for up to 12 hours, whereas with this PR the node holds it instead, which is better. Info calls like visibility in
getprivatebroadcastinfoand aborting viaabortprivatebroadcastaren't available to a script either. But as the PR is, pending txs aren't persisted and are lost on restart, so the node has to stay up too (so having the client up vs. the node up is the same tradeoff).It would be a bit more ideal if this were implemented for our wallet users, since it'd be awkward for them to create a tx and then have to use a script to delay broadcasting it.
Also see the recent discussion in https://github.com/bitcoin/bitcoin/issues/36403, which attempts to revive a lot of old ideas like a node rebroadcast module, improving wallet rebroadcast, e.t.c. it would involve some machinery to distinguish between delayed-rebroadcast txs, mempool txs, private-rebroadcast txs, and wallet txs, since they'd all need to be taken into account, but in practice can be done correctly with good SOC.
Fwiw, I am not completely dismissing this, I'd like to understand the privacy goal better. "Making time-correlation-based tracking more difficult" is a bit vague can you be more explicit, e.g. with scenarios and data? Because I think I'm missing something:
Hey @ismaelsadeeq , thanks for sharing your concerns!
That's true, most client could do the delay themselves (this is not true for private broadcast, for which the core node must be involved). However, many clients can not do this easily, as wallets are typically not used in an always-on mode. If someone uses a third-party wallet software (e.g. Sparrow, Nunchuk, etc.), connected to his own core node (directly or indirectly via an electrum server), ultimately the core node is the always-on component interfacing with the bitcoin network, and it's a good fit to offer scheduled/delayed broadcast support. I don't think shell script is a practical solution for an average user, even a power user.
For more concrete examples, here are some use cases:
A user manages TXs through a non-core wallet, connected to a core node. He wants to initiate a few transfers for some other persons, to be done the next day, without a need for a future user interaction, or keeping the wallet running, or leaving an early trace in the mempool/blockchain. Since the code node is used to interface with the network, and it is an always-on component, it makes sense to delegate. Note that this is a simple scheduled broadcast example.
A user manages TXs through a non-core wallet, connected to a core node. He wants to initiate a few transfers for some other persons, initiated at once, but with different public timing fingerprint (care is taken that the TXs are not related through UTXOs). The user does not want a future user interaction, or keeping the wallet running.
A service backend sometimes creates bitcoin transactions (through a core node), in response to some events, e.g. a trading/betting system. The triggering events are publicly observable, but not on the bitcoin network. Transactions related to specific events could be probabilistically matched based on timing analysis. To avoid that, the service wants to create the transactions with a random delay. While not the only solution, but it's preferred that the core node can handle delayed broadcast.
I think private broadcast, delayed broadcast, rebroadcast all fit in a larger picture: locally-originated transactions. Transactions originated in/through the node are special in many ways compared to relayed transactions originated elsewhere.
Sources:
Functionalities:
I would argue that an abstraction for local-originated transactions and a pool for such transactions would make a lot of sense.
(Note: added '[RFC]' prefix to title)
Yes, I like this idea - use
nLockTimefor deciding when to send the transaction. Because:nLockTimeheight is reached, then it cannot confirm, so it does not make sense to send it earlier.nLockTimeheight is reached, then it trivially reveals when the transaction was created (nLockTime) and a delayed send will not hide it. So it does not make sense from privacy perspective.If the point is to hide the transaction creation time and the wallet puts current height for
nLockTime(like the Bitcoin Core wallet mostly does) then sending later does not make sense. So such an option could mislead users that they can hide the transaction creation time by using it?Following some recent discussions, I plan to do some changes to the feature:
Acknowledge the two separate sub use cases of scheduling (for convenience) and random delay (for time obfuscation).
Use the 'nLockTime' of the transaction as a basis for scheduling time, instead of an extra parameter. This way it can be ensured that the scheduling time and lock time are in sync (or if they are not, that's intended).
Drop the random delay computation, because (1) it's not compatible with the lock time usage of the previous point, and (2) it is easy to be done on the client side
Keeping in Draft status until the above changes are applied.
@vasild , thanks for this and previous feedback! I also arrived at the same conclusion, see the previous comment.
I am thinking to also support the option for using a past lock time for obfuscation (wallet fingerprinting). One idea I came up with:
sendrawtransactionRPC introduce a new parameterdelay_after_lock_timenLockTimeand the parameter valueExamples (assume current height is 1000:
delay_after_lock_time=0delay_after_lock_time=20. Broadcast will be delayed until height 1005 (985+20).Scheme to be refined. It should also support time-based lock time.
ralph referenced this pull request2026-10-21 17:40:03 +00:00
Reworked the whole PR (code, description, title) in light of the above, to timelock-based.