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

bitcoin/bitcoin: PR #36884

2 suggestions

Optional improvements

Link

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

Details and suggested fix

For a connected peer without relay permission that is not already an announcer, consider Count(peer) == 4,999 and an orphan spending outputs 0 and 1 of one missing parent. Base records that peer and schedules one parent download; the new precheck returns before either operation because it counts two inputs. An announcement received before orphan storage still reaches the exact helper. The skip is not remembered, so a later eligible reannouncement or direct parent announcement can still provide a download opportunity. The frequency of useful exclusions is unmeasured.

Evaluate checking GetUniqueParents().size() against the budget before calling AlreadyHaveTx. This preserves shared-parent candidates while still skipping availability lookups when the distinct-parent bound exceeds the budget. It remains conservative for already-known parents and retains allocation, enumeration, sorting, and deduplication on each announcement. The supplied timings do not isolate that cost, so compare this variant before choosing the broader input-count policy.


Link

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

Details and suggested fix

The functional late-announcer test uses a fresh peer without budget pressure, while the large-inventory test covers ordinary announcements. The fuzz count invariant cannot distinguish the policies because MaybeAddOrphanResolutionCandidate still enforces the exact limit. Add a focused unit test that stores an orphan from peer A with two inputs spending different outputs of one missing parent. Fill connected peer B's tracker with unrelated unknown wtxids, then announce the orphan from B. At Count 4,999, assert no B membership and no count change; in a fresh case at 4,998, assert membership and one added parent announcement. Repeat the over-bound case with relay permission and assert admission. Check membership and request state rather than the return value, since AddTxAnnouncement returns true for both admission and skipping. These assertions would pin the precheck, equality boundary, and exemption; they would not by themselves prove that parent lookups were skipped.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

An orphan announcement is useful even after the transaction has been downloaded: it identifies another possible source of its missing parents. Retaining multiple candidates prevents one unresponsive or dishonest supplier from becoming the only chance to resolve the orphan.

This explains why AddTxAnnouncement has a special path for an already-stored orphan rather than simply discarding its announcement as redundant. Historical #31397 explicitly includes subsequent announcers among resolution candidates and motivates retrying for reliability, censorship resistance, and opportunistic one-parent-one-child package propagation. It also explains that a future ancestor-package protocol would still need retries because a different protocol does not make peers honest.

Source 1

Missing-parent requests share the ordinary transaction request tracker to avoid duplicate downloads, distribute work among peers, and reuse download preferences and overload handling. Announcer identity must nevertheless survive separately in the orphanage because the request tracker forgets successfully downloaded transactions.

In both pinned versions, MaybeAddOrphanResolutionCandidate treats the peer as having announced every missing parent and inserts those parents into m_txrequest. AddAnnouncer records the relationship in the orphanage. This is the architectural reason candidate admission concerns both request-tracker resources and a persistent orphan–peer association, rather than just whether the orphan bytes are already present.

Source 1 · Source 2 · Source 3 · Source 4

Tracked-announcement limits and in-flight overload delays serve different purposes. Announcement state consumes memory, while a hard in-flight ceiling can unnecessarily prevent downloading a transaction available from only one peer. Relay permission deliberately permits trusted bulk transaction submission to bypass the announcement ceiling.

Historical #19988 reduced the tracked-announcement limit to 5,000, replaced the hard 100-in-flight cap with a delay, and documented the relay-permission exception. The pinned candidate path inherits these policies. Its missing-parent count matters because one orphan candidate can introduce several parent announcements; the historical #31397 discussion explicitly raised that multi-parent budget issue. The PR's early budget check operates on this inherited per-peer admission policy, not a consensus limit.

Source 1 · Source 2 · Source 3

Recalculating missing parents when a new candidate appears was chosen to use current knowledge, avoid creating requests for parents that have already arrived, and simplify the code rather than maintain a cached parent list.

This directly explains the base behavior affected by the patch: GetUniqueParents is followed by AlreadyHaveTx filtering on each orphan-announcement opportunity. A historical reviewer articulated those benefits, and the author later reported switching to recalculation each time a candidate is added. The expensive lookups therefore descend from a freshness-and-simplicity decision, not merely incidental repetition.

Source 1 · Source 2

Orphan handling must bound CPU/latency as well as stored transaction weight, while protecting honest peers' orphan retention from churn caused by another peer. Increasing a global transaction-count limit alone does not achieve those goals.

Historical #31829 introduced separate resource accounting, including inputs and orphan–peer announcements, because operations can be expensive even when transaction storage is bounded. Evicting announcements rather than whole transactions prevents an attacker from making an honest peer's orphan disappear merely by also announcing it and then consuming resources. These are complementary constraints around the current candidate path: bounded orphan storage does not eliminate the separate concern of work performed while processing announcements.

Source 1 · Source 2

An unvalidated orphan cannot safely stand in for every transaction sharing its txid. A different-witness version can be attacker-supplied, so orphan storage must distinguish wtxids and allow same-txid variants.

Historical #30000 describes how an early mutated child could delay the real child, particularly when package acceptance depends on retaining the correct orphan. This explains the pinned code's wtxid-only orphan-announcement matching and its refusal to treat an arbitrary same-txid orphan as proof that a parent is already available. The lookups being skipped are consequently part of adversarially careful transaction-identity handling.

Source 1

Ralph's inferences

A new announcer can improve resolution availability, but another announcement from an already-recorded orphan–peer pair does not supply another independent candidate. Separating those cases avoids spending parent-discovery work where candidate membership cannot change.

The base already rejects HaveTxFromPeer inside MaybeAddOrphanResolutionCandidate, after discovering parents. The head performs that membership check first. The historical rationale supports preserving distinct potential suppliers; it does not imply that repeated announcements from the same recorded supplier provide the same benefit.

Source 1 · Source 2

The input-count precheck exchanges precision in candidate admission for avoiding parent enumeration and availability checks: a conservative resource estimate can decline some useful resolution opportunities without first calculating their exact request cost.

At the base, admission counts distinct parents remaining after AlreadyHaveTx filtering. At the head, an ordinary peer can be declined earlier using vin.size(), although multiple inputs may share a parent or reference parents already known. The underlying historical tension is between exploiting alternative suppliers for reliable propagation and bounding untrusted resource use. This describes the patch's policy tradeoff, not a historical endorsement of this particular estimate or a correctness assessment.

Source 1 · Source 2 · Source 3