Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | def sync_blocks(rpc_connections, *, wait=1, timeout=60): | ||||
one node already synced to the latest, stable tip, otherwise there's a | one node already synced to the latest, stable tip, otherwise there's a | ||||
chance it might return before all nodes are stably synced. | chance it might return before all nodes are stably synced. | ||||
""" | """ | ||||
stop_time = time.time() + timeout | stop_time = time.time() + timeout | ||||
while time.time() <= stop_time: | while time.time() <= stop_time: | ||||
best_hash = [x.getbestblockhash() for x in rpc_connections] | best_hash = [x.getbestblockhash() for x in rpc_connections] | ||||
if best_hash.count(best_hash[0]) == len(rpc_connections): | if best_hash.count(best_hash[0]) == len(rpc_connections): | ||||
return | return | ||||
# Check that each peer has at least one connection | |||||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | |||||
time.sleep(wait) | time.sleep(wait) | ||||
raise AssertionError("Block sync timed out:{}".format( | raise AssertionError("Block sync timed out:{}".format( | ||||
"".join("\n {!r}".format(b) for b in best_hash))) | "".join("\n {!r}".format(b) for b in best_hash))) | ||||
def sync_mempools(rpc_connections, *, wait=1, | def sync_mempools(rpc_connections, *, wait=1, | ||||
timeout=60, flush_scheduler=True): | timeout=60, flush_scheduler=True): | ||||
""" | """ | ||||
Wait until everybody has the same transactions in their memory | Wait until everybody has the same transactions in their memory | ||||
pools | pools | ||||
""" | """ | ||||
stop_time = time.time() + timeout | stop_time = time.time() + timeout | ||||
while time.time() <= stop_time: | while time.time() <= stop_time: | ||||
pool = [set(r.getrawmempool()) for r in rpc_connections] | pool = [set(r.getrawmempool()) for r in rpc_connections] | ||||
if pool.count(pool[0]) == len(rpc_connections): | if pool.count(pool[0]) == len(rpc_connections): | ||||
if flush_scheduler: | if flush_scheduler: | ||||
for r in rpc_connections: | for r in rpc_connections: | ||||
r.syncwithvalidationinterfacequeue() | r.syncwithvalidationinterfacequeue() | ||||
return | return | ||||
# Check that each peer has at least one connection | |||||
assert (all([len(x.getpeerinfo()) for x in rpc_connections])) | |||||
time.sleep(wait) | time.sleep(wait) | ||||
raise AssertionError("Mempool sync timed out:{}".format( | raise AssertionError("Mempool sync timed out:{}".format( | ||||
"".join("\n {!r}".format(m) for m in pool))) | "".join("\n {!r}".format(m) for m in pool))) | ||||
# Transaction/Block functions | # Transaction/Block functions | ||||
############################# | ############################# | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |