MCPcopy Create free account
hub / github.com/LUX-Core/lux / sync_blocks

Function sync_blocks

test/functional/test_framework/util.py:358–381  ·  view source on GitHub ↗

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.

(rpc_connections, *, wait=1, timeout=60)

Source from the content-addressed store, hash-verified

356 connect_nodes(nodes[b], a)
357
358def sync_blocks(rpc_connections, *, wait=1, timeout=60):
359 """
360 Wait until everybody has the same tip.
361
362 sync_blocks needs to be called with an rpc_connections set that has least
363 one node already synced to the latest, stable tip, otherwise there's a
364 chance it might return before all nodes are stably synced.
365 """
366 # Use getblockcount() instead of waitforblockheight() to determine the
367 # initial max height because the two RPCs look at different internal global
368 # variables (chainActive vs latestBlock) and the former gets updated
369 # earlier.
370 maxheight = max(x.getblockcount() for x in rpc_connections)
371 start_time = cur_time = time.time()
372 while cur_time <= start_time + timeout:
373 tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
374 if all(t["height"] == maxheight for t in tips):
375 if all(t["hash"] == tips[0]["hash"] for t in tips):
376 return
377 raise AssertionError("Block sync failed, mismatched block hashes:{}".format(
378 "".join("\n {!r}".format(tip) for tip in tips)))
379 cur_time = time.time()
380 raise AssertionError("Block sync to height {} timed out:{}".format(
381 maxheight, "".join("\n {!r}".format(tip) for tip in tips)))
382
383def sync_chain(rpc_connections, *, wait=1, timeout=60):
384 """

Callers 2

sync_allMethod · 0.70
_initialize_chainMethod · 0.70

Calls 3

maxFunction · 0.85
formatMethod · 0.80
joinMethod · 0.45

Tested by 2

sync_allMethod · 0.56
_initialize_chainMethod · 0.56