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

Manually merged
theStack merged 1 commit from test-p2p-no_immediate_respose-fix into master 2026-11-30 13:48:29 +00:00 AGit
theStack commented 2026-11-29 17:20:06 +00:00 (Migrated from github.com)

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:

Patch
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
+    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
     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()

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.

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 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 + 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 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.
DrahtBot commented 2026-11-29 17:20:18 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko

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

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37010 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37010.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37010#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/37010#issuecomment-7278384306) | 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No findings were published from this review.

Review coverage was incomplete.


Reviewed: a62be857f4de · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afedb19cca4c3b40d89514fb0c66b0c20e4f5d62 --> <!-- ralph-head:a62be857f4de782b8b1f541e580f394333434e2c --> <!-- ralph-case:d99bf40f2487869794f5c962e9becc661a1b0c3d49ad80952705a362e11cebb3 --> No findings were published from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`a62be857f4de`](<https://git.fish.foo/bitcoin/bitcoin/commit/a62be857f4de782b8b1f541e580f394333434e2c>) · [Review report](<https://review.fish.foo/report/37010-a62be857f4de782b8b1f541e580f394333434e2c-3303-1.html>) · [Previous reports](<https://review.fish.foo/traces/37010/>) [permalink](<https://review.fish.foo/report/37010-a62be857f4de782b8b1f541e580f394333434e2c-3303-1.html>)
maflcko commented 2026-11-30 12:24:10 +00:00 (Migrated from github.com)

lgtm ACK a62be857f4

lgtm ACK a62be857f4de782b8b1f541e580f394333434e2c
fanquake commented 2026-11-30 14:10:33 +00:00 (Migrated from github.com)

Backported to 32.x in #36984.

Backported to `32.x` in #36984.
fanquake commented 2026-11-30 14:21:46 +00:00 (Migrated from github.com)

Backported to 31.x in #36928 and 30.x in #36929.

Backported to `31.x` in #36928 and `30.x` in #36929.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37010
No description provided.