Repository navigation
Private broadcast as node-less jobs, reimplemented from the specification - #7
instagibbs wants to merge 35 commits into
Conversation
af8348b to
76976f0
Compare
|
I need to removed the fixed onion seeds as trivial version fingerprint, and need to more fully flesh out design issues that involve fingerprints via seeder more generally |
|
Thanks for sharing this approach. I realize this is still WIP, so just sharing some high level feedback: I agree generally with the goal. Moving the logic out of net_processing and removing dependence on node state should help reduce unintended privacy leaks. A separate tool could also be useful for users not currently running a node. Supporting 1P1C package relay out of the box is a big improvement! This is a lot of code change. It might make sense to try and simplify the change so it can be more easily reviewed. Why has i2p been removed? I think having more network diversity here would improve reliability. Is this an explicit design decision due to an inherent weakness, or is it to reduce complexity? I am not sure about using the built-in DNS seeds to source addresses.
We explicitly added |
|
Thanks for taking a look.
While it's a lot of code, it can be split up into multiple PRs, each compartmentalized and hopefully well-tested. I was unable to make this dramatically simpler, even when I delete ~all "goal 2" requirements of trying to not leak things between opportunities.
These are tied together in a way. Other than wishing to reduce the total loc changed, torv3 and i2p addresses don't fit in Tor's RESOLVE record responses, so the state machine would need to be extended into a slightly more involved state machine with RESOLVE->getaddressinfo->dial. We would still require dns seeds, otherwise we don't know who to ask. Another strategy is we could reduce the number of circuits by having a single circuit (via one exit) do RESOLVEs against all the dns seeds. During the discovery phase that would drop it down to 7 circuits, though you still need individual circuits for each opportunity. Given that, I'm not quite sure what it would buy. We would be able to RESOLVE a few times less. The real gains from that would mostly be not having to fire up N circuits per seeder during the discovery phase. I've run fairly extensive tests and have seen no indication that this many Tor circuits is a problem, but more testing is probably warranted. The real gain from doing "RESOLVE->getaddressinfo->dial" seems to be i2p support, but I have done no benchmarking on this front, including testing a client would actually get an appropriate number of i2p addresses from seeders. Even assuming it works, it still precludes i2p-only designs, as you need to get dns seeder responses first over Tor. If the user has Tor, we should just use that. I might be missing something. We can't safely use fixed seed i2p/tor addresses due to fingerprint potential across releases, and the decay quickly regardless, based on my testing.
This would be a unique fingerprint to their node. I don't think we should offer users this.
Yes, for block connectivity, we definitely should not be increasing reliance on the dns seeds. Usage in the context of the propose private broadcast functionality carries no such risk. Any realistic solution I see is solved by dsn seeders, or downstream of things they hand us via getaddressinfo. === wrt DNS seed rotation in releases, looks like:
So over time there is a mild fingerprint still, as churn is induced, with additions/modifications being the largest vector. side-note: I need to also modify the implementation to not silently run short of candidates for a job if dns seeds are removed. |
76976f0 to
dce7bf1
Compare
|
removed fixed seeds support, increased ANSWERS_KEPT_PER_SEED to 4 to stay at parity of usable responses doing some more Tor benchmarking to see how problematic discovery can get under load Might need to switch from 28x1 RESOLVEs to 4x7 which would mean only 4 Tor circuits based on the below: Each job makes 28 mainnet RESOLVEs through the local Tor (0.4.9.13). Only answers inside the 18 s window
iow, 4 concurrent jobs in 47 config seem to do as well as 1 concurrent job in 281. The number of tor circuits dominates it. |
dce7bf1 to
f3811f1
Compare
|
Implemented the 4x7 "query sets":
Another alternative would be to drop RESOLVE and do CONNECT stream instead so we could get N results from a seeder at once. This would require us doing DNS resolution ourselves including choosing a resolver and parsing responses. Sounds not worth it. |
e67b5a0 to
7d9534a
Compare
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.
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.
ProcessNewPackage's test mode checks each transaction without package feerates or replacements, as testmempoolaccept does. With test_as_submission it runs submission's evaluation instead and stops short of the mempool, so a caller can learn whether a child pays for its parent before relaying them. A transaction that passed before another failed is reported by its own result, as submission reports it. Results do not list replaced transactions, and a parent that passes alone gives no answer for its child, which it does not stage. From bitcoin#35286, without its RPC.
A test does not stage a transaction that passes alone, so the child that spends it was found missing its inputs. Test the new transactions together instead, each paying for itself. Their replacements get package RBF's checks of fees, feerate diagram and cluster limits, but not its rules that the package have no mempool ancestors and pay more per vbyte than the parent: submission would take the two in turn, each replacing what it may. A replacement of an ancestor of the package is refused instead, as it would take away the package's inputs. For a parent and child this accepts at least what submission accepts.
d353967 to
463f985
Compare
With -privatebroadcast, submitpackage now queues a private broadcast job instead of adding the transactions to the mempool. It takes one transaction, or a parent and its child, and queues one job, the child's, which carries the parent. A transaction whose txid is in the mempool counts as accepted; the rest is test-accepted, one transaction alone as by sendrawtransaction, two as a package, after the package checks on the whole submission, two as submitpackage evaluates them. maxfeerate follows each path's own convention. Unit tests drive the RPC through its table. The queue takes the parent with the transaction: a submission with a parent is covered only by a job with the same parent, one without by a job with any parent. getprivatebroadcastinfo lists the parent's txid and documents the report's package fields; abortprivatebroadcast matches the child's ids only. Both submission RPCs ask the queue whether an onion proxy is configured, which lets unit tests drive them without the process-wide proxy registry. The acceptance suite gains its package sections, run as p2p_private_broadcast.py --package. Implements the Extension's N5 and N11 amendments and its Interface for submitpackage.
Add the specification's section "Extension: one parent, one child", which the preceding commits implement: a job that carries a child and its unconfirmed parent announces only the child and serves the parent on request (F1-F4), and the tool and the node take such a pair.
Add the guide's part on a parent and its child: when it helps, which recipients accept such a package, what the tool and the node check and what peers can tell; and how submitpackage queues a job under -privatebroadcast.
463f985 to
eec78cc
Compare
…:__pad_and_output fa3821e test: Add missing suppression for race:std::__1::__pad_and_output (MarcoFalke) Pull request description: From https://github.com/bitcoin/bitcoin/actions/runs/41684419453/job/126086262840?pr=35990#step:11:8669: ``` WARNING: ThreadSanitizer: data race (pid=17903) Write of size 8 at 0x7ff5c1990c20 by thread T12 (mutexes: write M0): #0 width /llvm-project/libcxx/include/ios:498:18 (libc++.so.1+0xd3816) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306) #1 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output[abi:dee230102]<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) /llvm-project/libcxx/include/__locale_dir/pad_and_output.h:67:9 (libc++.so.1+0xd3816) #2 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>>::__do_put_integral[abi:dee230102]<long long>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, std::__1::ios_base&, char, long long) const /llvm-project/libcxx/include/__locale_dir/num.h:907:10 (libc++.so.1+0xbcfa0) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306) #3 std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>>::do_put(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, std::__1::ios_base&, char, long long) const /llvm-project/libcxx/include/__locale_dir/num.h:919:16 (libc++.so.1+0xbcb79) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306) #4 put /llvm-project/libcxx/include/__locale_dir/num.h:780:12 (libc++.so.1+0x9b40c) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306) #5 std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::basic_ostream<char, std::__1::char_traits<char>>::__put_num[abi:dee230102]<long long>(long long) /llvm-project/libcxx/include/__ostream/basic_ostream.h:104:21 (libc++.so.1+0x9b40c) #6 std::__1::basic_ostream<char, std::__1::char_traits<char>>::operator<<(long long) /llvm-project/libcxx/include/__ostream/basic_ostream.h:316:10 (libc++.so.1+0x9b2a0) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306) #7 KernelLog::LogMessage(btck::LogEntry const&) /home/runner/work/_temp/src/bitcoin-chainstate.cpp:49:33 (bitcoin-chainstate+0xf2667) (BuildId: cff46198c8fd29997404a749cd55fdd6fcb3e865) ACKs for top commit: fanquake: utACK fa3821e Tree-SHA512: 383705fe33e429d40baaf7811a3edd6ce5164c423a1450c7a7a5d749d1ba44b8dac7a1270cbb593fcd0888dd9a2efbe7507650adf69b2f46ac09db4488cb9aec
This is a second implementation of the design in #5. It was written from the specification
(
doc/design/private-broadcast-tool.md) and the black-box test suite alone, without reading #5'scode, and then compared with #5. The goal is the same: broadcast
a transaction without revealing the sender's IP address, onion address or node identity, by not
letting the local node's state influence the broadcast at all.
The design is specified in
doc/design/private-broadcast-tool.md: goals, threat model, invariants,parameters, interface, assumptions and non-goals. Usage is in
doc/private-broadcast.md.This PR is the whole series. It splits into four PRs, each mergeable in turn (branches
privbcast-1-supporttoprivbcast-4-package):net.h(move-only), and fixed-seed decoding is pulled out ofConvertSeedsfor reuse.its unit and fuzz tests (parameters and schedule, candidate assignment, a byte-driven SOCKS5
client, the attempt, proxy streams and discovery, the job), then the test harness,
bitcoin-privbcastwithtool_privbcast.py, the user guide and release notes.-privatebroadcastruns jobs, with master's tests replacedin the same commit; two delete-only commits removing the old relay and connection code (
git show -w --word-diff-regex='[A-Za-z0-9_]+|[^[:space:]]'shows deletions only);AdvertisedVersion()dropped; guide and release notes.
submitpackage; thespecification's extension section, guide and release notes.
The tool is useful on its own after step 2.
Compared with
-privatebroadcaston masterbitcoindup to 18 jobs overlapNODE_NONE, no wtxid relay, announces by txidNODE_WITNESS, protocol 70017, wtxid relay required (BIP339)bitcoin-privbcastprogramGiven up: I2P, peers that speak only v1, the node's address manager, and re-sending when the
transaction does not come back. The remedy for a transaction that did not arrive is another job.
Compared with #5
src/privbcast/; netbase untouchedTimingpassed in; tests drive the loop over fake clocks and socketsThe extra production lines are mostly the SOCKS5 client (about 420), the typed report (about 330),
the node queue (about 280) and the plan and assignment code (about 220); #5's attempt and discovery
code is the larger. The second SOCKS5 client is the main cost: netbase's client
blocks and takes its timeout and interrupt from process-wide globals, which is what forced #5 into a
thread per slot. If reviewers want one implementation, this client can move into common code with
netbase's
Socks5()rewritten as a blocking loop around it, as a change in the first PR.Comparing the two also found places where #5 does not meet the specification; this PR meets each:
-signetseednodeand-mocktimeare not refused (U1), and-listenonion -onion=0starts althoughonion can never become reachable (U2);
-signetchallenge;at a deadline (H2);
can overlap after a jump (N4);
Specification changes since #5
C7: an internal failure in one attempt or discovery query ends only that attempt or query. C8: no
exception for a TCP connect under way. D2: when a slot ends. R4 and R5b: a shared endpoint is
credited to the first of its seeds in the drawn order, a seed's kept answers are a random choice,
and a slot takes a candidate from a seed it already used rather than leave an opportunity empty. H2:
exit status 0 if any INV was fully written even if the job failed afterwards, else 1 for a usage,
input or job failure, 2 for a job that ran without failing;
summary.errorreplaces the per-sloterror. U1: the tool, and the node with-privatebroadcast, refuse-signetseednodeand-signetchallenge; the node refuses-mocktimeoff regtest. U2:-onion=0refused with-privatebroadcast. N3: after a backward clock step a start also waits for an open discovery (N4first). Interface: the tool reads no configuration file;
seen_in_mempoolis set from submissionwhen the txid is already in the mempool. Extension: the package input rule no longer requires the
spent parent output to be spendable;
submitpackagecounts fees and sizes as validation does;abortprivatebroadcastmatches a package job by its child only.Testing
tool_privbcast.pyandp2p_private_broadcast.py(each also with--package),p2p_private_broadcast_cap.py, and the-privatebroadcastchecks infeature_config_args.py,feature_init.pyandfeature_signet.py. Every invariant it claims to check was confirmed bymutation against Create privbcast tool, swap out in-node implementation for node-less driving #5's implementation: 98 mutants, each failing the intended test.
privbcast_*_tests, and the fuzz targetsprivbcast_attempt,privbcast_discovery,privbcast_socks5,privbcast_input,privbcast_queueandprivbcast_start_policy. A mutation pass designed from the invariant map: all 108 mutants ofmapped items were caught (84 by the unit case the map names, 17 by the named fuzz target, 7 by
another suite); of 36 further mutants, 4 survive, all behaviours the black-box suite checks.
the four tips the whole functional suite, the lints and a clang
-Wthread-safety -Werrorbuildpass. Not run locally: libc++ and Windows builds.
discoveron mainnet, testnet4 and signet; on mainnet, sends ofunconfirmed transactions taken from mempool.space (exit 0; requested and PONGed by peers that
lacked the transaction); on signet, a new transaction (served by two peers, in a separate node's
mempool 30 s after the job started) and a TRUC parent with its fee-paying child (the peer asked for
the parent 4.3 s after receiving the child; both in the separate node's mempool after 42 s).
Not done yet: node mode against real peers, a rebase onto current master, and seed inputs for the
new fuzz targets in qa-assets (the attempt target needs a corpus to get past the handshake).