Skip to content

Commit fa1436c

Browse files
author
MarcoFalke
committed
[qa] util: Remove unused sync_chain
1 parent dcfe218 commit fa1436c

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

test/functional/rpc_preciousblock.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from test_framework.util import (
99
assert_equal,
1010
connect_nodes_bi,
11-
sync_chain,
1211
sync_blocks,
1312
)
1413

@@ -72,7 +71,7 @@ def run_test(self):
7271
assert_equal(self.nodes[0].getbestblockhash(), hashC)
7372
self.log.info("Make Node1 prefer block C")
7473
self.nodes[1].preciousblock(hashC)
75-
sync_chain(self.nodes[0:2]) # wait because node 1 may not have downloaded hashC
74+
sync_blocks(self.nodes[0:2]) # wait because node 1 may not have downloaded hashC
7675
assert_equal(self.nodes[1].getbestblockhash(), hashC)
7776
self.log.info("Make Node1 prefer block G again")
7877
self.nodes[1].preciousblock(hashG)

test/functional/test_framework/util.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -361,54 +361,29 @@ def sync_blocks(rpc_connections, *, wait=1, timeout=60):
361361
one node already synced to the latest, stable tip, otherwise there's a
362362
chance it might return before all nodes are stably synced.
363363
"""
364-
# Use getblockcount() instead of waitforblockheight() to determine the
365-
# initial max height because the two RPCs look at different internal global
366-
# variables (chainActive vs latestBlock) and the former gets updated
367-
# earlier.
368-
maxheight = max(x.getblockcount() for x in rpc_connections)
369-
start_time = cur_time = time.time()
370-
while cur_time <= start_time + timeout:
371-
tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
372-
if all(t["height"] == maxheight for t in tips):
373-
if all(t["hash"] == tips[0]["hash"] for t in tips):
374-
return
375-
raise AssertionError("Block sync failed, mismatched block hashes:{}".format(
376-
"".join("\n {!r}".format(tip) for tip in tips)))
377-
cur_time = time.time()
378-
raise AssertionError("Block sync to height {} timed out:{}".format(
379-
maxheight, "".join("\n {!r}".format(tip) for tip in tips)))
380-
381-
def sync_chain(rpc_connections, *, wait=1, timeout=60):
382-
"""
383-
Wait until everybody has the same best block
384-
"""
385-
while timeout > 0:
364+
stop_time = time.time() + timeout
365+
while time.time() <= stop_time:
386366
best_hash = [x.getbestblockhash() for x in rpc_connections]
387-
if best_hash == [best_hash[0]] * len(best_hash):
367+
if best_hash.count(best_hash[0]) == len(rpc_connections):
388368
return
389369
time.sleep(wait)
390-
timeout -= wait
391-
raise AssertionError("Chain sync failed: Best block hashes don't match")
370+
raise AssertionError("Block sync timed out:{}".format("".join("\n {!r}".format(b) for b in best_hash)))
392371

393372
def sync_mempools(rpc_connections, *, wait=1, timeout=60, flush_scheduler=True):
394373
"""
395374
Wait until everybody has the same transactions in their memory
396375
pools
397376
"""
398-
while timeout > 0:
399-
pool = set(rpc_connections[0].getrawmempool())
400-
num_match = 1
401-
for i in range(1, len(rpc_connections)):
402-
if set(rpc_connections[i].getrawmempool()) == pool:
403-
num_match = num_match + 1
404-
if num_match == len(rpc_connections):
377+
stop_time = time.time() + timeout
378+
while time.time() <= stop_time:
379+
pool = [set(r.getrawmempool()) for r in rpc_connections]
380+
if pool.count(pool[0]) == len(rpc_connections):
405381
if flush_scheduler:
406382
for r in rpc_connections:
407383
r.syncwithvalidationinterfacequeue()
408384
return
409385
time.sleep(wait)
410-
timeout -= wait
411-
raise AssertionError("Mempool sync failed")
386+
raise AssertionError("Mempool sync timed out:{}".format("".join("\n {!r}".format(m) for m in pool)))
412387

413388
# Transaction/Block functions
414389
#############################

0 commit comments

Comments
 (0)