|
18 | 18 | msg_block,
|
19 | 19 | msg_getdata,
|
20 | 20 | msg_getheaders,
|
| 21 | + p2p_lock, |
21 | 22 | )
|
22 | 23 | from test_framework.test_framework import BitcoinTestFramework
|
23 | 24 | from test_framework.util import (
|
@@ -57,18 +58,6 @@ def send_header_request(self, block_hash, node):
|
57 | 58 | msg.hashstop = block_hash
|
58 | 59 | node.send_message(msg)
|
59 | 60 |
|
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 |
| - |
72 | 61 | # Checks that stale blocks timestamped more than a month ago are not served
|
73 | 62 | # by the node while recent stale blocks and old active chain blocks are.
|
74 | 63 | # This does not currently test that stale blocks timestamped within the
|
@@ -109,24 +98,23 @@ def run_test(self):
|
109 | 98 |
|
110 | 99 | # Longest chain is extended so stale is much older than chain tip
|
111 | 100 | 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) |
113 | 102 | 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) |
119 | 103 | node0.sync_with_ping()
|
120 | 104 |
|
121 | 105 | # Request for very old stale block should now fail
|
| 106 | + with p2p_lock: |
| 107 | + node0.last_message.pop("block", None) |
122 | 108 | 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 |
125 | 111 |
|
126 | 112 | # Request for very old stale block header should now fail
|
| 113 | + with p2p_lock: |
| 114 | + node0.last_message.pop("headers", None) |
127 | 115 | 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 |
130 | 118 |
|
131 | 119 | # Verify we can fetch very old blocks and headers on the active chain
|
132 | 120 | block_hash = int(block_hashes[2], 16)
|
|
0 commit comments