Repository navigation
p2p: don't let one peer's same-txid variant cancel another peer's 1p1c or orphan resolution - #36369
instagibbs wants to merge 9 commits into
Conversation
When a 1p1c package fails the package feerate check, the child gets a TX_RECONSIDERABLE result, and ProcessPackageResult passed it to ProcessInvalidTx, which erased the child from the orphanage for all of its announcers. The failure is a property of that pair of wtxids, which MempoolRejectedPackage already caches, not of the child. The child can still succeed with another version of the parent, such as the one an honest announcer holds, so it should stay available. Skip ProcessInvalidTx for package members with a TX_RECONSIDERABLE result. A child that is too low feerate on its own is still rejected when its parent's work set is processed.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Concept ACK |
c90036f to
21dc168
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
21dc168 to
bf732fa
Compare
Check that when another announcer of the child delivers a witness-padded parent that fails the package feerate check, the child stays in the orphanage and the honest peer's package is still accepted, for both v2 and TRUC packages.
A TX_RECONSIDERABLE rejection forgets the transaction's wtxid in TxRequestTracker for all peers. For a transaction without witness data the wtxid equals the txid, which is the hash orphan resolution uses to request a missing parent. Such a rejection therefore cancelled every announcer's request for the parent, and the orphan stayed unresolved until a new announcer appeared or the parent confirmed. Keep those requests when the rejected transaction has no witness and an orphan spends it.
Check that after another peer delivers a witnessless parent that is rejected as reconsiderable, the child's announcer is still asked for the parent and the package is accepted, for both a witness-stripped and a nonsegwit parent.
Add invariants to the txdownloadman_impl target: an event about one transaction or peer must not remove other peers' transaction requests or orphan announcements beyond that transaction's own hashes and entries. Uniform random operations almost never reach the states where this matters, so bias the harness towards orphans with missing parents and towards TX_MISSING_INPUTS and TX_RECONSIDERABLE results. Without the bias, reverting the witnessless-parent fix survived 57k runs.
Orphan handling treated every input's parent as missing: each was checked against the reject filters and requested from the orphan's announcers. A confirmed parent whose txid had entered the reject filter, which a rejected witnessless copy of it can cause, made the node drop every orphan spending one of its outputs. Have validation report which parents it found missing, and use only those when storing a new orphan. Parents that are present are no longer held against the orphan or requested. Update the orphan handling functional test, which expected present parents to be requested.
Check that a child spending a zero-fee parent and a confirmed output is stored and resolved even after the confirmed transaction's txid enters the reject filter, and that only the missing parent is requested. Have the txdownloadman_impl fuzz target pass a random non-empty subset of parents as missing.
TX_CONFLICT means the transaction is already known, in the mempool or confirmed, not that it is invalid. Its wtxid still went into the reject filter, and for a witnessless copy that is also the txid. If the known parent then leaves the mempool before the next block, through eviction or replacement, a child arriving afterwards is dropped as having a rejected parent. Don't add TX_CONFLICT results to the reject filter. The entry only saved re-downloading and re-checking a transaction we already have. Update the rejection-type table for TX_CONFLICT.
Check that after a stripped copy of a mempool parent is rejected as a conflict and the parent is evicted, a child spending it is still stored as an orphan.
bf732fa to
32cf270
Compare
|
note: I was considering the "average case" cost of c2d498b since theoretically it could be a common pattern to be missing an early input and we could skip more validation, but it turns out there is essentially no meaningful load like this, after analyzing over 36k orphans I could reconstruct history of and do some qualatative benchmarks, it adds maybe 10ms of verification in a day spread over up to ~75k orphans. I think the clarity of reporting what we're actually missing is better. The worst case is unchanged, where the entire tx is citing real inputs but they're all not the transaction maker's, so they fail script validation much later. |
|
ah, #33066 probably needs ot be directly addressed for F3+F4 from a local skill I'm tweaking, from which I got an Approach NACK: Click to expand additional detailsA. Working notesStatus: PR #36369 by instagibbs is open and not a draft. It has 5 commits of
Kept:
Rejected:
F1 (keep the orphan after a package-feerate failure) has no competing design
Kept:
Rejected:
F1 (keep the orphan after a package-feerate failure) has no competing design and looks correct as it is. Dominance: #33066's approach dominates F3+F4. It has the same payoff, removes the discipline risk by
|
fametrano
left a comment
There was a problem hiding this comment.
I checked that the new tests catch what they fix, at 32cf270. I reverted each of the four fixes on its own and ran txdownload_tests, p2p_opportunistic_1p1c.py and p2p_orphan_handling.py. Each revert makes at least one new test fail. F4 is caught only by the unit tests; no functional test covers it. I did not review the C++ changes.
One nit inline, in test_orphan_multiple_parents.
Happy to redo this check once F3 and F4 are reworked around #33066.
| assert_equal(len(peer.last_message["getdata"].inv), 1) | ||
| peer.wait_for_parent_requests([int(missing_tx["txid"], 16)]) |
There was a problem hiding this comment.
nit: assert_equal(len(peer.last_message["getdata"].inv), 1) can pass on the earlier getdata for the orphan, which also has one item. wait_for_parent_requests already checks the count. assert_never_requested checks directly that the long-confirmed parent is never requested. With this change the test passes, and with F3 reverted it fails at wait_for_parent_requests.
| assert_equal(len(peer.last_message["getdata"].inv), 1) | |
| peer.wait_for_parent_requests([int(missing_tx["txid"], 16)]) | |
| peer.wait_for_parent_requests([int(missing_tx["txid"], 16)]) | |
| peer.assert_never_requested(int(utxo_conf_old["txid"], 16)) |
|
putting this in draft since I want higher assurances that the gaps we care about are found and filled properly: #36437 Other PR has a more straight forward fix + invariant fuzzer |
|
replaced by #36506 |

Opportunistic 1p1c relay and orphan resolution fetch a missing parent by txid, but several outcomes
are recorded by wtxid, or against a single package member, in ways another peer could exploit. A peer
sending a variant of a parent with the same txid and a different or missing witness could make the node
drop the honest child, cancel the honest peer's request for the parent, or reject later children of
that parent. Each case delays a CPFP package until a new announcer appears or the parent confirms.
This PR fixes four such cases deemed the easiest to accomplish by a direct node peer trying to frustrate 1P1C relay at each individual hop.
There are remaining residuals that are cataloged here in sloppy form: https://gist.github.com/instagibbs/880a76535fd802fced9f9a5253cdbb40
To close these classes of issues by construction, we would have to replace our opportunistic protocol with a sender-initiated one, but that requires a network wide protocol update. This is beyond the scope of this PR and effort, for now.
Follow-up PR enforcing invariants we want to see post-fixes: #36371
Given these are 4 essentially individual fixes, I can also split off fixes to make review easier, but I will keep this PR open in some form to show the scope of the desired changes.
Related minor PR: #36328
Investigation kicked off by a Project Loupe report