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.