@@ -274,6 +274,17 @@ def setup_nodes(self):
274274 self .add_nodes (self .num_nodes , extra_args )
275275 self .start_nodes ()
276276 self .import_deterministic_coinbase_privkeys ()
277+ if not self .setup_clean_chain :
278+ for n in self .nodes :
279+ assert_equal (n .getblockchaininfo ()["blocks" ], 199 )
280+ self .log .debug ('Generate a block with current time to finalize the cache and assert we are out of IBD' )
281+ block_hash = self .nodes [0 ].generate (1 )[0 ]
282+ block = self .nodes [0 ].getblock (blockhash = block_hash , verbosity = 0 )
283+ for n in self .nodes :
284+ n .submitblock (block )
285+ chain_info = n .getblockchaininfo ()
286+ assert_equal (chain_info ["blocks" ], 200 )
287+ assert_equal (chain_info ["initialblockdownload" ], False )
277288
278289 def import_deterministic_coinbase_privkeys (self ):
279290 for n in self .nodes :
@@ -433,7 +444,7 @@ def _start_logging(self):
433444 def _initialize_chain (self ):
434445 """Initialize a pre-mined blockchain for use by the test.
435446
436- Create a cache of a 200 -block-long chain (with wallet) for MAX_NODES
447+ Create a cache of a 199 -block-long chain (with wallet) for MAX_NODES
437448 Afterward, create num_nodes copies from the cache."""
438449
439450 assert self .num_nodes <= MAX_NODES
@@ -476,15 +487,24 @@ def _initialize_chain(self):
476487 for node in self .nodes :
477488 node .wait_for_rpc_connection ()
478489
479- # Create a 200 -block-long chain; each of the 4 first nodes
490+ # Create a 199 -block-long chain; each of the 4 first nodes
480491 # gets 25 mature blocks and 25 immature.
492+ # The 4th node gets only 24 immature blocks so that the very last
493+ # block in the cache does not age too much (have an old tip age).
494+ # This is needed so that we are out of IBD when the test starts,
495+ # see the tip age check in IsInitialBlockDownload().
481496 for i in range (2 ):
482497 for peer in range (4 ):
483498 for j in range (25 ):
499+ if i == 1 and peer == 3 and j == 24 :
500+ break
484501 self .nodes [peer ].generatetoaddress (1 , self .nodes [peer ].get_deterministic_priv_key ().address )
485502 # Must sync before next peer starts generating blocks
486503 sync_blocks (self .nodes )
487504
505+ for n in self .nodes :
506+ assert_equal (n .getblockchaininfo ()["blocks" ], 199 )
507+
488508 # Shut them down, and clean up cache directories:
489509 self .stop_nodes ()
490510 self .nodes = []
0 commit comments