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

Open
sr-gi wants to merge 38 commits from 2026-05-erlay-recon-only-full-impl into master AGit
sr-gi commented 2026-06-23 12:40:28 +00:00 (Migrated from github.com)

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.

Erlay Project Tracking: [#30249](https://github.com/bitcoin/bitcoin/issues/30249) Conceptual Discussion: [#34542](https://github.com/bitcoin/bitcoin/issues/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 commented 2026-06-23 12:40:37 +00:00 (Migrated from github.com)

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

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35591 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35591.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35591#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36904](https://github.com/bitcoin/bitcoin/pull/36904) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36904.svg"></sub> (log: Remove trailing and embedded newlines from log messages by maflcko) * [#36372](https://github.com/bitcoin/bitcoin/pull/36372) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36372.svg"></sub> (p2p: replace full outbound peers that don't support tx relay (take 2) by fjahr) * [#36167](https://github.com/bitcoin/bitcoin/pull/36167) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable `-Wunused` by fanquake) * [#35522](https://github.com/bitcoin/bitcoin/pull/35522) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35522.svg"></sub> (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc) * [#35502](https://github.com/bitcoin/bitcoin/pull/35502) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35502.svg"></sub> (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt) * [#34824](https://github.com/bitcoin/bitcoin/pull/34824) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34824.svg"></sub> (net: encapsulate TxRelay state and replace recursive mutexes by w0xlt) * [#32554](https://github.com/bitcoin/bitcoin/pull/32554) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32554.svg"></sub> (bench: replace embedded raw block with configurable block generator by l0rinc) * [#29418](https://github.com/bitcoin/bitcoin/pull/29418) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29418.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### 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)`. <sup>2026-11-30 12:52:28</sup>
sr-gi commented 2026-06-23 13:13:54 +00:00 (Migrated from github.com)

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
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](https://github.com/bitcoin/bips/blob/master/bip-0330.mediawiki#sendtxr) 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](https://github.com/bitcoin/bitcoin/pull/35221). - 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 commented 2026-06-23 23:04:51 +00:00 (Migrated from github.com)

Fixed some typos and addressed some of the linter suggestions

6554707...e63db1a

Fixed some typos and addressed some of the linter suggestions [6554707](https://github.com/bitcoin/bitcoin/pull/35591/commits/65547074596b5d5be0e84bf749651a3673361c3b)...[e63db1a](https://github.com/bitcoin/bitcoin/pull/35591/commits/e63db1a848feaa97626d44276507330f4594f4fd)
sr-gi commented 2026-06-24 12:52:03 +00:00 (Migrated from github.com)

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](https://github.com/bitcoin/bitcoin/commit/e63db1a848feaa97626d44276507330f4594f4fd)...[23053a3](https://github.com/bitcoin/bitcoin/commit/23053a379fd72ef49a240e9014bed454719f8ba1)
sr-gi commented 2026-06-24 14:41:45 +00:00 (Migrated from github.com)

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

e63db1a...35bcd04

Fixed several bugs and added a new test for receiving reconciliation messages when reconciliation is not enabled. [e63db1a](https://github.com/bitcoin/bitcoin/commit/e63db1a848feaa97626d44276507330f4594f4fd)...[35bcd04](https://github.com/bitcoin/bitcoin/commit/35bcd043b468ccb05ec3cbb5a384724cf0e47e23)
sr-gi commented 2026-06-24 16:06:16 +00:00 (Migrated from github.com)

Addressed some issues pointed out by corecheck.

35bcd04...280d603

Addressed some issues pointed out by corecheck. [35bcd04](https://github.com/bitcoin/bitcoin/commit/35bcd043b468ccb05ec3cbb5a384724cf0e47e23)...[280d603](https://github.com/bitcoin/bitcoin/commit/280d603597076be8b4d1b47db737f6b293cecb7c)
sr-gi commented 2026-06-24 20:57:46 +00:00 (Migrated from github.com)

Addressed some issues pointed out by corecheck.

35bcd04...d08f127

Addressed some issues pointed out by corecheck. [35bcd04](https://github.com/bitcoin/bitcoin/commit/35bcd043b468ccb05ec3cbb5a384724cf0e47e23)...[d08f127](https://github.com/bitcoin/bitcoin/commit/d08f127a7764e37c30ed815b0a6c4f1d37282173)
brunoerg (Migrated from github.com) reviewed 2026-06-29 16:23:07 +00:00
brunoerg (Migrated from github.com) left a comment

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:

  • not sending REQSKETCHEXT after an undecodable sketch in net_processing
  • not snapshotting state before the extension round
  • accepting/rejecting malformed extension sizes incorrectly
  • flipping success/failure outcomes of extension decoding
  • using the wrong transaction set after extension failure
  • not clearing peer state after extension completion

This 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:

  • add end-to-end functional tests that force an extension round and assert the exact message sequence: REQTXRCNCL -> SKETCH -> REQSKETCHEXT -> SKETCH -> RECONCILDIFF
  • assert both extension success and extension failure behavior
  • verify that extension failure falls back to announcing the snapshotted set, not the live set
  • verify that state is cleared after extension completion and that a second reconciliation starts cleanly

2. Boundary conditions are not pinned down tightly enough

Several survivors change strict inequalities to inclusive ones and still pass:

  • remote_sketch_capacity > MAX_SKETCH_CAPACITY changed to >=
  • extended_capacity > MAX_SKETCH_CAPACITY * 2 changed to >=
  • peer_q > Q_PRECISION changed 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 q formatting in src/test/txreconciliation_tests.cpp, but the same precision is missing for protocol acceptance thresholds.

What should be improved:

  • add exact-boundary tests for MAX_SKETCH_CAPACITY, 2 * MAX_SKETCH_CAPACITY, and Q_PRECISION
  • check both sides of each threshold: limit must pass, limit + 1 must fail

3. INV relay side effects are only partially asserted

Many survivors in PeerManagerImpl::AnnounceTxs() and the send path in SendMessages() remove or alter important side effects without breaking tests:

  • skipping heap construction/pop order
  • changing continue to break when one candidate should not be sent
  • not inserting into m_tx_inventory_known_filter
  • not erasing from m_tx_inventory_to_send
  • not flushing INV batches at MAX_INV_SZ
  • not clearing the batch after sending

The 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:

  • add tests with a mix of sendable and unsendable transactions and assert that later eligible transactions are still announced
  • assert that transactions already known to the peer are not re-announced in the next round
  • add a case above MAX_INV_SZ and verify the number and sizes of INV messages
  • verify that reconciliation and fanout paths do not duplicate announcements after internal state should have been cleared

4. Some state-management behaviors are observable in principle, but not asserted

Survivors also show weak checking around reconciliation state transitions:

  • not clearing m_short_id_mapping
  • not clearing peer state after handling a result
  • always taking the “removed” branch in TryRemovingFromSet
  • not recording m_announced_while_reconciling
  • returning success from queue-selection paths that should be false

These 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:

  • add two-step tests that perform one reconciliation round and then immediately start another to detect stale snapshots, stale mappings, or stale queue state
  • specifically verify the “received while reconciling” behavior across the extension path, not just the non-extension path

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:

  1. Add full initiator/responder extension-path functional tests.
  2. Add exact boundary tests for sketch capacity and q.
  3. Add stronger assertions around INV batching, filtering, and duplicate suppression.
  4. Add second-round/state-cleanup tests to catch stale reconciliation state.

That would likely eliminate most of the meaningful survivors from this run and materially improve confidence in the PR’s tests.

**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: - unit coverage for peer registration, queue rotation, set insertion/removal, and non-extension reconciliation in [src/test/txreconciliation_tests.cpp](/home/bruno/projects/bitcoin/src/test/txreconciliation_tests.cpp:18) - functional coverage for initiator/responder happy paths in [test/functional/p2p_txrecon_initiator.py](/home/bruno/projects/bitcoin/test/functional/p2p_txrecon_initiator.py:62) and [test/functional/p2p_txrecon_responder.py](/home/bruno/projects/bitcoin/test/functional/p2p_txrecon_responder.py:70) - protocol-violation checks for clearly invalid message ordering and unsupported peers 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: - not sending `REQSKETCHEXT` after an undecodable sketch in `net_processing` - not snapshotting state before the extension round - accepting/rejecting malformed extension sizes incorrectly - flipping success/failure outcomes of extension decoding - using the wrong transaction set after extension failure - not clearing peer state after extension completion This 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](/home/bruno/projects/bitcoin/test/functional/p2p_txrecon_initiator.py:248) and [test/functional/p2p_txrecon_responder.py](/home/bruno/projects/bitcoin/test/functional/p2p_txrecon_responder.py:268). What should be improved: - add end-to-end functional tests that force an extension round and assert the exact message sequence: `REQTXRCNCL -> SKETCH -> REQSKETCHEXT -> SKETCH -> RECONCILDIFF` - assert both extension success and extension failure behavior - verify that extension failure falls back to announcing the snapshotted set, not the live set - verify that state is cleared after extension completion and that a second reconciliation starts cleanly ### 2. Boundary conditions are not pinned down tightly enough Several survivors change strict inequalities to inclusive ones and still pass: - `remote_sketch_capacity > MAX_SKETCH_CAPACITY` changed to `>=` - `extended_capacity > MAX_SKETCH_CAPACITY * 2` changed to `>=` - `peer_q > Q_PRECISION` changed 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 `q` formatting in [src/test/txreconciliation_tests.cpp](/home/bruno/projects/bitcoin/src/test/txreconciliation_tests.cpp:381), but the same precision is missing for protocol acceptance thresholds. What should be improved: - add exact-boundary tests for `MAX_SKETCH_CAPACITY`, `2 * MAX_SKETCH_CAPACITY`, and `Q_PRECISION` - check both sides of each threshold: `limit` must pass, `limit + 1` must fail ### 3. INV relay side effects are only partially asserted Many survivors in `PeerManagerImpl::AnnounceTxs()` and the send path in `SendMessages()` remove or alter important side effects without breaking tests: - skipping heap construction/pop order - changing `continue` to `break` when one candidate should not be sent - not inserting into `m_tx_inventory_known_filter` - not erasing from `m_tx_inventory_to_send` - not flushing INV batches at `MAX_INV_SZ` - not clearing the batch after sending The 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: - add tests with a mix of sendable and unsendable transactions and assert that later eligible transactions are still announced - assert that transactions already known to the peer are not re-announced in the next round - add a case above `MAX_INV_SZ` and verify the number and sizes of INV messages - verify that reconciliation and fanout paths do not duplicate announcements after internal state should have been cleared ### 4. Some state-management behaviors are observable in principle, but not asserted Survivors also show weak checking around reconciliation state transitions: - not clearing `m_short_id_mapping` - not clearing peer state after handling a result - always taking the “removed” branch in `TryRemovingFromSet` - not recording `m_announced_while_reconciling` - returning success from queue-selection paths that should be false These 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: - add two-step tests that perform one reconciliation round and then immediately start another to detect stale snapshots, stale mappings, or stale queue state - specifically verify the “received while reconciling” behavior across the extension path, not just the non-extension path ## 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: 1. Add full initiator/responder extension-path functional tests. 2. Add exact boundary tests for sketch capacity and `q`. 3. Add stronger assertions around INV batching, filtering, and duplicate suppression. 4. Add second-round/state-cleanup tests to catch stale reconciliation state. That would likely eliminate most of the meaningful survivors from this run and materially improve confidence in the PR’s tests.
DrahtBot commented 2026-07-24 23:25:20 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sr-gi commented 2026-08-13 20:05:02 +00:00 (Migrated from github.com)

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

Rebased to include the latest changes in master, including the changes introduced in [https://github.com/bitcoin/bitcoin/pull/34628](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](https://github.com/bitcoin/bitcoin/commit/d08f127a7764e37c30ed815b0a6c4f1d37282173)...[41de5f9](https://github.com/bitcoin/bitcoin/pull/35591/commits/41de5f931189563158f0b953638bcb626e65dd7d)
DrahtBot commented 2026-08-14 17:51:29 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sr-gi commented 2026-08-17 16:29:59 +00:00 (Migrated from github.com)

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

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](https://github.com/bitcoin/bitcoin/pull/35591/commits/41de5f931189563158f0b953638bcb626e65dd7d)...[816d2cd](https://github.com/bitcoin/bitcoin/pull/35591/commits/816d2cd4328a060577aa7cb0e854a117faa7ca74)
sr-gi commented 2026-08-17 17:04:30 +00:00 (Migrated from github.com)

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

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](https://github.com/bitcoin/bitcoin/pull/35591/commits/816d2cd4328a060577aa7cb0e854a117faa7ca74)...[d34d736](https://github.com/bitcoin/bitcoin/pull/35591/commits/d34d7362ee554b044e3d3acb237e2be477b260c1)
sr-gi commented 2026-08-18 17:49:21 +00:00 (Migrated from github.com)

Fixes several uncovered edge cases.

d34d736...7937670

Fixes several uncovered edge cases. [d34d736](https://github.com/bitcoin/bitcoin/pull/35591/commits/d34d7362ee554b044e3d3acb237e2be477b260c1)...[7937670](https://github.com/bitcoin/bitcoin/pull/35591/commits/7937670255acd8c787ecaded629b621518f6306e)
sr-gi commented 2026-08-19 15:36:29 +00:00 (Migrated from github.com)

Fixed several uncovered edge cases.

d34d736...b0186aa

Fixed several uncovered edge cases. [d34d736](https://github.com/bitcoin/bitcoin/pull/35591/commits/d34d7362ee554b044e3d3acb237e2be477b260c1)...[b0186aa](https://github.com/bitcoin/bitcoin/pull/35591/commits/b0186aacfe054b9e4a0d1b6a2db74c59af308ffe)
sr-gi commented 2026-08-19 19:23:59 +00:00 (Migrated from github.com)

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.

ns/element element/s err% total benchmark
9,992.50 100,075.03 0.6% 0.33 ReconcileSketchConstructReconSetMax
536,306.23 1,864.61 0.1% 96.69 ReconcileSketchDecodeExtensionMax
281,615.18 3,550.94 0.1% 25.38 ReconcileSketchDecodeMaxCapacity
39,963.18 25,023.03 1.1% 1.30 ReconcileSketchDecodeReconSetMax
2,379.92 420,182.37 3.5% 0.01 ReconcileSketchDecodeTypical

This results in the following:

benchmark capacity per-decode
ReconcileSketchDecodeTypical 54 0.13 ms
ReconcileSketchDecodeReconSetMax 3001 120 ms
ReconcileSketchDecodeMaxCapacity 8192 2.3 s
ReconcileSketchDecodeExtensionMax 16384 8.8 s
  • The decode for a typical/realistic round (7 tx/s, 30s, q=0.25) is in the order of tens of microseconds.
  • A round between two Core nodes (limiting their set size to MAX_RECONSET_SIZE) takes ~120ms
  • A peer that advertises sketches as big as they get (MAX_SKETCH_CAPACITY) can make us take ~2.3s to decode
    • This is amplified to 8.8s in the extension case, as we allow up to double the max capacity

This 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_SIZE elements. So the maximum sketch sizes are 3001 for the initial sketch, 6002 for an extension.

b0186aa...62bf7d1

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. | ns/element | element/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 9,992.50 | 100,075.03 | 0.6% | 0.33 | `ReconcileSketchConstructReconSetMax` | 536,306.23 | 1,864.61 | 0.1% | 96.69 | `ReconcileSketchDecodeExtensionMax` | 281,615.18 | 3,550.94 | 0.1% | 25.38 | `ReconcileSketchDecodeMaxCapacity` | 39,963.18 | 25,023.03 | 1.1% | 1.30 | `ReconcileSketchDecodeReconSetMax` | 2,379.92 | 420,182.37 | 3.5% | 0.01 | `ReconcileSketchDecodeTypical` This results in the following: benchmark | capacity | per-decode -- | -- | -- ReconcileSketchDecodeTypical | 54 | 0.13 ms ReconcileSketchDecodeReconSetMax | 3001 | 120 ms ReconcileSketchDecodeMaxCapacity | 8192 | 2.3 s ReconcileSketchDecodeExtensionMax | 16384 | 8.8 s - The decode for a typical/realistic round (7 tx/s, 30s, q=0.25) is in the order of tens of microseconds. - A round between two Core nodes (limiting their set size to `MAX_RECONSET_SIZE`) takes ~120ms - A peer that advertises sketches as big as they get (MAX_SKETCH_CAPACITY) can make us take ~2.3s to decode - This is amplified to 8.8s in the extension case, as we allow up to double the max capacity This 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_SIZE` elements. So the maximum sketch sizes are 3001 for the initial sketch, 6002 for an extension. [b0186aa](https://github.com/bitcoin/bitcoin/pull/35591/commits/b0186aacfe054b9e4a0d1b6a2db74c59af308ffe)...[62bf7d1](https://github.com/bitcoin/bitcoin/pull/35591/commits/62bf7d11115d4b86cb3a8fb0de035f87e79c7ace)
DrahtBot commented 2026-08-19 19:24:12 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/32289116534/job/96185584884
LLM reason (✨ experimental): CI failed because IWYU detected and rejected incorrect/missing #include ordering/content (generated “Failure generated from IWYU” for src/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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/32289116534/job/96185584884</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU detected and rejected incorrect/missing `#include` ordering/content (generated “Failure generated from IWYU” for `src/bench/txreconciliation.cpp`).</sub> <details><summary>Hints</summary> 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. </details>
sr-gi commented 2026-08-20 10:22:54 +00:00 (Migrated from github.com)

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):

  • Should we negotiate reconciliation using BIP-434?
  • Should the new connection type be considered a full-outbound? If so, the eviction logic needs to be patched to include these.
  • Are extensions worth if we will be using reconciliation as a fallback, or should we just slightly overestimate the sketch capacity and default to fanout on failure?
  • Should we cap the maximum capacity sketch we accept closer to MAX_RECONSET_SIZE than to MAX_SKETCH_CAPACITY?
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): - Should we negotiate reconciliation using BIP-434? - Should the new connection type be considered a full-outbound? If so, the eviction logic needs to be patched to include these. - Are extensions worth if we will be using reconciliation as a fallback, or should we just slightly overestimate the sketch capacity and default to fanout on failure? - Should we cap the maximum capacity sketch we accept closer to `MAX_RECONSET_SIZE` than to `MAX_SKETCH_CAPACITY`?
DrahtBot commented 2026-08-24 09:21:17 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sr-gi commented 2026-08-24 12:34:56 +00:00 (Migrated from github.com)

Rebased e366778...534a890

Rebased [e366778](https://github.com/bitcoin/bitcoin/pull/35591/commits/e366778976f36998a120ea3bdf397e9c456692c7)...[534a890](https://github.com/bitcoin/bitcoin/pull/35591/commits/534a89069d594a05e6bfb15858046464b05fbc9e)
brunoerg (Migrated from github.com) reviewed 2026-08-31 17:58:38 +00:00
brunoerg (Migrated from github.com) commented 2026-08-31 17:58:39 +00:00

Could reconcilitation peers exceed m_max_outbound_full_recon during v2-to-v1 fallback? Thinking about a possible race.

Could reconcilitation peers exceed `m_max_outbound_full_recon` during v2-to-v1 fallback? Thinking about a possible race.
brunoerg (Migrated from github.com) reviewed 2026-08-31 18:07:54 +00:00
brunoerg (Migrated from github.com) commented 2026-08-31 18:07:54 +00:00

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?

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?
brunoerg (Migrated from github.com) reviewed 2026-08-31 18:12:19 +00:00
brunoerg (Migrated from github.com) commented 2026-08-31 18:12:20 +00:00

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.

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.
sr-gi (Migrated from github.com) reviewed 2026-09-01 09:11:05 +00:00
sr-gi (Migrated from github.com) commented 2026-09-01 09:11:05 +00:00

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

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
sr-gi (Migrated from github.com) reviewed 2026-09-01 09:20:57 +00:00
sr-gi (Migrated from github.com) commented 2026-09-01 09:20:57 +00:00

You're right, will change

You're right, will change
sr-gi (Migrated from github.com) reviewed 2026-09-01 10:29:20 +00:00
sr-gi (Migrated from github.com) commented 2026-09-01 10:29:20 +00:00

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).

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).
sr-gi commented 2026-09-01 10:44:43 +00:00 (Migrated from github.com)

Addresses @brunoerg comments.

I changed the way we parse recon_result to 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_RECONCILIATION should be considered full outbound, and on whether extensions are worth keeping.

534a890...25e545c

Addresses @brunoerg comments. I changed the way we parse `recon_result` to 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_RECONCILIATION` should be considered full outbound, and on whether extensions are worth keeping. [534a890](https://github.com/bitcoin/bitcoin/pull/35591/commits/534a89069d594a05e6bfb15858046464b05fbc9e)...[25e545c](https://github.com/bitcoin/bitcoin/pull/35591/commits/25e545c9448a70e0080d97aac583c2869b6c5723)
sr-gi commented 2026-09-01 13:57:03 +00:00 (Migrated from github.com)

Rebased to fix CI, plus slightly decreased MAX_INBOUND_RECONCILIATION_PEERS for now, as some inbounds were being evicted in p2p_sendtxrcncl.py after #36078.

MAX_INBOUND_RECONCILIATION_PEERS is 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

Rebased to fix CI, plus slightly decreased `MAX_INBOUND_RECONCILIATION_PEERS` for now, as some inbounds were being evicted in `p2p_sendtxrcncl.py` after #36078. `MAX_INBOUND_RECONCILIATION_PEERS` is 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](https://github.com/bitcoin/bitcoin/commit/d08f127a7764e37c30ed815b0a6c4f1d37282173)...[0eddbbc](https://github.com/bitcoin/bitcoin/pull/35591/commits/0eddbbca81d0ceceb6375ba34e2113575057e579)
DrahtBot commented 2026-09-04 19:28:17 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/33909308334/job/101141694892
LLM reason (✨ experimental): CI failed because the fuzz build didn’t compile: connman.cpp calls ConnmanTestMsg::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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `ASan + LSan + UBSan + integer`: https://github.com/bitcoin/bitcoin/actions/runs/33909308334/job/101141694892</sub> <sub>LLM reason (✨ experimental): CI failed because the fuzz build didn’t compile: `connman.cpp` calls `ConnmanTestMsg::GetExtraFullOutboundCount()` which no longer exists (“no member named”).</sub> <details><summary>Hints</summary> 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. </details>
sr-gi commented 2026-09-04 19:42:14 +00:00 (Migrated from github.com)

@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, ab8528650b to refactor the current logic into a method that can be reused by reconciliation connections, and a 0ce6c11e2a that 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

@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, ab8528650be36714554934946679d69247dbb719 to refactor the current logic into a method that can be reused by reconciliation connections, and a 0ce6c11e2a1c2f583a5e0b4eaed5f019c62c0dba that 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](https://github.com/bitcoin/bitcoin/pull/35591/commits/0eddbbca81d0ceceb6375ba34e2113575057e579)...[37912ec](https://github.com/bitcoin/bitcoin/pull/35591/commits/37912ec1789ab2384982a3a045f9e864fdccf722)
DrahtBot commented 2026-09-14 15:51:34 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
bartoli (Migrated from github.com) reviewed 2026-09-25 21:33:31 +00:00
bartoli (Migrated from github.com) commented 2026-09-25 21:33:31 +00:00

This could return a const ref (even though all current calls would make a copy anyway)

This could return a const ref (even though all current calls would make a copy anyway)
bartoli (Migrated from github.com) reviewed 2026-09-25 21:44:57 +00:00
bartoli (Migrated from github.com) commented 2026-09-25 21:44:57 +00:00

first set size once to skdata.size()+m_remote_sketch_snapshot.size then copy values?

first set size once to skdata.size()+m_remote_sketch_snapshot.size then copy values?
bartoli (Migrated from github.com) reviewed 2026-09-25 22:02:20 +00:00
bartoli (Migrated from github.com) left a comment

Just some generic C++ comments

Just some generic C++ comments
First-time contributor

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 one SKETCH exchange 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 handling

A short-ID collision is detected under one tracker lock and the colliding entry is removed under another, so an asynchronous RemoveFromSets in 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_sequence update, 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 -maxconnections lets reconciliation peers consume the feeler and extra-peer permit

With -txreconciliation and -maxconnections between 11 and 14, persistent outbound peers hold every semOutbound permit, 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 -txreconciliation option 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 reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:8e09dc7bf97fc224f4f1d7777685e1994265db5e --> <!-- ralph-head:8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf --> <!-- ralph-case:7b672127381cbb3f9baf611c209726120080b3814a6892bf4cc2e113512af955 --> [16 additional verified findings in the Review report](<https://review.fish.foo/report/35591-8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf-3346-3.html>). 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 one `SKETCH` exchange 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/node/txreconciliation_impl.cpp#L291>) (head). **🟠 Minor · `Assume(TryRemovingFromSet)` can fail when mempool pruning races the collision handling** A short-ID collision is detected under one tracker lock and the colliding entry is removed under another, so an asynchronous `RemoveFromSets` in between aborts debug builds. Location: [`src/net_processing.cpp:6151`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/net_processing.cpp#L6151>) (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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/net_processing.cpp#L2269>) (head). **🟠 Minor · Post-reconciliation INV can name a re-admitted entry that GETDATA will not serve** Reconciliation announcements skip the `m_last_inv_sequence` update, 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/net_processing.cpp#L6189>) (head). **🟠 Minor · Low `-maxconnections` lets reconciliation peers consume the feeler and extra-peer permit** With `-txreconciliation` and `-maxconnections` between 11 and 14, persistent outbound peers hold every `semOutbound` permit, so feelers and extra outbound peers can no longer be opened. Location: [`src/net.h:1145`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/net.h#L1145>) (head). **🟠 Minor · Signalling-only v1 peers register as responders but never start a round** Older nodes running the hidden `-txreconciliation` option negotiate v1 but never initiate, so transactions for them wait in their set until it reaches 3000 entries. Location: [`src/net_processing.cpp:4060`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf/src/net_processing.cpp#L4060>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`8b5acf5ceb8e`](<https://git.fish.foo/bitcoin/bitcoin/commit/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf>) · [Review report](<https://review.fish.foo/report/35591-8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf-3346-3.html>) · [Previous reports](<https://review.fish.foo/traces/35591/>) [permalink](<https://review.fish.foo/report/35591-8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf-3346-3.html>)
sr-gi commented 2026-11-11 08:24:18 +00:00 (Migrated from github.com)

Rebased and fixed a flaky test involving short id collisions on a full reconciliation set

dc0395c585..37912ec178 44901d8f64..1b7d988a4e

Rebased and fixed a flaky test involving short id collisions on a full reconciliation set dc0395c585..37912ec178 44901d8f64..1b7d988a4e
DrahtBot commented 2026-11-16 17:23:48 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
sr-gi commented 2026-11-30 13:05:31 +00:00 (Migrated from github.com)

Rebased and fixed flaky test

1b7d988...8b5acf5

Rebased and fixed flaky test [1b7d988](https://github.com/bitcoin/bitcoin/commit/1b7d988a4e9a7ce6d44d904d271a863ed5fcbb17)...[8b5acf5](https://github.com/bitcoin/bitcoin/pull/35591/commits/8b5acf5ceb8e39d3c5ebf7df32a394415f6f76bf)
DrahtBot commented 2026-11-30 13:50:59 +00:00 (Migrated from github.com)

🚧 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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `test ancestor commits`: https://github.com/bitcoin/bitcoin/actions/runs/46422669884/job/141861698654</sub> <sub>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.</sub> <details><summary>Hints</summary> 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. </details>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35591
No description provided.