Skip to content

[DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) - #35591

Open
sr-gi wants to merge 38 commits into
bitcoin:masterfrom
sr-gi:2026-05-erlay-recon-only-full-impl
Open

sr-gi wants to merge 38 commits into
bitcoin:masterfrom
sr-gi:2026-05-erlay-recon-only-full-impl

Conversation

@sr-gi

@sr-gi sr-gi commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

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.

@DrahtBot

DrahtBot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • #36904 (log: Remove trailing and embedded newlines from log messages by maflcko)
  • #36372 (p2p: replace full outbound peers that don't support tx relay (take 2) by fjahr)
  • #36167 (build: Enable -Wunused by fanquake)
  • #35522 (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc)
  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)
  • #34824 (net: encapsulate TxRelay state and replace recursive mutexes by w0xlt)
  • #32554 (bench: replace embedded raw block with configurable block generator by l0rinc)
  • #29418 (rpc: provide per message stats for global traffic via new field in 'getnettotals' by vasild)

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++, and func(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 → Prefer assert_equal(self.nodes[0].process.poll(), None).
  • test/functional/test_framework/p2p_txrecon.py: assert message.nVersion >= 70016 → Prefer assert_greater_than_or_equal(message.nVersion, 70016).

2026-11-30 12:52:28

@sr-gi

sr-gi commented Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

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:

  • This is currently using sendtxrcncl as a way, for outbound nodes, to signal they want to establish a full-reconciliation connection, plus adding a limit on the number of full-reconcilition inbounds that will be accepted by a node. This is not the originally intended way of using sendtxrcncl. It may be worth considering an approach based on BIP-434.
  • The extension phase was designed so peers with an ongoing reconciliation that had underpredicted the sketch capacity could still reconcile without having to directly fallback to fanout. Given reconciliation is now used as fallback, and the extra bandwidth may not be as problematic, it may be worth considering overshooting the initial sketch capacity and getting rid of the extension phase.
  • Fuzz tests are missing

@sr-gi

sr-gi commented Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

Fixed some typos and addressed some of the linter suggestions

6554707...e63db1a

@sr-gi

sr-gi commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

Fixed several bugs and added a new test for receiving reconciliation messages when reconciliation is not enabled.

e63db1a...35bcd04

@sr-gi
sr-gi force-pushed the 2026-05-erlay-recon-only-full-impl branch 2 times, most recently from 280d603 to d08f127 Compare June 24, 2026 18:51
@sr-gi

sr-gi commented Jun 24, 2026 •

Copy link
Copy Markdown
Member Author

Addressed some issues pointed out by corecheck.

35bcd04...d08f127

sr-gi and others added 20 commits November 30, 2026 12:31
When we're finalizing negotiation, we should add the peers
for which we will initiate reconciliations to the queue.

Co-authored-by: Gleb Naumenko <[email protected]>
We initiate reconciliation by looking at the queue periodically
with equal intervals between peers to achieve efficiency.

This will be later used to see whether it's time to initiate.

Co-authored-by: Gleb Naumenko <[email protected]>
When the time comes for the peer, we send a
reconciliation request with the parameters which
will help the peer to construct a (hopefully) sufficient
reconciliation sketch for us. We will then use that
sketch to find missing transactions.

Co-authored-by: Gleb Naumenko <[email protected]>
Store the parameters the peer sent us inside th reconciliation request.

Co-authored-by: Gleb Naumenko <[email protected]>
When the time comes, we should send a sketch of our
local reconciliation set to the reconciliation initiator.

Co-authored-by: Gleb Naumenko <[email protected]>
When the sketches from both sides are combined successfully,
the diff is produced. Then this diff can (together with the local txs)
be used to identified which transactions are missing locally and remotely.

Co-authored-by: Gleb Naumenko <[email protected]>
Move the transaction announcement loop from SendMessages into its own
method, so it can be reused to announce transactions after a
reconciliation round. No behaviour change.
Transactions the peer is found to be missing during a reconciliation round
need to be announced right away, rather than waiting for the next trickle
interval and being added back to the reconciliation set.

Add AnnounceReconciliationTxs on top of AnnounceTxs.

Co-authored-by: Gleb Naumenko <[email protected]>
If after decoding a reconciliation sketch it turned out
to be insufficient to find set difference, request extension.

Co-authored-by: Gleb Naumenko <[email protected]>
Store the initial sketches so that we are able to process
extension sketch while avoiding transmitting the same data.

Co-authored-by: Gleb Naumenko <[email protected]>
To be ready to respond to a sketch extension request
from our peer, we should store a snapshot of our state
and capacity of the initial sketch, so that we compute
extension of the same size and over the exact same
transactions.

Transactions arriving during this reconciliation will
be instead stored in the regular set.

Co-authored-by: Gleb Naumenko <[email protected]>
If peer failed to reconcile based on our initial response sketch,
they will ask us for a sketch extension. Store this request to respond later.

Co-authored-by: Gleb Naumenko <[email protected]>
Sending an extension may allow the peer to reconcile
transactions, because now the full sketch has twice
as much capacity.

Co-authored-by: Gleb Naumenko <[email protected]>
If a peer sent us an extension sketch, we should
reconstruct a full sketch from it with the snapshot
we stored initially, and attempt to decode the difference.

Co-authored-by: Gleb Naumenko <[email protected]>
This currently unused function is supposed to be used once
a reconciliation round is done. It cleans the state corresponding
to the passed reconciliation.

Co-authored-by: Gleb Naumenko <[email protected]>
Once a peer tells us reconciliation is done, we should behave as follows:
- if it was successful, just respond them with the transactions they asked
  by short ID.
- if it was a full failure, respond with all local transactions from the reconciliation
  set snapshot
- if it was a partial failure (only low or high part was failed after a bisection),
  respond with all transactions which were asked for by short id,
  and announce local txs which belong to the failed chunk.

Co-authored-by: Gleb Naumenko <[email protected]>
@sr-gi
sr-gi force-pushed the 2026-05-erlay-recon-only-full-impl branch from 1b7d988 to ffc072f Compare November 30, 2026 11:39
sr-gi and others added 3 commits November 30, 2026 13:45
We may still need to add more tests, specially around extensions (if we keep them)

Co-authored-by: Gleb Naumenko <[email protected]>
…he mempool

A transaction that has left our mempool can no longer be served, but nothing
removed it from the reconciliation sets it had been added to. It would still be
sketched, requested by the peer, and then dropped, wasting sketch capacity and a
round trip after every block.

Prune on both removal signals: removeUnchecked deliberately skips
TransactionRemovedFromMempool for MemPoolRemovalReason::BLOCK, so mined
transactions, which are the bulk of the case, only arrive via
MempoolTransactionsRemovedForBlock.

Snapshots of an in-flight round are left untouched so that a sketch extension
still describes the same elements as the sketch already sent. Flagging the wtxid
instead keeps it out of the announcement.
Raises the question of whether the current sketch capacity limits are too high
@sr-gi
sr-gi force-pushed the 2026-05-erlay-recon-only-full-impl branch from ffc072f to 8b5acf5 Compare November 30, 2026 12:51
@sr-gi

sr-gi commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Rebased and fixed flaky test

1b7d988...8b5acf5

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/46422669884/job/141861698654
LLM reason (✨ experimental): intermittent_network: apt-get update failed 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants