Skip to content

Commit 0f0229d

Browse files
committed
Merge #12643: [qa] util: Remove unused sync_chain
fa1436c [qa] util: Remove unused sync_chain (MarcoFalke) Pull request description: The util function `sync_blocks` already checks for equal chains, so we can remove the unused `sync_chain`. Also cleaned up the errors that are printed in case of timeout: ``` AssertionError: Block sync timed out: '72a3a3e9dcfd0a09204c3447af0f481d19641eeadbe6a91b8e680ed614bc7712' '5032af4ae22ae7a21afdc9d9f516877309c4dd8ef2ecadb9354be7088439b4a6' '5032af4ae22ae7a21afdc9d9f516877309c4dd8ef2ecadb9354be7088439b4a6' ``` and ``` AssertionError: Mempool sync timed out: {'c2af943d9b321c36e0f5a153a9d3d8b11bdd46ceb28e38f5fd2c722e3edb3563'} set() set() ``` Tree-SHA512: cb4ad30e3e3773072f59afa2c81cfa27bd8f389a93f02acb919990298627fcfbaa53a3d3944d827cc8a5d009871e42a47ea09e9bb93e85c22e3af6a24a574e5d
2 parents 0f58d7f + fa1436c commit 0f0229d

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
@@ -370,54 +370,29 @@ def sync_blocks(rpc_connections, *, wait=1, timeout=60):
370370
one node already synced to the latest, stable tip, otherwise there's a
371371
chance it might return before all nodes are stably synced.
372372
"""
373-
# Use getblockcount() instead of waitforblockheight() to determine the
374-
# initial max height because the two RPCs look at different internal global
375-
# variables (chainActive vs latestBlock) and the former gets updated
376-
# earlier.
377-
maxheight = max(x.getblockcount() for x in rpc_connections)
378-
start_time = cur_time = time.time()
379-
while cur_time <= start_time + timeout:
380-
tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
381-
if all(t["height"] == maxheight for t in tips):
382-
if all(t["hash"] == tips[0]["hash"] for t in tips):
383-
return
384-
raise AssertionError("Block sync failed, mismatched block hashes:{}".format(
385-
"".join("\n {!r}".format(tip) for tip in tips)))
386-
cur_time = time.time()
387-
raise AssertionError("Block sync to height {} timed out:{}".format(
388-
maxheight, "".join("\n {!r}".format(tip) for tip in tips)))
389-
390-
def sync_chain(rpc_connections, *, wait=1, timeout=60):
391-
"""
392-
Wait until everybody has the same best block
393-
"""
394-
while timeout > 0:
373+
stop_time = time.time() + timeout
374+
while time.time() <= stop_time:
395375
best_hash = [x.getbestblockhash() for x in rpc_connections]
396-
if best_hash == [best_hash[0]] * len(best_hash):
376+
if best_hash.count(best_hash[0]) == len(rpc_connections):
397377
return
398378
time.sleep(wait)
399-
timeout -= wait
400-
raise AssertionError("Chain sync failed: Best block hashes don't match")
379+
raise AssertionError("Block sync timed out:{}".format("".join("\n {!r}".format(b) for b in best_hash)))
401380

402381
def sync_mempools(rpc_connections, *, wait=1, timeout=60, flush_scheduler=True):
403382
"""
404383
Wait until everybody has the same transactions in their memory
405384
pools
406385
"""
407-
while timeout > 0:
408-
pool = set(rpc_connections[0].getrawmempool())
409-
num_match = 1
410-
for i in range(1, len(rpc_connections)):
411-
if set(rpc_connections[i].getrawmempool()) == pool:
412-
num_match = num_match + 1
413-
if num_match == len(rpc_connections):
386+
stop_time = time.time() + timeout
387+
while time.time() <= stop_time:
388+
pool = [set(r.getrawmempool()) for r in rpc_connections]
389+
if pool.count(pool[0]) == len(rpc_connections):
414390
if flush_scheduler:
415391
for r in rpc_connections:
416392
r.syncwithvalidationinterfacequeue()
417393
return
418394
time.sleep(wait)
419-
timeout -= wait
420-
raise AssertionError("Mempool sync failed")
395+
raise AssertionError("Mempool sync timed out:{}".format("".join("\n {!r}".format(m) for m in pool)))
421396

422397
# Transaction/Block functions
423398
#############################

0 commit comments

Comments
 (0)