p2p: skip parent lookups for orphan announcements that cannot add a candidate #36884

Open
kah-ja wants to merge 1 commit from orphan-announcer-early-exit into master AGit
kah-ja commented 2026-11-15 18:58:28 +00:00 (Migrated from github.com)

For a wtxid announcement of a transaction that is in the orphanage, AddTxAnnouncement computes the missing parents of the orphan (GetUniqueParents, then AlreadyHaveTx per parent) and then calls MaybeAddOrphanResolutionCandidate. That function returns without using the parents if the peer is already an announcer of the orphan. If the peer has no relay permission and m_txrequest.Count(peer) + unique_parents.size() > MAX_PEER_TX_ANNOUNCEMENTS, it returns after using only their count. In both cases the peer is not added as a candidate, and the same lookups run again for every inv message that lists the wtxid. #35878 deduplicates within one message only.

This PR does both checks before the parent lookups. The second check uses vin.size() in place of the number of missing parents.

Behavior change: vin.size() is an upper bound for the number of missing parents. A peer without relay permission is no longer added as a candidate when Count(peer) + vin.size() exceeds MAX_PEER_TX_ANNOUNCEMENTS but Count(peer) plus the number of missing parents does not. That needs inputs that share a parent, or parents that are already known.

Measurement: regtest, one node, RelWithDebInfo, base a527a0077a. The orphanage holds 12 orphans with 2430 inputs each. One peer, which delivered one of the 12 orphans and has sent at least 3600 announcements of unknown wtxids before, sends 300 inv messages that each list the 12 wtxids. Time per inv message:

per inv
master 14.5 to 16.2 ms
announcer check only 13.2 to 15.0 ms
this PR 0.19 to 0.22 ms
control, 12 unknown wtxids per inv 0.18 to 0.27 ms

Tests: no new test. Passing locally: unit suites txdownload_tests and orphanage_tests; functional p2p_orphan_handling.py, p2p_tx_download.py, p2p_opportunistic_1p1c.py, p2p_1p1c_network.py, p2p_invalid_tx.py, p2p_permissions.py, p2p_leak_tx.py, mempool_packages.py. Not run: the rest of both suites, fuzz targets, lint.

Contributed by turingpoint.

For a wtxid announcement of a transaction that is in the orphanage, `AddTxAnnouncement` computes the missing parents of the orphan (`GetUniqueParents`, then `AlreadyHaveTx` per parent) and then calls `MaybeAddOrphanResolutionCandidate`. That function returns without using the parents if the peer is already an announcer of the orphan. If the peer has no relay permission and `m_txrequest.Count(peer) + unique_parents.size() > MAX_PEER_TX_ANNOUNCEMENTS`, it returns after using only their count. In both cases the peer is not added as a candidate, and the same lookups run again for every `inv` message that lists the wtxid. #35878 deduplicates within one message only. This PR does both checks before the parent lookups. The second check uses `vin.size()` in place of the number of missing parents. **Behavior change:** `vin.size()` is an upper bound for the number of missing parents. A peer without relay permission is no longer added as a candidate when `Count(peer) + vin.size()` exceeds `MAX_PEER_TX_ANNOUNCEMENTS` but `Count(peer)` plus the number of missing parents does not. That needs inputs that share a parent, or parents that are already known. **Measurement:** regtest, one node, RelWithDebInfo, base a527a0077a. The orphanage holds 12 orphans with 2430 inputs each. One peer, which delivered one of the 12 orphans and has sent at least 3600 announcements of unknown wtxids before, sends 300 `inv` messages that each list the 12 wtxids. Time per `inv` message: | | per inv | | --- | --- | | master | 14.5 to 16.2 ms | | announcer check only | 13.2 to 15.0 ms | | this PR | 0.19 to 0.22 ms | | control, 12 unknown wtxids per inv | 0.18 to 0.27 ms | **Tests:** no new test. Passing locally: unit suites `txdownload_tests` and `orphanage_tests`; functional `p2p_orphan_handling.py`, `p2p_tx_download.py`, `p2p_opportunistic_1p1c.py`, `p2p_1p1c_network.py`, `p2p_invalid_tx.py`, `p2p_permissions.py`, `p2p_leak_tx.py`, `mempool_packages.py`. Not run: the rest of both suites, fuzz targets, lint. Contributed by [turingpoint](https://www.turingpoint.de).
DrahtBot commented 2026-11-15 18:58:54 +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

No conflicts as of last run.

<!--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/36884 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36884.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36884#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 No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · Input-count bound excludes otherwise eligible fallback peers

The disclosed stricter policy turns away some late orphan announcers that the exact budget check accepts, while first-receipt candidates still use the distinct-missing-parent count.

Location: src/node/txdownloadman_impl.cpp:186 (head).

🔵 Suggestion · Late-announcer budget boundary and relay exemption lack coverage

Existing tests do not distinguish the new conservative admission rule from the exact helper, or check relay permission at the late-announcer budget boundary.

Location: src/node/txdownloadman_impl.cpp:186 (head).

Review coverage was incomplete.


Reviewed: b2f33e529879 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4afac00dcf2100063250ef321636839508f727ef6ae0cc9ede404a011c46a59f:87c7358e6b1a9709279e41fe01f3f324759c2be7a6239dcb2b0a6d875f8630b0 --> <!-- ralph-base:a527a0077a0fcae913188410214efe98021c0cca --> <!-- ralph-head:b2f33e529879f057db996fab85357be883eef440 --> <!-- ralph-case:0ef9c7deda95efb17456bb4a77f84d48fef2ad40772c16225b06c7a6d99a9eef --> **🔵 Suggestion · Input-count bound excludes otherwise eligible fallback peers** The disclosed stricter policy turns away some late orphan announcers that the exact budget check accepts, while first-receipt candidates still use the distinct-missing-parent count. Location: [`src/node/txdownloadman_impl.cpp:186`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b2f33e529879f057db996fab85357be883eef440/src/node/txdownloadman_impl.cpp#L186>) (head). **🔵 Suggestion · Late-announcer budget boundary and relay exemption lack coverage** Existing tests do not distinguish the new conservative admission rule from the exact helper, or check relay permission at the late-announcer budget boundary. Location: [`src/node/txdownloadman_impl.cpp:186`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b2f33e529879f057db996fab85357be883eef440/src/node/txdownloadman_impl.cpp#L186>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`b2f33e529879`](<https://git.fish.foo/bitcoin/bitcoin/commit/b2f33e529879f057db996fab85357be883eef440>) · [Review report](<https://review.fish.foo/report/36884-b2f33e529879f057db996fab85357be883eef440-2698-1.html>) · [Previous reports](<https://review.fish.foo/traces/36884/>) [permalink](<https://review.fish.foo/report/36884-b2f33e529879f057db996fab85357be883eef440-2698-1.html>)
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!36884
No description provided.