17
17
18
18
import time
19
19
20
+ from test_framework .p2p import P2PInterface , msg_getheaders
20
21
from test_framework .test_framework import BitcoinTestFramework
21
22
from test_framework .util import assert_equal
22
23
@@ -41,6 +42,9 @@ def setup_network(self):
41
42
for i in range (self .num_nodes - 1 ):
42
43
self .connect_nodes (i + 1 , i )
43
44
45
+ # Set clock of node2 2 days ahead, to keep it in IBD during this test.
46
+ self .nodes [2 ].setmocktime (int (time .time ()) + 48 * 60 * 60 )
47
+
44
48
def run_test (self ):
45
49
# Start building a chain on node0. node2 shouldn't be able to sync until node1's
46
50
# minchainwork is exceeded
@@ -71,6 +75,15 @@ def run_test(self):
71
75
assert self .nodes [1 ].getbestblockhash () != self .nodes [0 ].getbestblockhash ()
72
76
assert_equal (self .nodes [2 ].getblockcount (), starting_blockcount )
73
77
78
+ self .log .info ("Check that getheaders requests to node2 are ignored" )
79
+ peer = self .nodes [2 ].add_p2p_connection (P2PInterface ())
80
+ msg = msg_getheaders ()
81
+ msg .locator .vHave = [int (self .nodes [2 ].getbestblockhash (), 16 )]
82
+ msg .hashstop = 0
83
+ peer .send_and_ping (msg )
84
+ time .sleep (5 )
85
+ assert "headers" not in peer .last_message
86
+
74
87
self .log .info ("Generating one more block" )
75
88
self .generate (self .nodes [0 ], 1 )
76
89
@@ -85,5 +98,13 @@ def run_test(self):
85
98
self .sync_all ()
86
99
self .log .info (f"Blockcounts: { [n .getblockcount () for n in self .nodes ]} " )
87
100
101
+ self .log .info ("Test that getheaders requests to node2 are not ignored" )
102
+ peer .send_and_ping (msg )
103
+ assert "headers" in peer .last_message
104
+
105
+ # Verify that node2 is in fact still in IBD (otherwise this test may
106
+ # not be exercising the logic we want!)
107
+ assert_equal (self .nodes [2 ].getblockchaininfo ()['initialblockdownload' ], True )
108
+
88
109
if __name__ == '__main__' :
89
110
MinimumChainWorkTest ().main ()
0 commit comments