test: make p2p_orphan_handling's never-requested checks able to fail #36406

Manually merged
fametrano merged 2 commits from test-orphan-handling-never-requested-int into master 2026-11-04 21:29:10 +00:00 AGit
fametrano commented 2026-10-01 20:32:06 +00:00 (Migrated from github.com)

assert_never_requested compares its argument with the hashes in the node's getdata messages, which are ints. test_orphan_inherit_rejection passes it hex strings, so its four checks pass whatever the node requests.

This passes ints, which needs two more changes. The rejected parent is now relayed from peer2: relaying a transaction makes the node request it from that peer (the parent has no witness, so the request is for its txid), and from peer1 that request would fail the peer1 check. Mocktime is bumped before the peer1 and peer2 checks, because the node requests an orphan's missing parent only after a delay; without the bump those checks would pass before any request could be sent.

It also fixes a comment: the parent is rejected for its weight (tx-size), not its fee.

To see each check fail, change the scenario so that the node does request the hash. The commit message lists the changes I used.

Found while porting these tests to https://github.com/btclib-org/bitcoin-node-tests.

Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.

`assert_never_requested` compares its argument with the hashes in the node's getdata messages, which are ints. `test_orphan_inherit_rejection` passes it hex strings, so its four checks pass whatever the node requests. This passes ints, which needs two more changes. The rejected parent is now relayed from `peer2`: relaying a transaction makes the node request it from that peer (the parent has no witness, so the request is for its txid), and from `peer1` that request would fail the `peer1` check. Mocktime is bumped before the `peer1` and `peer2` checks, because the node requests an orphan's missing parent only after a delay; without the bump those checks would pass before any request could be sent. It also fixes a comment: the parent is rejected for its weight (`tx-size`), not its fee. To see each check fail, change the scenario so that the node does request the hash. The commit message lists the changes I used. Found while porting these tests to https://github.com/btclib-org/bitcoin-node-tests. *Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.*
DrahtBot commented 2026-10-01 20:32:26 +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 instagibbs

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/36406 * Ralph review: https://git.fish.foo/bitcoin/bitcoin/pulls/36406#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 | [instagibbs](https://github.com/bitcoin/bitcoin/pull/36406#issuecomment-5955357196) | 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

Base: 69142eacd1374925cc9e4ea736c21fcec16307d0
Head: 5f22014aca2d071edfea95e8d3d4ba0bebbc57ca

I found no actionable issues in this static review.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `69142eacd1374925cc9e4ea736c21fcec16307d0` Head: `5f22014aca2d071edfea95e8d3d4ba0bebbc57ca` I found no actionable issues in this static review. [Full review report](<https://review.fish.foo/traces/36406-5f22014aca2d071edfea95e8d3d4ba0bebbc57ca-290-2.html>)
instagibbs (Migrated from github.com) reviewed 2026-10-02 13:41:06 +00:00
instagibbs (Migrated from github.com) left a comment

concept ACK, good catches

Could we add this to assert_never_requested to remove the footgun and find misuse elsewhere going forward:

assert isinstance(txhash, int), f"txhash must be an int, got {type(txhash).__name__}"
concept ACK, good catches Could we add this to `assert_never_requested` to remove the footgun and find misuse elsewhere going forward: ``` assert isinstance(txhash, int), f"txhash must be an int, got {type(txhash).__name__}" ```
instagibbs (Migrated from github.com) commented 2026-10-02 13:36:05 +00:00

since we're changing this to peer2, and it's non-obvious, very brief comment why?

          # Relay it from peer2: below, we check that the node does not ask peer1 for the parent after
          # peer1 relays the child. Relaying the parent from peer1 would make that check fail, since the
          # node requests the parent from the relaying peer by wtxid, which equals its txid.
since we're changing this to peer2, and it's non-obvious, very brief comment why? ``` # Relay it from peer2: below, we check that the node does not ask peer1 for the parent after # peer1 relays the child. Relaying the parent from peer1 would make that check fail, since the # node requests the parent from the relaying peer by wtxid, which equals its txid. ```
instagibbs (Migrated from github.com) commented 2026-10-02 13:36:03 +00:00

nit: think this works here and elsewhere and is less verbose

        peer1.assert_never_requested(parent_overly_large_nonsegwit["txid"].txid_int)
nit: think this works here and elsewhere and is less verbose ```suggestion peer1.assert_never_requested(parent_overly_large_nonsegwit["txid"].txid_int) ```
fametrano commented 2026-10-02 15:07:05 +00:00 (Migrated from github.com)

Thanks, all three taken, and rebased on master. The int check is in its own commit; it trips nowhere else, because assert_never_requested is only defined and used in this test. x["txid"] is a hex string, so I used x["tx"].txid_int instead of x["txid"].txid_int.

Thanks, all three taken, and rebased on master. The int check is in its own commit; it trips nowhere else, because `assert_never_requested` is only defined and used in this test. `x["txid"]` is a hex string, so I used `x["tx"].txid_int` instead of `x["txid"].txid_int`.
instagibbs commented 2026-10-02 15:10:32 +00:00 (Migrated from github.com)
ACK https://github.com/bitcoin/bitcoin/pull/36406/commits/5f22014aca2d071edfea95e8d3d4ba0bebbc57ca
sedited (Migrated from github.com) approved these changes 2026-11-04 21:23:27 +00:00
sedited (Migrated from github.com) left a comment
ACK 5f22014aca2d071edfea95e8d3d4ba0bebbc57ca
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!36406
No description provided.