Skip to content

Commit 1126c85

Browse files
committed
[qa] Change sync_blocks to pick smarter maxheight
Instead of syncing to max height returned by the waitforblockheight RPC, sync to the max height returned by the getblockcount RPC. This change was suggested by Suhas Daftuar <[email protected]>.
1 parent 67c6326 commit 1126c85

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

qa/rpc-tests/test_framework/util.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,19 @@ def sync_blocks(rpc_connections, *, wait=1, timeout=60):
129129
one node already synced to the latest, stable tip, otherwise there's a
130130
chance it might return before all nodes are stably synced.
131131
"""
132-
maxheight = 0
132+
# Use getblockcount() instead of waitforblockheight() to determine the
133+
# initial max height because the two RPCs look at different internal global
134+
# variables (chainActive vs latestBlock) and the former gets updated
135+
# earlier.
136+
maxheight = max(x.getblockcount() for x in rpc_connections)
133137
start_time = cur_time = time.time()
134138
while cur_time <= start_time + timeout:
135139
tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
136-
heights = [t["height"] for t in tips]
137-
if all(t == tips[0] for t in tips):
138-
return
139-
if all(h == heights[0] for h in heights):
140+
if all(t["height"] == maxheight for t in tips):
141+
if all(t["hash"] == tips[0]["hash"] for t in tips):
142+
return
140143
raise AssertionError("Block sync failed, mismatched block hashes:{}".format(
141144
"".join("\n {!r}".format(tip) for tip in tips)))
142-
maxheight = max(heights)
143145
cur_time = time.time()
144146
raise AssertionError("Block sync to height {} timed out:{}".format(
145147
maxheight, "".join("\n {!r}".format(tip) for tip in tips)))

0 commit comments

Comments
 (0)