Skip to content

Commit 6b56c1f

Browse files
committed
test: 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().
1 parent 136d96b commit 6b56c1f

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

test/functional/p2p_fingerprint.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
msg_block,
1919
msg_getdata,
2020
msg_getheaders,
21+
p2p_lock,
2122
)
2223
from test_framework.test_framework import BitcoinTestFramework
2324
from test_framework.util import (
@@ -57,18 +58,6 @@ def send_header_request(self, block_hash, node):
5758
msg.hashstop = block_hash
5859
node.send_message(msg)
5960

60-
# Check whether last block received from node has a given hash
61-
def last_block_equals(self, expected_hash, node):
62-
block_msg = node.last_message.get("block")
63-
return block_msg and block_msg.block.rehash() == expected_hash
64-
65-
# Check whether last block header received from node has a given hash
66-
def last_header_equals(self, expected_hash, node):
67-
headers_msg = node.last_message.get("headers")
68-
return (headers_msg and
69-
headers_msg.headers and
70-
headers_msg.headers[0].rehash() == expected_hash)
71-
7261
# Checks that stale blocks timestamped more than a month ago are not served
7362
# by the node while recent stale blocks and old active chain blocks are.
7463
# This does not currently test that stale blocks timestamped within the
@@ -109,24 +98,23 @@ def run_test(self):
10998

11099
# Longest chain is extended so stale is much older than chain tip
111100
self.nodes[0].setmocktime(0)
112-
tip = self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0]
101+
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
113102
assert_equal(self.nodes[0].getblockcount(), 14)
114-
115-
# Send getdata & getheaders to refresh last received getheader message
116-
block_hash = int(tip, 16)
117-
self.send_block_request(block_hash, node0)
118-
self.send_header_request(block_hash, node0)
119103
node0.sync_with_ping()
120104

121105
# Request for very old stale block should now fail
106+
with p2p_lock:
107+
node0.last_message.pop("block", None)
122108
self.send_block_request(stale_hash, node0)
123-
time.sleep(3)
124-
assert not self.last_block_equals(stale_hash, node0)
109+
node0.sync_with_ping()
110+
assert "block" not in node0.last_message
125111

126112
# Request for very old stale block header should now fail
113+
with p2p_lock:
114+
node0.last_message.pop("headers", None)
127115
self.send_header_request(stale_hash, node0)
128-
time.sleep(3)
129-
assert not self.last_header_equals(stale_hash, node0)
116+
node0.sync_with_ping()
117+
assert "headers" not in node0.last_message
130118

131119
# Verify we can fetch very old blocks and headers on the active chain
132120
block_hash = int(block_hashes[2], 16)

0 commit comments

Comments
 (0)