This small PR takes use of the message receiving helper functions wait_for_block() and wait_for_header() (from module test_framework.p2p) in the test p2p_fingerprint.py. It also simplifies the checks for very old stale blocks/headers requests by getting rid of the functions last_block_equals() and last_header_equals() and rather only testing that not any blocks/headers message is received at all. Unneeded sending of requests are also removed and calls to time.sleep(...) substituted by ping syncs.
test: use wait_for_{block,header} helpers in p2p_fingerprint.py #20047
pull theStack wants to merge 2 commits into bitcoin:master from theStack:20200930-test-use-wait-for-block-header-in-fingerprint-py changing 1 files +14 −30-
theStack commented at 3:01 PM on September 30, 2020: member
-
test: use wait_for_{block,header} helpers in p2p_fingerprint.py 136d96b71f
-
theStack commented at 3:01 PM on September 30, 2020: member
Note that the test methods
last_block_equals()andlast_header_equals()are still needed for checking that the concerned message didn't arrive within a certain time window: https://github.com/bitcoin/bitcoin/blob/72affcb16cad45bd9e08ca163b2147fd01b84b70/test/functional/p2p_fingerprint.py#L123-L131 Unfortunately I couldn't figure out how to use thewait_for_{block,header}functions for that -- using something likeassert_raises(AssertionError, lambda: node0.wait_for_block(stale_hash, timeout=3))works, but still prints out the assertion error, clogging up the log:
2020-09-30T15:00:20.316000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_hh8usu8u 2020-09-30T15:00:27.134000Z TestFramework.utils (ERROR): wait_until() failed. Predicate: '''' def test_function(): if check_connected: assert self.is_connected return test_function_in() ''' 2020-09-30T15:00:30.150000Z TestFramework.utils (ERROR): wait_until() failed. Predicate: '''' def test_function(): if check_connected: assert self.is_connected return test_function_in() ''' 2020-09-30T15:00:30.252000Z TestFramework (INFO): Stopping nodes 2020-09-30T15:00:30.354000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_hh8usu8u on exit 2020-09-30T15:00:30.355000Z TestFramework (INFO): Tests successful - DrahtBot added the label Tests on Sep 30, 2020
-
guggero commented at 10:20 AM on October 4, 2020: contributor
Concept ACK 136d96b7.
Maybe we should inline the two methods
last_block_equalsandlast_header_equalsbecause they are only used with a negation currently. That means the test would still pass if for some reasonnode.last_message.get("block")is falsey. What should be tested in theassert not self.last_block_equals()is that the last message's block was available but the hash didn't match. -
theStack commented at 12:36 PM on October 4, 2020: member
@guggero: Thanks a lot for reviewing and your inputs, good points! I think that actually we can get rid of the functions
last_{block,header}_equalscompletely (i.e. not even needing to inline them), as a check ensuring that no blocks or header message actually arrives after requesting very old blocks/headers should be sufficient. That is, removing "blocks"/"headers" from the last_message dictionary before the request, and after the waiting time, checking that it hasn't been added in-between. That should do it in my opinion. -
guggero commented at 1:09 PM on October 4, 2020: contributor
tACK 521b833a.
Nice change with this additional commit, I agree that this makes the test even more precise while removing more code than it adds.
-
in test/functional/p2p_fingerprint.py:107 in 521b833a32 outdated
107 | @@ -121,14 +108,18 @@ def run_test(self): 108 | node0.sync_with_ping() 109 | 110 | # Request for very old stale block should now fail 111 | + with p2p_lock: 112 | + node0.last_message.pop("block", None)
MarcoFalke commented at 10:00 AM on October 5, 2020:I think this can replace the section "# Send getdata & getheaders to refresh last received getheader message", no?
theStack commented at 1:29 PM on October 6, 2020:Indeed, done. The "node0.sync_with_ping()" is still needed though to ensure that the newly generated block in the previous section "Longest chain is extended so stale is much older than chain tip" has been already received and doesn't interfere with the request for the old stale block test.
in test/functional/p2p_fingerprint.py:114 in 521b833a32 outdated
107 | @@ -121,14 +108,18 @@ def run_test(self): 108 | node0.sync_with_ping() 109 | 110 | # Request for very old stale block should now fail 111 | + with p2p_lock: 112 | + node0.last_message.pop("block", None) 113 | self.send_block_request(stale_hash, node0) 114 | time.sleep(3)
MarcoFalke commented at 10:01 AM on October 5, 2020:unrelated: why not sync_with_ping?
theStack commented at 1:29 PM on October 6, 2020:Good idea, done. It's always nice to get rid of time.sleep(...) constructs that are not really needed.
MarcoFalke approvedMarcoFalke commented at 10:01 AM on October 5, 2020: memberACK
theStack force-pushed on Oct 6, 2020theStack commented at 1:30 PM on October 6, 2020: memberForce-pushed with the suggestions from MarcoFalke (https://github.com/bitcoin/bitcoin/pull/20047#discussion_r499482654, #20047 (review)).
theStack force-pushed on Oct 6, 2020in test/functional/p2p_fingerprint.py:101 in 8e4fd958e8 outdated
97 | @@ -109,24 +98,23 @@ def run_test(self): 98 | 99 | # Longest chain is extended so stale is much older than chain tip 100 | self.nodes[0].setmocktime(0) 101 | - tip = self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0] 102 | + self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0]
guggero commented at 12:42 PM on October 21, 2020:The array index selection at the end of the line (
[0]) isn't needed anymore if return value isn't stored in a variable.
theStack commented at 1:33 PM on October 21, 2020:Good find, thanks! Fixed.
6b56c1f4d0test: remove last_{block,header}_equals() in p2p_fingerprint.py
Testing that requests to very old blocks / block headers fail can simply be done by checking that the node doesn't respond with any "blocks" / "headers" message at all. Also removes unnecessary sending of block/header requests and replaces time.sleep(3) with node0.sync_with_ping().
theStack force-pushed on Oct 21, 2020guggero commented at 7:58 AM on October 22, 2020: contributorACK 6b56c1f4
laanwj merged this on Nov 19, 2020laanwj closed this on Nov 19, 2020MarcoFalke commented at 3:37 PM on November 19, 2020: memberpm ACK 6b56c1f4d0d5857d9d61a81dc96db1b603c368b5
sidhujag referenced this in commit 1d61eea827 on Nov 19, 2020theStack deleted the branch on Dec 1, 2020deadalnix referenced this in commit 8ae2ce5d86 on Jan 11, 2022DrahtBot locked this on Feb 15, 2022ContributorsLabels
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-04-14 21:14 UTC
More mirrored repositories can be found on mirror.b10c.me