Repository navigation
Reimplement private broadcast as node state-less jobs + package relay support - #36608
instagibbs wants to merge 35 commits into
Conversation
Empty commit marking where the parts of this pull request begin. Part 1 moves code that bitcoin-privbcast shares with the node into the common library and exports what it needs from net and netbase. No behaviour change.
bitcoin-privbcast (added later in this series) links the BIP324 cipher without the node library. The cipher depends only on crypto, keys, randomness and chain parameters, which the common library already provides.
The transports and the messages they carry are needed by a tool that
must not link the node library (bitcoin-privbcast, added later in this
series). Move them, with NodeId and MAX_PROTOCOL_MESSAGE_LENGTH, to
net_transport.{h,cpp} in the common library. net.h includes the new
header and drops the includes that only the moved code used; files that
name NodeId include the new header themselves.
net.h includes the new header first, where bip324.h was: Qt's moc reads
net.h through the GUI's headers and cannot parse libstdc++'s <concepts>
unless an earlier header has defined _GLIBCXX_VISIBILITY.
Move-only: no code changes.
Empty commit marking the start of part 2: the specification and the standalone tool. Nothing in the node changes.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, 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. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
Possible places where comparison-specific test macros should replace generic comparisons:
2026-10-22 17:41:53 |
This is the design the following commits implement: what a private broadcast job guarantees, the values peers and observers see, and the interfaces of the tool and the node. Later commits cite its items by number.
Start bitcoin_privbcast, the library that will run private broadcast jobs for bitcoin-privbcast and the node. params.h holds the values of the specification. DrawPlan draws a job's plan from the job's own randomness: the schedule, the order of the DNS seeds and the seed of the order in which each DNS seed hands out its candidates. MIN_DNS_SEEDS is the floor R3 sets for the mainnet seed list, and a unit test holds the list to it, so a release that drops seeds below what fills a job fails the test rather than leaving opportunities empty. Implements C1 and R3; the values of Parameters.
Assign fixes every opportunity's candidate once discovery ends, from the plan and the discovery result alone. An endpoint that several seeds returned is credited to the seed that comes first in the plan's seed order, through the lowest query set that returned it. Each seed hands out its candidates in an order drawn at random by a generator of its own, seeded from the plan and the seed's place in that order. Slot j's first attempt comes from query set j mod 4 whenever a seed it may draw from has one, so a single exit supplies at most two first attempts. Neither which seed answers first nor the order of a seed's answers changes the assignment. Implements C2, R2, R4, R5a, R5b and R5c.
A job reaches recipients and resolves DNS seed names through the proxy, on streams its event loop drives without blocking. Socks5Client holds no socket: it offers the bytes to write, consumes the proxy's replies, and leaves bytes past the final reply to the P2P transport. It offers only username and password authentication, with the credentials it is given or fresh ones, and sends a numeric address as IPV4 or IPV6 without resolving anything. Implements B2 and the Proxy interface section.
An attempt is one connection to a recipient once the proxy connected it: a BIP324 session as initiator, the handshake with the job's VERSION, one INV, the transaction served at most once, and the PING. It holds no socket and reads no clock: the job's loop passes the bytes read and the time; each call records what happened (a completed write, the connection, bytes received) and then enforces the attempt's deadlines, so that nothing is acted on at or after one. The attempt draws its VERSION and PING nonces from the random context it is given, and takes its BIP324 key, ellswift entropy and garbage from a key source. Without one, as in production, V2Transport draws them from the strong RNG. The tests and the fuzz target inject a source that draws from their seeded context, so that an attempt's bytes are a function of that context and of what the peer sent. Implements E1-E8, A2, B4, D3 and the attempt part of D2.
A job reaches the network only through streams to the SOCKS5 proxy, which its event loop drives without blocking. ProxyStream connects to the proxy by address or unix socket path, resolving nothing, and runs the exchange of its Socks5Client; each stage, the connect and each step of the exchange, times out on the steady clock. Once the proxy has connected the stream, its socket carries the destination's bytes. Discovery launches every RESOLVE query at job start, each on a stream of its own, in four query sets: each set has credentials of its own and one query of every seed, so Tor builds four circuits rather than one per query, and each seed is still asked through four exits. Discovery ends when every query has ended or when the discovery window does, whatever is still pending. It keeps the answers that are public routable IPv4 or IPv6 addresses, with the chain's default port, and counts the others; its result gives each seed's answers by the query set they came through, whatever order they arrived in. An exception thrown while it acts on one query ends only that query, as a failed stream would. The tests run discovery against a scripted proxy behind fake sockets that connect as non-blocking sockets do. The fake socket and the proxy's side of the SOCKS5 exchange go into the test utilities, as the job's tests use them too. Implements B1, B2, C3, D1, R1, R2 and C7 for the queries.
A job is one event loop on its caller's thread. Step() runs the deadlines and the dials that are due, waits on every open stream until the next deadline, and does the I/O; Run() steps to the end. The plan is drawn when the job is made, before any socket exists, and discovery starts with the first step. When discovery ends the assignment is fixed, and each slot dials its opportunities at their scheduled times, one attempt at a time, until one reaches the announcement point or none is left. The slots share only the loop, so a stalled stream holds up no other slot, and the cancel flag ends everything at the next step. An exception thrown while the loop acts on one attempt ends only that attempt, as a failed stream would. One thrown anywhere else in a step fails the job: it stops as a cancelled job does, and its report gives the error. The report mirrors Interface/Report, every time an offset from job start on the plan clock. Snapshot() gives the progress the node is to show, from any thread. ExitStatus() gives the tool's exit status for a report. Implements A1, A3, A4, C1-C8, D1, D2, H1, H3 and the report interface.
The SOCKS5 server gains Tor's RESOLVE command, reply delays for a slow or stalled proxy, a mode that offers only unauthenticated access and a mode that behaves as an ordinary non-Tor proxy. A client that hangs up before its greeting, as a cancelled job's streams can, and a connection that Windows reports as aborted count as closed, not as errors. The P2P network thread judges a failed protocol by its own reconnect flag, so that several listeners can share one loop. The framework learns where bitcoin-privbcast is and how to skip a test without it. Prepares the functional test that the next commit adds with the binary.
The standalone tool: it reads one transaction on stdin, runs one job through the Tor proxy named by -tor and prints the report on stdout, with progress lines on stderr. It takes no configuration file and only a loopback proxy, refuses the regtest overrides on other chains and checks its arguments and input before any network activity. The discover command runs discovery alone. Build and packaging: the BUILD_PRIVBCAST option (on with BUILD_TESTS), the privbcast subcommand of the bitcoin wrapper, the man page, the Windows resource file, the manpage generator and Windows CI lists, and the test configuration that tells the functional framework the binary exists. The functional tests tool_privbcast.py, tool_privbcast_proxy.py and tool_privbcast_peers.py, with their harness in test_framework/privbcast.py, are the specification's black-box acceptance suite for the tool: scripted recipients and a scripted proxy check every wire-visible parameter, the schedule, the assignment, the exit statuses and cancellation. Implements B3, H2, U1 and the Interface section for bitcoin-privbcast.
Add the user guide to private broadcast with its bitcoin-privbcast part: the Tor proxy the tool needs, how to send a transaction and read the exit status and the report, discover, and the limits of what a job protects.
Empty commit marking the start of part 3: the node runs each private broadcast as the tool's job, and the old relay and connections are removed.
The node runs each private broadcast as a privbcast::Job, the tool's job, on a thread of its own. PrivbcastQueue queues the submitted transactions, starts and cancels the jobs from one scheduler thread, and keeps in memory the records that getprivatebroadcastinfo and abortprivatebroadcast are to show. It reaches the node only through callbacks for networking, the onion proxy and the mempool, and takes the job runner as a parameter, so that the tests drive it with stub jobs and mocked clocks. A job that failed, or whose runner threw, ends aborted with the error in its record. The scheduler's start rule is a pure function, StartPolicy::Decide(), which each pass of the scheduler applies: a fuzz target checks the rule on its own, and another the queue through its interface. bitcoin_node now links bitcoin_privbcast. Implements N3-N7, N9, N10, the node's D2 and D3, U3. Not yet wired: the next commit switches -privatebroadcast to it.
With -privatebroadcast, sendrawtransaction now queues a job on the node's PrivbcastQueue instead of handing the transaction to the connection manager, getprivatebroadcastinfo lists the jobs with their progress and reports, and abortprivatebroadcast aborts them. Startup requires onion to be able to become reachable, refuses the regtest seed overrides on other chains, -signetseednode, -signetchallenge, and off regtest a non-zero -mocktime, and refuses to start rather than trim connections when the jobs' file descriptors are not available. -connect and -proxyrandomize no longer matter. The old private broadcast connections and relay stay in the tree, no longer fed, until the commits that remove them. Implements N1, N2, N8, N10, N11, U1, U2 and Interface/Node; replaces the old implementation's tests with the specification's.
Since -privatebroadcast runs jobs, nothing hands PeerManager a
transaction for private broadcast any more. Remove its queue
(src/private_broadcast.{h,cpp}) with the methods, the retry task and
the private_broadcast option that served it, and its handling of
private broadcast connections: the fixed VERSION, the INV after
VERACK, the GETDATA and PONG handling, the incoming message filter,
the lifetime limit and the exemption from discouragement. The unit and
fuzz tests of that code go with it, including the net_tests case for
the addrman exception and the denialofservice_tests cases for the
discouragement exemption.
Delete-only: besides whole lines, conditions and arguments are cut out
of lines, and the lines of a removed branch's alternative move out one
indentation level. git show -w --word-diff-regex='[A-Za-z0-9_]+|[^[:space:]]'
shows deletions only, apart from the size of the node array in
denialofservice_tests, which goes back from 5 to 3.
With the relay gone, nothing asks CConnman for private broadcast connections. Remove the connection type, the thread that opened such connections with its counters and choice of network, and the places that treated them specially: the incoming nonce check, the fresh I2P session, the guard against direct connections, the outbound message filter, the fixed protocol version, the exception in disconnection by subnet and their term in the orphanage's static_assert. The type's names go from getpeerinfo's help, bitcoin-cli -netinfo and the GUI. The proxy override of ConnectNode() and OpenNetworkConnection(), which only that thread set, goes too, with its copy in CNode and in the reconnection record and the fuzz input for it. Delete-only: besides whole lines, conditions, arguments and list separators are cut out of lines, what followed a cut argument joins its line, and one line moves out an indentation level with the if around it. git show -w --word-diff-regex='[A-Za-z0-9_]+|[^[:space:]]' shows deletions only.
Without private broadcast connections, a node advertises PROTOCOL_VERSION on every connection, and CNode::AdvertisedVersion() only returns it. Use the constant again where the method was called.
Add the node part of the private broadcast guide: which Tor proxy the jobs use, how sendrawtransaction queues them and when they start, what is not queued again, how to follow and abort jobs, what disabling networking and shutdown do, which node settings do not apply, what the default log shows, the file descriptors the jobs need, and the link between a job's connections and the node's peers at shutdown.
Empty commit marking the start of part 4: one parent and its child. The validation commits here serve only this part.
A child can pay for a parent too cheap to enter mempools alone when the recipient takes the two together. A job may now carry the parent: each attempt announces only the child, serves the parent to a peer that asks for it, and holds the PING for that request. A job without a parent runs and reports as before. Implements F1-F4 and the package amendments of E6-E8.
bitcoin-privbcast send also reads two transactions, an unconfirmed parent and its child in either order, checks that they are such a pair and runs the job in package mode. The acceptance suite gains its package sections in tool_privbcast_package.py. Implements the Extension's Interface for bitcoin-privbcast.
Two prioritisetransaction deltas near INT64_MIN made the sum overflow.
|
in draft, #36628 is the slimmed down branch to review |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
not being considered at the moment, can be resurrected easily |
|
Thanks for bringing in a fresh perspective, if not else, it's a good base for further discussions (despite that it's closed now). I tried to expand on the comparison with the current implementation (master) from the description.
For reference, the common fallback, Also, mainnet has exactly 7 DNS seeds, and Design questions I attempt to list the various dimensions in the design space:
Several of these are independent of each other. For example, separate connection code doesn't require DNS-seed targets. Most likely direction? To me, 36608's main benefit is that targets don't come from the node's addrman, which closes the planted-address attack (an address gossiped only to the victim). DNS seeds alone is also the most contentious part, though: liveness, the 7-of-7 seed margin, and every connection through an exit. Changes to master that seem more likely:
|

Goals
Goal 1: Remove reliance on, and probes about, internal node state from private broadcast
Goal 2: Specify observable behavior to aid reimplementation and reduce profile fingerprints across versions
Layout
Four parts, each starting with an empty marker commit:
For the v33 release, I think 1 through 3 should be the goal, but the roadmap could be trimmed down to remove tool-only code if the conceptual support for the standalone tool is not there.
The tool itself introduces about 600 loc of logic, and also necessitates some of the prep move-only commits putting things in common. The vast majority is the shared Job machinery.
Node-less state
The primary failure mode of the in-master private broadcast is that it relies on node state for operation, and this has led to a number of "careful coding" fixes:
There are many other sources of fingerprints as well, some harder than others to exploit, and to fix. The solution: remove reliance on node state entirely to drive attempts. The spec states the goals as:
Jobs, slots and opportunities
The times are drawn at job start, and each opportunity's candidate is fixed when discovery ends, before any peer is contacted. Nothing a peer does moves them (C1–C4). A job makes at most 24 connections, at most 6 of them at once.
Differences at a glance
bitcoindonlybitcoind -privatebroadcast, or the standalonebitcoin-privbcastwith no node; the same job either way (U3), with a JSON report of every connectionaddrman.Select()over onion, I2P, and IPv4/IPv6 through the proxy; networks follow-onlynetCConnmanpeers of typePRIVATE_BROADCAST, visible ingetpeerinfosubmitpackagewith one parent and one child: announce the child, serve the parent on requestNo addrman
Under master, the node's private broadcast destinations are drawn from the node's addrman. Other parties write to that table through addr gossip, which makes it a unique fingerprint vector, and inherently attacker influenced. This rules out drawing recipients from anything the node or its peers can write to.
Its replacement is querying DNS seeds in a predetermined way under a static profile. This is inherently less robust than the p2p network in terms of liveness, but leaves no fingerprint within a release. The marginal fingerprint is the set of DNS seeds per release, which affects who is queried and exactly how. Each RESOLVE returns one address and exits cache answers, so each seed is asked through several exits: 4 Tor circuits, each querying all 7 seeds, for up to 28 results, which are assigned to the 6x4 opportunities before any dialing happens. A circuit per query, 28 in all, kept Tor busy enough that overlapping discoveries lost answers.
If the list shrinks, grows, or is modified, the release is revealed to the Tor exits carrying the queries, which see every seed name queried. A DNS seed learns only that it is on the list, and only when the exit has no cached answer.
The fingerprint potential also precludes fixed seeds, which change greatly each release, and which degrade in connectivity over time regardless.
Minimal release fingerprint
Once a release is cut, behavior profiles are intended to be identical per user. This precludes user knobs and per-instance parameters, and requires a constant user agent and VERSION.
Across releases, the reimplemented p2p message state machine allows better control of unnecessary profile breaks going forward.
Specification
doc/design/private-broadcast-tool.mdcomes before any code in part 2. It has goals, a threat model per party (recipient, exit, seed, network observer, guard), 54 numbered invariants (A–U, N), parameters, interface, assumptions, non-goals and a rationale. Code comments and tests cite the invariant IDs, so review can check code against a stated property. Concept review of the goals, threat model and non-goals is most useful first, then review of the implementation against the invariants.This implementation is actually the second implementation, initially implemented solely via the spec and black box tests, which were handed to an otherwise blind agent.
Tradeoffs
getprivatebroadcastinfonow reports jobs, and the connections no longer show ingetpeerinfo.