@@ -274,6 +274,17 @@ def setup_nodes(self):
274
274
self .add_nodes (self .num_nodes , extra_args )
275
275
self .start_nodes ()
276
276
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 )
277
288
278
289
def import_deterministic_coinbase_privkeys (self ):
279
290
for n in self .nodes :
@@ -433,7 +444,7 @@ def _start_logging(self):
433
444
def _initialize_chain (self ):
434
445
"""Initialize a pre-mined blockchain for use by the test.
435
446
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
437
448
Afterward, create num_nodes copies from the cache."""
438
449
439
450
assert self .num_nodes <= MAX_NODES
@@ -476,15 +487,24 @@ def _initialize_chain(self):
476
487
for node in self .nodes :
477
488
node .wait_for_rpc_connection ()
478
489
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
480
491
# 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().
481
496
for i in range (2 ):
482
497
for peer in range (4 ):
483
498
for j in range (25 ):
499
+ if i == 1 and peer == 3 and j == 24 :
500
+ break
484
501
self .nodes [peer ].generatetoaddress (1 , self .nodes [peer ].get_deterministic_priv_key ().address )
485
502
# Must sync before next peer starts generating blocks
486
503
sync_blocks (self .nodes )
487
504
505
+ for n in self .nodes :
506
+ assert_equal (n .getblockchaininfo ()["blocks" ], 199 )
507
+
488
508
# Shut them down, and clean up cache directories:
489
509
self .stop_nodes ()
490
510
self .nodes = []
0 commit comments