@@ -361,54 +361,29 @@ def sync_blocks(rpc_connections, *, wait=1, timeout=60):
361
361
one node already synced to the latest, stable tip, otherwise there's a
362
362
chance it might return before all nodes are stably synced.
363
363
"""
364
- # Use getblockcount() instead of waitforblockheight() to determine the
365
- # initial max height because the two RPCs look at different internal global
366
- # variables (chainActive vs latestBlock) and the former gets updated
367
- # earlier.
368
- maxheight = max (x .getblockcount () for x in rpc_connections )
369
- start_time = cur_time = time .time ()
370
- while cur_time <= start_time + timeout :
371
- tips = [r .waitforblockheight (maxheight , int (wait * 1000 )) for r in rpc_connections ]
372
- if all (t ["height" ] == maxheight for t in tips ):
373
- if all (t ["hash" ] == tips [0 ]["hash" ] for t in tips ):
374
- return
375
- raise AssertionError ("Block sync failed, mismatched block hashes:{}" .format (
376
- "" .join ("\n {!r}" .format (tip ) for tip in tips )))
377
- cur_time = time .time ()
378
- raise AssertionError ("Block sync to height {} timed out:{}" .format (
379
- maxheight , "" .join ("\n {!r}" .format (tip ) for tip in tips )))
380
-
381
- def sync_chain (rpc_connections , * , wait = 1 , timeout = 60 ):
382
- """
383
- Wait until everybody has the same best block
384
- """
385
- while timeout > 0 :
364
+ stop_time = time .time () + timeout
365
+ while time .time () <= stop_time :
386
366
best_hash = [x .getbestblockhash () for x in rpc_connections ]
387
- if best_hash == [ best_hash [0 ]] * len (best_hash ):
367
+ if best_hash . count ( best_hash [0 ]) == len (rpc_connections ):
388
368
return
389
369
time .sleep (wait )
390
- timeout -= wait
391
- raise AssertionError ("Chain sync failed: Best block hashes don't match" )
370
+ raise AssertionError ("Block sync timed out:{}" .format ("" .join ("\n {!r}" .format (b ) for b in best_hash )))
392
371
393
372
def sync_mempools (rpc_connections , * , wait = 1 , timeout = 60 , flush_scheduler = True ):
394
373
"""
395
374
Wait until everybody has the same transactions in their memory
396
375
pools
397
376
"""
398
- while timeout > 0 :
399
- pool = set (rpc_connections [0 ].getrawmempool ())
400
- num_match = 1
401
- for i in range (1 , len (rpc_connections )):
402
- if set (rpc_connections [i ].getrawmempool ()) == pool :
403
- num_match = num_match + 1
404
- if num_match == len (rpc_connections ):
377
+ stop_time = time .time () + timeout
378
+ while time .time () <= stop_time :
379
+ pool = [set (r .getrawmempool ()) for r in rpc_connections ]
380
+ if pool .count (pool [0 ]) == len (rpc_connections ):
405
381
if flush_scheduler :
406
382
for r in rpc_connections :
407
383
r .syncwithvalidationinterfacequeue ()
408
384
return
409
385
time .sleep (wait )
410
- timeout -= wait
411
- raise AssertionError ("Mempool sync failed" )
386
+ raise AssertionError ("Mempool sync timed out:{}" .format ("" .join ("\n {!r}" .format (m ) for m in pool )))
412
387
413
388
# Transaction/Block functions
414
389
#############################
0 commit comments