@@ -123,19 +123,26 @@ def str_to_b64str(string):
123
123
124
124
def sync_blocks (rpc_connections , * , wait = 1 , timeout = 60 ):
125
125
"""
126
- Wait until everybody has the same tip
126
+ Wait until everybody has the same tip.
127
+
128
+ sync_blocks needs to be called with an rpc_connections set that has least
129
+ one node already synced to the latest, stable tip, otherwise there's a
130
+ chance it might return before all nodes are stably synced.
127
131
"""
128
132
maxheight = 0
129
- while timeout > 0 :
133
+ start_time = cur_time = time .time ()
134
+ while cur_time <= start_time + timeout :
130
135
tips = [r .waitforblockheight (maxheight , int (wait * 1000 )) for r in rpc_connections ]
131
136
heights = [t ["height" ] for t in tips ]
132
- if tips == [ tips [0 ]] * len ( tips ):
137
+ if all ( t == tips [0 ] for t in tips ):
133
138
return
134
- if heights == [ heights [0 ]] * len ( heights ):
135
- raise AssertionError ("Block sync failed: (Hashes don't match)" )
136
- timeout -= wait
139
+ if all ( h == heights [0 ] for h in heights ):
140
+ raise AssertionError ("Block sync failed, mismatched block hashes:{}" . format (
141
+ "" . join ( " \n {!r}" . format ( tip ) for tip in tips )))
137
142
maxheight = max (heights )
138
- raise AssertionError ("Block sync failed with heights: {}" .format (heights ))
143
+ cur_time = time .time ()
144
+ raise AssertionError ("Block sync to height {} timed out:{}" .format (
145
+ maxheight , "" .join ("\n {!r}" .format (tip ) for tip in tips )))
139
146
140
147
def sync_chain (rpc_connections , * , wait = 1 , timeout = 60 ):
141
148
"""
0 commit comments