test: fix no-immediate-response check in p2p_orphan_handling.py #37010

pull theStack wants to merge 1 commits into bitcoin:master from theStack:test-p2p-no_immediate_respose-fix changing 1 files +2 −2
  1. theStack commented at 5:20 PM on November 29, 2026: contributor

    The no-immediate-response check in p2p_orphan_handling.py currently can't fail and thus doesn't test anything: assert_no_immediate_response saves self.last_message before and after send_and_ping, but both names refer to the same dict, which on_message updates in place. Fix it by copying the dict before sending. The second copy isn't strictly needed, since nothing changes the dict after the ping returns, but it's added so both snapshots are taken the same way.

    This affects both call sites, including the check that the node doesn't serve a not-yet-announced parent to a spy peer.

    To check the helper itself, apply the subtest below (e.g. with git apply). An outbound peer gets an immediate getdata for an announced tx, which the helper should detect. On master it fails with "No exception raised"; with this PR it passes:

    <details> <summary>Patch</summary>

    diff --git a/test/functional/p2p_orphan_handling.py b/test/functional/p2p_orphan_handling.py
    --- a/test/functional/p2p_orphan_handling.py
    +++ b/test/functional/p2p_orphan_handling.py
    @@ -33,6 +33,7 @@ from test_framework.p2p import (
         TXID_RELAY_DELAY,
     )
     from test_framework.util import (
    +    assert_raises,
         assert_not_equal,
         assert_equal,
     )
    @@ -139,6 +140,14 @@ class OrphanHandlingTest(BitcoinTestFramework):
             peer.wait_for_getdata([wtxid])
             peer.send_and_ping(msg_tx(tx))
    
    + [@cleanup](/bitcoin-bitcoin/contributor/cleanup/)
    +    def test_no_immediate_response_helper(self):
    +        self.log.info("Check that assert_no_immediate_response detects an immediate response")
    +        # Outbound peers are preferred, so an announced wtxid is requested without delay
    +        peer = self.nodes[0].add_outbound_p2p_connection(PeerTxRelayer(), p2p_idx=0)
    +        assert_raises(AssertionError, peer.assert_no_immediate_response, msg_inv([CInv(t=MSG_WTX, h=1)]))
    +        assert_equal(peer.message_count["getdata"], 1)
    + [@cleanup](/bitcoin-bitcoin/contributor/cleanup/)
         def test_arrival_timing_orphan(self):
             self.log.info("Test missing parents that arrive during delay are not requested")
    @@ -883,6 +892,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
             self.wallet = MiniWallet(self.nodes[0])
             self.generate(self.wallet, 160)
    
    +        self.test_no_immediate_response_helper()
             self.test_arrival_timing_orphan()
             self.test_orphan_rejected_parents_exceptions()
             self.test_orphan_multiple_parents()
    

    </details>

    I'm not sure it makes sense to add a test for a test helper, so this isn't part of the PR for now. Happy to add it as a separate commit if reviewers think it's worth it.

  2. test: fix no-immediate-response check in p2p_orphan_handling.py
    The no-immediate-response check in p2p_orphan_handling.py currently
    can't fail and thus doesn't test anything: `assert_no_immediate_response`
    saves `self.last_message` before and after `send_and_ping`, but both
    names refer to the same dict, which `on_message` updates in place. Fix
    it by copying the dict before sending. The second copy isn't strictly
    needed, since nothing changes the dict after the ping returns, but it's
    added so both snapshots are taken the same way.
    
    This affects both call sites, including the check that the node doesn't
    serve a not-yet-announced parent to a spy peer.
    a62be857f4
  3. DrahtBot added the label Tests on Nov 29, 2026
  4. DrahtBot commented at 5:20 PM on November 29, 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-->

Contributors
Labels

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-30 03:50 UTC

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