mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
[DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) #35591
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!35591
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-05-erlay-recon-only-full-impl"
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?
Erlay Project Tracking: #30249
Conceptual Discussion: #34542
This is a full implementation of Erlay. Its purpose is to check the integrity and correctness of the implementation against changes/additions that may originate from the review process and/or rebases on top of newer functionality.
This is not to be merged. Functionality will be spread across multiple smaller PRs to ease the review process.
Approach
This approach uses Erlay as a fallback mechanism for transaction propagation. Instead of mixing fanout and reconciliation into a single connection type, the current approach leaves the existing connections as they are, and adds additional low-bandwidth connections to be used in case the node is being eclipsed. This connections should have minimal cost under normal circumstances, and only undergo real traffic in case other 8 full-outbound connections are being captured.
outbound-full-reconciliation connections
For now, we are adding 4 additional reconciliation-only connections to the node while we test it's impact on real node running the approach. Further analysis may be needed to pick a meaningful value for this. The number of inbound connections should also be scaled based on how many connections we are adding.
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:
-Wunusedby fanquake)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 typos and grammar issues:
src/node/txreconciliation_impl.cpp:all out outbound neighborhood→all outbound peers[duplicated/misspelled wording]src/node/txreconciliation_impl.cpp:now matter at which phase→no matter at which phase[wrong word]src/test/txreconciliation_tests.cpp:6x marging→6x margin[misspelling]src/test/txreconciliation_tests.cpp:snapsotted/snapshop→snapshotted/snapshot[misspellings]test/functional/p2p_txrecon_initiator.py:one one tx→one tx[duplicated word]test/functional/p2p_txrecon_initiator.py:matches out sketch som no diff→matches our sketch, so no diff[misspellings]test/functional/p2p_txrecon_responder.py:inital request→initial request[misspelling]test/functional/p2p_txrecon_responder.py:one of out transactions→one of our transactions[wrong word]Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):test/functional/p2p_txrecon_initiator.py:self.generate_txs(self.wallet, 0, 10, 0)test/functional/p2p_txrecon_initiator.py:self.generate_txs(self.wallet, 0, 0, 2)test/functional/p2p_txrecon_initiator.py:self.test_reconciliation_initiator_no_extension(3, 3, 20)test/functional/p2p_txrecon_responder.py:self.generate_txs(self.wallet, 0, 1, 0)test/functional/p2p_txrecon_responder.py:self.test_reconciliation_responder_flow_no_extension(3, 3, 20)Possible places where comparison-specific test macros should replace generic comparisons:
test/functional/p2p_txrecon_disabled.py:assert self.nodes[0].process.poll() is None→ Preferassert_equal(self.nodes[0].process.poll(), None).test/functional/test_framework/p2p_txrecon.py:assert message.nVersion >= 70016→ Preferassert_greater_than_or_equal(message.nVersion, 70016).2026-11-30 12:52:28
Rebased on master.
Opening this so it can be tested against CI and to make sure nothing obvious is missing. Next step will be testing with real nodes (most likely in Warnet).
Things to consider/add:
sendtxrcncl. It may be worth considering an approach based on BIP-434.Fixed some typos and addressed some of the linter suggestions
6554707...e63db1a
Fixed several bugs and added a new test for receiving reconciliation messages when reconciliation is not enabled.
e63db1a...23053a3
Fixed several bugs and added a new test for receiving reconciliation messages when reconciliation is not enabled.
e63db1a...35bcd04
Addressed some issues pointed out by corecheck.
35bcd04...280d603
Addressed some issues pointed out by corecheck.
35bcd04...d08f127
Testing report (LLM/experimental) based on the results of an incremental mutation testing run for this PR - full result is avaliable at: https://bitcoincore.space
The overall result is mixed. The PR already has useful coverage for the happy-path reconciliation flow, basic protocol violations, and some queue/timer behavior. However, the survivors show that the tests still leave several important behaviors only weakly specified, especially where reconciliation falls back, extends, or interacts with INV relay bookkeeping.
What the current tests do well
The existing tests cover the basic handshake and some normal flows reasonably well:
That baseline is good enough to kill most straightforward mutations. The survivors are mostly about what happens around the edges of the protocol, not the central flow.
Main gaps exposed by the surviving mutants
1. Extension handling is under-tested
This is the clearest gap. Several survivors change extension behavior without being detected:
REQSKETCHEXTafter an undecodable sketch innet_processingThis lines up with the current functional tests: both initiator and responder tests explicitly stop short of extension coverage and even leave TODOs for it in test/functional/p2p_txrecon_initiator.py and test/functional/p2p_txrecon_responder.py.
What should be improved:
REQTXRCNCL -> SKETCH -> REQSKETCHEXT -> SKETCH -> RECONCILDIFF2. Boundary conditions are not pinned down tightly enough
Several survivors change strict inequalities to inclusive ones and still pass:
remote_sketch_capacity > MAX_SKETCH_CAPACITYchanged to>=extended_capacity > MAX_SKETCH_CAPACITY * 2changed to>=peer_q > Q_PRECISIONchanged to>=This means the tests exercise invalid-above-limit cases, but not the exact boundary values that should remain valid. There is already a good example of this style for rounded
qformatting in src/test/txreconciliation_tests.cpp, but the same precision is missing for protocol acceptance thresholds.What should be improved:
MAX_SKETCH_CAPACITY,2 * MAX_SKETCH_CAPACITY, andQ_PRECISIONlimitmust pass,limit + 1must fail3. INV relay side effects are only partially asserted
Many survivors in
PeerManagerImpl::AnnounceTxs()and the send path inSendMessages()remove or alter important side effects without breaking tests:continuetobreakwhen one candidate should not be sentm_tx_inventory_known_filterm_tx_inventory_to_sendMAX_INV_SZThe current tests mostly check that transactions eventually arrive. They do not strongly check how they are batched, filtered, or suppressed from future re-announcement. That leaves a lot of bookkeeping mutations alive.
What should be improved:
MAX_INV_SZand verify the number and sizes of INV messages4. Some state-management behaviors are observable in principle, but not asserted
Survivors also show weak checking around reconciliation state transitions:
m_short_id_mappingTryRemovingFromSetm_announced_while_reconcilingThese are not all equally severe, but together they indicate that the tests often validate the final external effect of a single round without checking the follow-up round that would expose stale state.
What should be improved:
Bottom line
The current tests are good at proving that the basic txreconciliation flow works. They are not yet strong enough to fully specify the extension path, the exact protocol boundaries, or the internal bookkeeping that prevents duplicate, truncated, or stale announcements.
If I had to prioritize follow-up work, I would do it in this order:
q.That would likely eliminate most of the meaningful survivors from this run and materially improve confidence in the PR’s tests.
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased to include the latest changes in master, including the changes introduced in https://github.com/bitcoin/bitcoin/pull/34628.
Reworked the transaction announcement logic so most of it can be re-used by the trickle code path and the new post-reconciliation code path.
Also started to killing @brunoerg reported mutants.
d08f127...41de5f9
🐙 This pull request conflicts with the target branch and needs rebase.
Finished covering the most relevant mutants. Left out the ones regarding extensions, as I'm still debating whether those will be part of the PR.
41de5f9...816d2cd
Rebased master to cover https://github.com/bitcoin/bitcoin/pull/35852, and applied the inline const(expr) convention introduced by the PR to cover new definitions.
816d2cd...d34d736
Fixes several uncovered edge cases.
d34d736...7937670
Fixed several uncovered edge cases.
d34d736...b0186aa
Added benches for how long it takes to build and decode sketches based on their capacity. This may affect the max sketch capacity that we may accept to work with.
ReconcileSketchConstructReconSetMaxReconcileSketchDecodeExtensionMaxReconcileSketchDecodeMaxCapacityReconcileSketchDecodeReconSetMaxReconcileSketchDecodeTypicalThis results in the following:
MAX_RECONSET_SIZE) takes ~120msThis applies only to outbound peers, as those are the ones that makes us decode. This bears the question, should we limit the maximum sketch size that we accept far bellow
MAX_SKETCH_CAPACITY?In the case of Core nodes, sets cannot have more than
MAX_RECONSET_SIZEelements. So the maximum sketch sizes are 3001 for the initial sketch, 6002 for an extension.b0186aa...62bf7d1
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/32289116534/job/96185584884LLM reason (✨ experimental): CI failed because IWYU detected and rejected incorrect/missing
#includeordering/content (generated “Failure generated from IWYU” forsrc/bench/txreconciliation.cpp).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
This should be ready to review at this point, even though some details still need deciding. Happy to split the PR into smaller chunks if it makes it easier.
Open questions (that may arise from reviewing parts of the code):
MAX_RECONSET_SIZEthan toMAX_SKETCH_CAPACITY?🐙 This pull request conflicts with the target branch and needs rebase.
Rebased e366778...534a890
Could reconcilitation peers exceed
m_max_outbound_full_reconduring v2-to-v1 fallback? Thinking about a possible race.I got 31.2 seconds on my machine (Ryzen 9 7900). Wondering if a malicious peer could use it to cause a DoS since it would block all msgs processings?
nit: I think that, according to the BIP330, we must accept 0 or 1 here. This way it would treat any nonzero byte as true.
Yes, I think it can. I left a comment on this earlier on the PR.
Given this is quadratic, I think limiting the size of the sketch (and potentially getting rid of extensions) will make it less of an issue.
https://github.com/bitcoin/bitcoin/pull/35591#issuecomment-5354604209
You're right, will change
I took a look at this, and I think we can overshoot it by 1 if there is a race between a v2-to-v1 downgrade and the opening of a new full recon connection. Since we do not check for extra reconciliation peers in
EvictExtraOutboundPeers, we can end up with an extra connection.I will note this, I think it can be handled alongside deciding whether we want to count reconciliations connections as full outbounds (we will need eviction logic in that case too).
Addresses @brunoerg comments.
I changed the way we parse
recon_resultto mimic the check we already have in place for BIP152. Also added a test for it.Regarding the race, I left a comment so we can address it when addressing general recon connection eviction.
I'd appreciate your input on whether
OUTBOUND_FULL_RECONCILIATIONshould be considered full outbound, and on whether extensions are worth keeping.534a890...25e545c
Rebased to fix CI, plus slightly decreased
MAX_INBOUND_RECONCILIATION_PEERSfor now, as some inbounds were being evicted inp2p_sendtxrcncl.pyafter #36078.MAX_INBOUND_RECONCILIATION_PEERSis currently a magic number, so we can set it properly (and increase the number of inbounds accordingly) once we decide on how to treat recon connections eviction.d08f127...0eddbbc
🚧 At least one of the CI tasks failed.
Task
ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/33909308334/job/101141694892LLM reason (✨ experimental): CI failed because the fuzz build didn’t compile:
connman.cppcallsConnmanTestMsg::GetExtraFullOutboundCount()which no longer exists (“no member named”).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
@brunoerg, I've gone ahead and added reconciliation connections as full outbound connections, and dealt with connection eviction in the same way we did for full outbounds.
I'm happy to re-work this if reviewers think this should no be seen as full outbounds, but I thought it may be best to just go ahead with an approach instead of waiting for discussion. The change is split in two commits,
ab8528650bto refactor the current logic into a method that can be reused by reconciliation connections, and a0ce6c11e2athat implements that for them.With this, I should have also covered your concern about v2->v1 downgrades, as outbound reconciliations now have eviction logic.
On top of that, I've changed the logic for when a peer does not accept our reconciliation connection. Before, we would have keept that node connected, acting as a regular outbound but taking a reconciliation slot. This is dangerous as it can lead to 12 full outbound connections, which may make us create even more redundant announcements. Now, those connections are dropped, and we look for another peer.
This can create some issues during the deployment phase, if not enough slots are available for all the new connections. I think we can mitigate the issue by deploying the feature in two phases. Phase 1 deploys the code, but only makes nodes accept incoming reconciliation connections, not start them, that is gated over a flag that is disabled by default (or even just disabled in general). Once enough deployment is reached, we can flip that feature and allow nodes to proactively initiate those. I have currently not gated this, as it makes it easier for testing, but I think it is worth mentioning.
0eddbbc...37912ec
🐙 This pull request conflicts with the target branch and needs rebase.
This could return a const ref (even though all current calls would make a copy anyway)
first set size once to skdata.size()+m_remote_sketch_snapshot.size then copy values?
Just some generic C++ comments
16 additional verified findings in the Review report.
Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive linked from the Review report for their assessments.
🔴 Major · Peer-chosen sketch capacity allows multi-second synchronous decodes on the message thread
With
-txreconciliation, an outbound reconciliation peer can make oneSKETCHexchange cost about 16 seconds of decoding under the tracker mutex, far beyond what our 3000-entry sets ever need.Location:
src/node/txreconciliation_impl.cpp:291(head).🟠 Minor ·
Assume(TryRemovingFromSet)can fail when mempool pruning races the collision handlingA short-ID collision is detected under one tracker lock and the colliding entry is removed under another, so an asynchronous
RemoveFromSetsin between aborts debug builds.Location:
src/net_processing.cpp:6151(head).🟠 Minor · A late removal callback can drop a transaction that has since been re-admitted
A queued removal notification that predates a re-admission can erase the new pending reconciliation entry, so that link never announces the transaction; the trigger requires validation-queue lag.
Location:
src/net_processing.cpp:2269(head).🟠 Minor · Post-reconciliation INV can name a re-admitted entry that GETDATA will not serve
Reconciliation announcements skip the
m_last_inv_sequenceupdate, so a re-admitted transaction with a newer mempool sequence is INVed and then answered with NOTFOUND on that link; the window is narrow.Location:
src/net_processing.cpp:6189(head).🟠 Minor · Low
-maxconnectionslets reconciliation peers consume the feeler and extra-peer permitWith
-txreconciliationand-maxconnectionsbetween 11 and 14, persistent outbound peers hold everysemOutboundpermit, so feelers and extra outbound peers can no longer be opened.Location:
src/net.h:1145(head).🟠 Minor · Signalling-only v1 peers register as responders but never start a round
Older nodes running the hidden
-txreconciliationoption negotiate v1 but never initiate, so transactions for them wait in their set until it reaches 3000 entries.Location:
src/net_processing.cpp:4060(head).Review coverage was incomplete.
Reviewed:
8b5acf5ceb8e· Review report · Previous reportspermalink
Rebased and fixed a flaky test involving short id collisions on a full reconciliation set
dc0395c585..37912ec178 44901d8f64..1b7d988a4e
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased and fixed flaky test
1b7d988...8b5acf5
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/46422669884/job/141861698654LLM reason (✨ experimental): intermittent_network:
apt-get updatefailed to fetch Ubuntu security repository package indexes due to connection failures, so dependency setup exited with code 100 before tests ran.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.
A functional or integration test failure may be intermittent or unrelated to this pull request.
If no dedicated issue thread exists, create a new one to track it.
Leave a comment here, if you need help tracking down a confusing failure.