@@ -121,33 +121,35 @@ def hex_str_to_bytes(hex_str):
121121def str_to_b64str (string ):
122122 return b64encode (string .encode ('utf-8' )).decode ('ascii' )
123123
124- def sync_blocks (rpc_connections , wait = 1 , timeout = 60 ):
124+ def sync_blocks (rpc_connections , * , wait = 1 , timeout = 60 ):
125125 """
126126 Wait until everybody has the same tip
127127 """
128128 maxheight = 0
129129 while timeout > 0 :
130- tips = [ x .waitforblockheight (maxheight , int (wait * 1000 )) for x in rpc_connections ]
131- heights = [ x ["height" ] for x in tips ]
132- if tips == [ tips [0 ] ] * len (tips ):
133- return True
134- if heights == [ heights [0 ] ] * len (heights ): #heights are the same but hashes are not
135- raise AssertionError ("Block sync failed" )
130+ tips = [r .waitforblockheight (maxheight , int (wait * 1000 )) for r in rpc_connections ]
131+ heights = [t ["height" ] for t in tips ]
132+ if tips == [tips [0 ]] * len (tips ):
133+ return
134+ if heights == [heights [0 ]] * len (heights ):
135+ raise AssertionError ("Block sync failed: (Hashes don't match) " )
136136 timeout -= wait
137137 maxheight = max (heights )
138- raise AssertionError ("Block sync failed" )
138+ raise AssertionError ("Block sync failed with heights: {}" . format ( heights ) )
139139
140- def sync_chain (rpc_connections , wait = 1 ):
140+ def sync_chain (rpc_connections , * , wait = 1 , timeout = 60 ):
141141 """
142142 Wait until everybody has the same best block
143143 """
144- while True :
145- counts = [ x .getbestblockhash () for x in rpc_connections ]
146- if counts == [ counts [0 ] ]* len (counts ):
147- break
144+ while timeout > 0 :
145+ best_hash = [x .getbestblockhash () for x in rpc_connections ]
146+ if best_hash == [best_hash [0 ]]* len (best_hash ):
147+ return
148148 time .sleep (wait )
149+ timeout -= wait
150+ raise AssertionError ("Chain sync failed: Best block hashes don't match" )
149151
150- def sync_mempools (rpc_connections , wait = 1 , timeout = 60 ):
152+ def sync_mempools (rpc_connections , * , wait = 1 , timeout = 60 ):
151153 """
152154 Wait until everybody has the same transactions in their memory
153155 pools
@@ -159,7 +161,7 @@ def sync_mempools(rpc_connections, wait=1, timeout=60):
159161 if set (rpc_connections [i ].getrawmempool ()) == pool :
160162 num_match = num_match + 1
161163 if num_match == len (rpc_connections ):
162- return True
164+ return
163165 time .sleep (wait )
164166 timeout -= wait
165167 raise AssertionError ("Mempool sync failed" )
0 commit comments