@@ -121,33 +121,35 @@ def hex_str_to_bytes(hex_str):
121
121
def str_to_b64str (string ):
122
122
return b64encode (string .encode ('utf-8' )).decode ('ascii' )
123
123
124
- def sync_blocks (rpc_connections , wait = 1 , timeout = 60 ):
124
+ def sync_blocks (rpc_connections , * , wait = 1 , timeout = 60 ):
125
125
"""
126
126
Wait until everybody has the same tip
127
127
"""
128
128
maxheight = 0
129
129
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) " )
136
136
timeout -= wait
137
137
maxheight = max (heights )
138
- raise AssertionError ("Block sync failed" )
138
+ raise AssertionError ("Block sync failed with heights: {}" . format ( heights ) )
139
139
140
- def sync_chain (rpc_connections , wait = 1 ):
140
+ def sync_chain (rpc_connections , * , wait = 1 , timeout = 60 ):
141
141
"""
142
142
Wait until everybody has the same best block
143
143
"""
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
148
148
time .sleep (wait )
149
+ timeout -= wait
150
+ raise AssertionError ("Chain sync failed: Best block hashes don't match" )
149
151
150
- def sync_mempools (rpc_connections , wait = 1 , timeout = 60 ):
152
+ def sync_mempools (rpc_connections , * , wait = 1 , timeout = 60 ):
151
153
"""
152
154
Wait until everybody has the same transactions in their memory
153
155
pools
@@ -159,7 +161,7 @@ def sync_mempools(rpc_connections, wait=1, timeout=60):
159
161
if set (rpc_connections [i ].getrawmempool ()) == pool :
160
162
num_match = num_match + 1
161
163
if num_match == len (rpc_connections ):
162
- return True
164
+ return
163
165
time .sleep (wait )
164
166
timeout -= wait
165
167
raise AssertionError ("Mempool sync failed" )
0 commit comments