1717
1818import time
1919
20+ from test_framework .p2p import P2PInterface , msg_getheaders
2021from test_framework .test_framework import BitcoinTestFramework
2122from test_framework .util import assert_equal
2223
@@ -41,6 +42,9 @@ def setup_network(self):
4142 for i in range (self .num_nodes - 1 ):
4243 self .connect_nodes (i + 1 , i )
4344
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+
4448 def run_test (self ):
4549 # Start building a chain on node0. node2 shouldn't be able to sync until node1's
4650 # minchainwork is exceeded
@@ -71,6 +75,15 @@ def run_test(self):
7175 assert self .nodes [1 ].getbestblockhash () != self .nodes [0 ].getbestblockhash ()
7276 assert_equal (self .nodes [2 ].getblockcount (), starting_blockcount )
7377
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+
7487 self .log .info ("Generating one more block" )
7588 self .generate (self .nodes [0 ], 1 )
7689
@@ -85,5 +98,13 @@ def run_test(self):
8598 self .sync_all ()
8699 self .log .info (f"Blockcounts: { [n .getblockcount () for n in self .nodes ]} " )
87100
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+
88109if __name__ == '__main__' :
89110 MinimumChainWorkTest ().main ()
0 commit comments