WIP: node: Persist private broadcast transactions over node restarts

bitcoin/bitcoin: PR #34322

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 4 minor findings · 4 suggestions

Findings

Link

[major] · Early startup exits overwrite the saved private-broadcast queue

With -privatebroadcast=1, an exit after peerman construction but before restoration can replace unread privatebroadcast.dat with an empty snapshot, permanently removing the node's saved pending submissions.

Location: src/init.cpp:325 (head).

Details and suggested fix

node.peerman is constructed before index and wallet loading, and -stopafterblockimport explicitly returns before LoadPrivateBroadcast. bitcoind still calls Shutdown, which joins the background thread but checks no load-state flag before dumping. The untouched in-memory queue is empty, so a successful dump writes a zero-entry temporary file and RenameOver replaces the previous snapshot. A subsequent normal restart cannot restore those submissions. Record whether private-broadcast loading was attempted and gate the shutdown dump on that state, as the mempool does with GetLoadTried(). Add a regression test with a saved pending transaction, an intervening -stopafterblockimport startup, and then a normal restart.


Link

[minor] · privatebroadcast.dat is removed after failed or partial loading

A local read or decoding failure can make startup unlink privatebroadcast.dat without restoring its full contents, preventing a later retry; no production occurrence was identified.

Location: src/init.cpp:2010 (head).

Details and suggested fix

LoadPrivateBroadcast returns void: it returns after an open failure, silently rejects an unsupported version, and catches decoding exceptions after adding only the decoded prefix. The caller then removes the original file, discarding the bytes needed to retry or repair the load. On POSIX, an unreadable file can still be removable when its directory is writable. Only version 1 exists today, so a legitimate newer-format snapshot requires a future format change. Return an explicit load result and remove the file only after a complete, version-matched load. Preserve or quarantine failed input and prevent the later shutdown dump from overwriting it. Log unsupported versions rather than silently rejecting them.


Link

[minor] · Persistence test can skip the restored broadcast

The new test can skip an already-recorded restored broadcast and time out; source inspection establishes the race, but no test failure was observed.

Location: test/functional/p2p_private_broadcast.py:448 (head).

Details and suggested fix

skip_destinations is captured after both start_node and mockscheduler(300). Startup schedules an immediate private-broadcast retry, and the scheduler RPC independently makes a pending retry runnable. Either can cause the SOCKS factory to append the expected connection before the count is read. check_broadcasts excludes that connection permanently. If its PONG has already been processed, advancing scheduler deadlines does not advance NodeClock, so the transaction need not be stale again; the next retry is scheduled 2–3 minutes later. Capture the destination baseline after stop_node(0) and before start_node(0), so the helper observes both startup-triggered and scheduler-triggered broadcasts.


Link

[minor] · Loader drops writer-produced entries beyond 100,000

Queues above 100,000 pending private-broadcast transactions lose their excess entries on restart, although no current caller creating such a backlog was found.

Location: src/node/private_broadcast_persist.cpp:53 (head).

Details and suggested fix

PrivateBroadcast::Add has no count limit, and private sendrawtransaction submissions use test acceptance without entering the mempool, so mempool capacity does not bound this queue. DumpPrivateBroadcast writes every entry in deterministic hash order, but LoadPrivateBroadcast clamps the serialized count to 100,000. Startup then deletes the complete source file after restoring only that prefix, with no truncation diagnostic. Make the limits consistent by enforcing the same bound at submission with an explicit RPC error, and report oversized snapshots as incomplete loads so startup preserves them rather than silently discarding accepted entries.


Link

[minor] · LoadPrivateBroadcast bypasses admission and connection accounting

LoadPrivateBroadcast inserts unvalidated, unbudgeted entries that can delay new submissions by consuming or cancelling their connection requests, extending an existing cancellation-accounting weakness.

Location: src/node/private_broadcast_persist.cpp:58 (head).

Details and suggested fix

The loader uses pb.Add(tx) directly instead of the submission path's test acceptance and three-connection reservation. If startup's zero-delay retry runs before loading, restored entries wait another 2–3 minutes and receive one connection each. Before that retry, PickTxForSend may select a restored entry for a new submission's connection without revalidation, even if it was mined or conflicted while the node was offline. On a non-IBD TX return with zero reception confirmations, removal also subtracts three from the global connection counter, potentially cancelling requests belonging to another submission until a periodic retry. Over-cancellation already occurs in some base cases, but restored entries never reserved those initial requests at all.

A paced restart may be intentional, but it still needs consistent validation and budgeting. Route restoration through a PeerManager admission path that test-accepts under cs_main, logs and drops failures, and reserves initial connections like InitiateTxBroadcastPrivate before making restored entries eligible for selection.


Optional improvements

Link

[suggestion] · The new private-broadcast snapshot is undocumented

The new privatebroadcast.dat stores pending local submissions, but doc/files.md and -privatebroadcast help do not describe its contents or lifecycle.

Location: src/node/private_broadcast_persist_args.cpp:14 (head).

Details and suggested fix

PrivateBroadcastPath places this file in the network-specific datadir, and the dump stores complete pending transactions with the XOR key alongside them, not encrypted data. Add an entry to doc/files.md and update the option help or release notes to explain that the snapshot is written on shutdown and removed after the startup load attempt. Persistence is currently inseparable from -privatebroadcast, unlike -persistmempool. A separate switch is a policy choice rather than an established secrecy requirement: existing Info logs already record private-broadcast transaction identifiers.


Link

[suggestion] · Cleanup barrier does not verify removal of both witness siblings

One shared-txid log line satisfies both sibling expectations, so the functional test does not establish that both distinct-wtxid entries were removed before persistence.

Location: test/functional/p2p_private_broadcast.py:427 (head).

Details and suggested fix

The fixture asserts that sibling1 and sibling2 share a txid, making their entries in received_back_msgs identical. busy_wait_for_debug_log repeatedly tests substring membership in the same log buffer, so a single occurrence satisfies both expectations. PrivateBroadcast::Remove distinguishes entries by wtxid, meaning removal of one sibling does not remove the other. The barrier can therefore pass with sibling2 still queued, leaving the intended single-transaction persistence fixture unverified. Require two occurrences of the shared removal message before leaving the cleanup barrier.


Link

[suggestion] · Persistence tests lack a multi-entry round-trip oracle

The new fuzz target never reloads its output, and the functional round trip covers only one transaction, leaving loss or merging of witness variants unchecked.

Location: src/test/fuzz/private_broadcast_persist.cpp:43 (head).

Details and suggested fix

FuzzedFileProvider::write returns a fuzzed byte count without retaining the bytes, and the target calls load followed by dump without assertions. The existing witness-variant unit tests exercise GetBroadcastInfo, not persistence. A writer or loader that collapsed entries by txid could therefore pass the added assertions. Keep the error-injection fuzzing and add a deterministic temporary-file round trip: populate a queue with two same-txid, different-wtxid transactions, dump it, load a fresh queue, and compare both the wtxid set and serialized transactions.


Link

[suggestion] · Snapshot open failures leave no persistence diagnostic

If privatebroadcast.dat.new cannot be opened at shutdown, pending submissions are not saved and neither the caller nor the dumper reports the failure.

Location: src/node/private_broadcast_persist.cpp:74 (head).

Details and suggested fix

DumpPrivateBroadcast returns at file.IsNull() before reaching the try/catch that logs commit, close, and rename failures. Its interface returns void, and shutdown subsequently destroys the in-memory queue without another diagnostic. After a normal startup has consumed the previous snapshot, a permissions, inode, or file-descriptor problem can therefore leave nothing to restore on the next run. Log a warning containing the temporary path and SysErrorString(errno) when opening fails, at least for a nonempty queue, while continuing shutdown.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Keeping a privately originated transaction out of the mempool was a defense against active origin probing, not merely a way to suppress ordinary announcements. The earlier mempool-based proposal could conceal direct responses yet still reveal possession through missing INV responses or the availability of related transactions. Historical discussion also identified maintaining such concealment over time as unrealistic.

Persistence concerns a separate, privacy-sensitive queue rather than an ordinary mempool snapshot. The original boundary was that locally originating transactions should not acquire externally observable mempool effects before returning through the network. Restoring into PrivateBroadcast preserves that architectural separation; the history does not imply that durability requires mempool admission.

Source 1 · Source 2 · Source 3

Short-lived, one-transaction anonymous connections were intended to prevent linking the sender to its ordinary network identity and to prevent linking otherwise unrelated transactions through a shared long-running connection. The design expressly accepted that a recipient could recognize an initial private broadcast, assuming it could not identify the sender.

The historical guarantee is origin unlinkability under stated network assumptions, not concealment that private broadcasting occurred. Restoring queued transactions continues to depend on those anonymous-connection properties; neither persistence nor resetting counters establishes recipient unlinkability by itself.

Source 1 · Source 2

Non-persistence was known during development, and persistence was discussed as follow-up work rather than an established prohibition. In July 2024, the author explained that transactions normally remained outside the mempool for only seconds, explicitly noted loss of the queue across restarts, and said deliberately delaying broadcast for substantial periods warranted persistence.

This supports distinguishing a deliberately scoped, short-lived queue from a durable transaction-submission service. It provides historical motivation for adding restart continuity, but specifies neither a crash-safe durability level nor a file-consumption policy.

Source 1

Unresolved disagreements

The original discussion distinguished protection against spying Bitcoin peers from protection against an observer monitoring the sender's internet traffic. Gregory Maxwell argued that predictable Tor traffic associated with transactions could weaken privacy under the latter threat model, while judging the many-spying-nodes threat more important; he proposed padding and third-party transaction broadcasts as possible mitigations.

Repeated transmission has a privacy dimension beyond whether a recipient learns the sender's IP address. The inspected record documents that tradeoff but does not resolve how restarting transmission schedules affects traffic-analysis exposure, or establish that the original anonymity assumptions cover repeated restarts.

Source 1 · Source 2