p2p: plug "tier 1" 1p1c liveness holes #36506

pull instagibbs wants to merge 4 commits into bitcoin:master from instagibbs:2026-10-1p1c-liveness-fixes changing 13 files +540 −22
  1. instagibbs commented at 9:20 PM on October 12, 2026: member

    Resolves a few key weaknesses in 1p1c relay, focusing on issues that can be easily achieved on average cpfp behavior.

    Deferred fuzz harness for the holes: https://github.com/instagibbs/bitcoin/tree/2026-11-1p1c-liveness-fuzz

    Known issues doc: https://gist.github.com/instagibbs/880a76535fd802fced9f9a5253cdbb40

  2. DrahtBot added the label P2P on Oct 12, 2026
  3. DrahtBot commented at 9:20 PM on October 12, 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.

    Type Reviewers
    ACK mzumsande
    Concept ACK ismaelsadeeq
    Stale ACK fametrano

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36946 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36946.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where comparison-specific test macros should replace generic comparisons:

    • test/functional/p2p_opportunistic_1p1c.py: assert package_fee / honest_vsize * 1000 > mempoolminfee → Prefer assert_greater_than(package_fee / honest_vsize * 1000, mempoolminfee).

    <sup>2026-11-30 20:30:50</sup>

  4. instagibbs force-pushed on Oct 14, 2026
  5. instagibbs marked this as ready for review on Oct 14, 2026
  6. instagibbs renamed this:
    p2p: plug various 1p1c liveness holes
    p2p: plug "tier 1" 1p1c liveness holes
    on Oct 14, 2026
  7. instagibbs force-pushed on Oct 14, 2026
  8. DrahtBot added the label CI failed on Oct 14, 2026
  9. instagibbs commented at 2:07 AM on October 14, 2026: member

    @marcofleon @mzumsande this will be the ultimate target PR to fuzz

  10. instagibbs force-pushed on Oct 14, 2026
  11. DrahtBot removed the label CI failed on Oct 14, 2026
  12. fametrano commented at 2:43 PM on October 14, 2026: none

    Tested c8abd9ee41: each of the four fixes is caught by a test this PR adds or extends. I reverted each fix on its own, keeping the tests, and each revert made txdownload_tests, orphanage_tests or p2p_opportunistic_1p1c.py fail, while the unchanged branch passes them all. I did not review the C++ changes. Details on request.

  13. fametrano commented at 3:31 PM on October 14, 2026: none

    ACK c8abd9ee41. I have now reviewed the four fixes commit by commit and found nothing blocking. One gap remains for a follow-up: in the 1p1c package path, a DIFFERENT_WITNESS result still goes through ProcessInvalidTx, so a witness-stripped copy of a mempool parent puts the parent's txid in the reject filter, as TX_CONFLICT did before 3a2b5539a1. A functional test shows it end to end: an attacker peer re-sends the stripped copy with an orphan of its own, and after the parent leaves the mempool, an honest child is dropped as having a rejected parent. Test on request.

  14. instagibbs force-pushed on Oct 15, 2026
  15. fametrano commented at 3:28 AM on October 15, 2026: none

    reACK 8d44ac8909. The new DIFFERENT_WITNESS case closes the 1p1c gap I noted at c8abd9ee41, and the only other code change is its test, known_parent_in_package_does_not_poison_after_eviction. I built test_bitcoin and ran txdownload_tests, orphanage_tests and txpackage_tests: the new test passes, and fails with that case moved back next to INVALID.

  16. instagibbs commented at 4:04 AM on October 15, 2026: member

    @fametrano fuzzer hit it, which is a good sign

  17. mzumsande commented at 6:05 PM on November 24, 2026: contributor

    Concept ACK

    I reviewed the production code fixes/non-fuzz test changes and they are all quite small and reviewable, and they all look good to me.

    Personally, it would help me to ACK quicker if the large p2p_1p1c_liveness fuzz target was added in a separate PR, especially since all the changes covered by other tests as well, and a lot of code gets added first and then removed again in later commits - but up to you of course.

  18. instagibbs commented at 7:19 PM on November 24, 2026: member

    Personally, it would help me to ACK quicker if the large p2p_1p1c_liveness fuzz target was added in a separate PR, especially since all the changes covered by other tests as well, and a lot of code gets added first and then removed again in later commits - but up to you of course.

    If that makes it easier, can do. Would you prefer just to have me close #36437 , split out the fuzz target commits, and get this one merged ASAP?

  19. instagibbs force-pushed on Nov 25, 2026
  20. instagibbs commented at 3:51 PM on November 25, 2026: member

    Rabased on master, deferring the fuzz harness as future PR work at https://github.com/instagibbs/bitcoin/tree/2026-11-1p1c-liveness-fuzz

  21. fanquake added this to the milestone 33.0 on Nov 25, 2026
  22. in src/txrequest.h:161 in a30665c3c6
     156 | +     *
     157 | +     * Announcements of the other type for the same txhash are kept. This matters when txid == wtxid: a txid
     158 | +     * announcement is a request for the transaction with any witness, so a verdict about one witness (recorded
     159 | +     * under a wtxid that equals the txid because that copy had no witness) should not cancel it.
     160 | +     */
     161 | +    void ForgetTxHash(const GenTxid& gtxid);
    


    mzumsande commented at 5:48 PM on November 30, 2026:

    I think I'd prefer a different name, such as ForgetTxHashOfType or similar to avoid confusion with the existing method (e.g. ForgetTxHash(ptx->GetHash()) used to be a compile error, now it compiles and has different behavior from ForgetTxHash(ptx->GetHash().ToUint256())) which may not be intended by future callers.


    instagibbs commented at 8:07 PM on November 30, 2026:

    suggestion taken

  23. in src/txrequest.h:219 in a30665c3c6
     213 | @@ -203,6 +214,10 @@ class TxRequestTracker {
     214 |       * result_peers. Does not try to ensure that result_peers contains no duplicates. */
     215 |      void GetCandidatePeers(const uint256& txhash, std::vector<NodeId>& result_peers) const;
     216 |  
     217 | +    /** Like GetCandidatePeers(txhash, result_peers), but only for announcements whose type (txid or wtxid)
     218 | +     * matches that of gtxid. */
     219 | +    void GetCandidatePeers(const GenTxid& gtxid, std::vector<NodeId>& result_peers) const;
    


    mzumsande commented at 5:54 PM on November 30, 2026:

    nit: Maybe we don't really need this? It's only called from tests, and it seems that existing checks already covers the behavior pretty well, so not sure if its adds enough additional coverage.


    instagibbs commented at 8:07 PM on November 30, 2026:

    removed

  24. mzumsande commented at 6:09 PM on November 30, 2026: contributor

    Code Review ACK a30665c3c66f90f9130e43bcd231f26ddd89f73e

    I reviewed the entire code changes after the new fuzz test was deferred, the comments are minor.

  25. instagibbs force-pushed on Nov 30, 2026
  26. txorphanage: hand reconsideration over when its announcement is erased
    A child that arrives before its parent is kept as an orphan. Once the
    parent is accepted on its own, the orphan is put in one randomly chosen
    announcer's work set to be retried. If that announcer disconnects or is
    evicted first, the orphan is never retried, and re-announcements by the
    other announcers don't fetch it again since it is already held. This
    keeps e.g. a CPFP child of a parent that pays for itself out of the
    mempool until the orphan is evicted, and an announcer can cause it on
    purpose.
    
    Hand reconsideration over to the remaining announcer with the lowest
    NodeId instead.
    fc024e7ae1
  27. p2p: don't add already-known transactions to the reject filter
    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. For a witnessless copy that is also the txid, so if the known
    parent then left the mempool before the next block, a child arriving
    afterwards was dropped as having a rejected parent. For the honest
    version of a parent whose other-witness version is in the mempool, the
    honest parent itself was ignored once that version left.
    
    Don't add TX_CONFLICT results to the reject filter. The entry only saved
    re-downloading and re-checking a transaction we already have. Do the
    same for a DIFFERENT_WITNESS result in 1p1c package evaluation, which
    ProcessPackageResult passed to ProcessInvalidTx with a valid state and
    so reached the filter by another path.
    
    This also keeps a witnessless copy of a confirmed transaction out of
    the filter, as it is rejected as already known when one of its outputs
    is in the coins cache, so children spending that transaction are no
    longer dropped. A copy of a coinbase is rejected as TX_CONSENSUS
    instead, before any input lookup, and still poisons the coinbase's
    txid.
    
    Update the rejection-type table for TX_CONFLICT.
    744f2773ca
  28. p2p: keep orphan after a package feerate failure
    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.
    a0545eb857
  29. txrequest: forget announcements by type, keep orphan parent requests
    A reconsiderable rejection of a witnessless copy of a transaction
    forgot its wtxid in TxRequestTracker regardless of announcement type,
    and since that wtxid equals the txid, it also cancelled every peer's
    txid-typed request for the transaction, including orphan resolution
    requests for a missing parent.
    
    Now only wtxid-typed announcements of that hash are forgotten, so
    witnessless parents are treated like witnessed ones, which were never
    affected since their wtxid differs from the txid.
    d8c1eb7e8d
  30. instagibbs force-pushed on Nov 30, 2026
  31. mzumsande commented at 3:00 PM on December 1, 2026: contributor

    Code Review ACK d8c1eb7e8d3a1bc99313c4e70b36d874ce865f5f

  32. ismaelsadeeq commented at 3:27 PM on December 3, 2026: member

    Concept ACK


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-12-04 00:52 UTC

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