@ -123,10 +123,15 @@ def str_to_b64str(string):
def sync_blocks ( rpc_connections , * , wait = 1 , timeout = 60 ) :
def sync_blocks ( rpc_connections , * , wait = 1 , timeout = 60 ) :
"""
"""
Wait until everybody has the same tip
Wait until everybody has the same tip .
sync_blocks needs to be called with an rpc_connections set that has least
one node already synced to the latest , stable tip , otherwise there ' s a
chance it might return before all nodes are stably synced .
"""
"""
maxheight = 0
maxheight = 0
while timeout > 0 :
start_time = cur_time = time . time ( )
while cur_time < = start_time + timeout :
tips = [ r . waitforblockheight ( maxheight , int ( wait * 1000 ) ) for r in rpc_connections ]
tips = [ r . waitforblockheight ( maxheight , int ( wait * 1000 ) ) for r in rpc_connections ]
heights = [ t [ " height " ] for t in tips ]
heights = [ t [ " height " ] for t in tips ]
if tips == [ tips [ 0 ] ] * len ( tips ) :
if tips == [ tips [ 0 ] ] * len ( tips ) :
@ -134,8 +139,8 @@ def sync_blocks(rpc_connections, *, wait=1, timeout=60):
if heights == [ heights [ 0 ] ] * len ( heights ) :
if heights == [ heights [ 0 ] ] * len ( heights ) :
raise AssertionError ( " Block sync failed, mismatched block hashes: {} " . format (
raise AssertionError ( " Block sync failed, mismatched block hashes: {} " . format (
" " . join ( " \n {!r} " . format ( tip ) for tip in tips ) ) )
" " . join ( " \n {!r} " . format ( tip ) for tip in tips ) ) )
timeout - = wait
maxheight = max ( heights )
maxheight = max ( heights )
cur_time = time . time ( )
raise AssertionError ( " Block sync to height {} timed out: {} " . format (
raise AssertionError ( " Block sync to height {} timed out: {} " . format (
maxheight , " " . join ( " \n {!r} " . format ( tip ) for tip in tips ) ) )
maxheight , " " . join ( " \n {!r} " . format ( tip ) for tip in tips ) ) )