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

pull kah-ja wants to merge 1 commits into bitcoin:master from kah-ja:orphan-announcer-early-exit changing 1 files +8 −0
  1. kah-ja commented at 6:58 PM on November 15, 2026: none

    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.

  2. p2p: skip parent lookups for orphan announcements that cannot add a candidate
    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 <jan@turingpoint.de>
    b2f33e5298
  3. DrahtBot added the label P2P on Nov 15, 2026
  4. DrahtBot commented at 6:58 PM on November 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-16 00:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me