Skip to content

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

Open
kah-ja wants to merge 1 commit into
bitcoin:masterfrom
kah-ja:orphan-announcer-early-exit
Open

kah-ja wants to merge 1 commit into
bitcoin:masterfrom
kah-ja:orphan-announcer-early-exit

Conversation

@kah-ja

@kah-ja kah-ja commented Nov 15, 2026

Copy link
Copy Markdown

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

…andidate

When a peer announces the wtxid of a transaction in the orphanage,
AddTxAnnouncement computes the orphan's missing parents before
MaybeAddOrphanResolutionCandidate decides whether the peer can become
a resolution candidate. For an orphan with many inputs this means
thousands of lookups per announcement, and the result is discarded
when the peer is already an announcer or has no room left in its
announcement budget.

Do both checks first. The budget check uses the number of inputs as
an upper bound for the number of missing parents, so a peer close to
MAX_PEER_TX_ANNOUNCEMENTS may no longer be added as a candidate for
an orphan whose inputs share parents or whose parents are partly
known.

Signed-off-by: Jan Kahmen <[email protected]>
@DrahtBot DrahtBot added the P2P label Nov 15, 2026
@DrahtBot

DrahtBot commented Nov 15, 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

No conflicts as of last run.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants