Skip to content

Commit cc68a3b

Browse files
committed
Merge bitcoin/bitcoin#28589: test: assumeutxo func test race fixes
7e40032 tests: assumeutxo: accept final height from either chainstate (James O'Beirne) 5bd2010 test: assumeutxo: avoid race in functional test (James O'Beirne) 7005a01 test: add wait_for_connect to BitcoinTestFramework.connect_nodes (James O'Beirne) Pull request description: Fixes bitcoin/bitcoin#28585. Fixes a few races within the assumeutxo tests: - In general, `-stopatheight` can't be used with `connect_nodes` safely because the latter performs blocking assertions that are racy with the stopatheight triggering. - Now that the snapshot chainstate is listed as `normal` after background validation, accept the final height from either chainstate. ACKs for top commit: MarcoFalke: lgtm ACK 7e40032 fjahr: Code review ACK 7e40032 achow101: ACK 7e40032 ryanofsky: Code review ACK 7e40032 Tree-SHA512: 8cbd2a0ca8643f94baa0ae3561dcf68c3519d5ba851c6049e1768f28cae6434f47ffc28d404bf38ed11030ce3f00aae0a8be3f6d563e6ae6680d83c928a173d8
2 parents 3cd0280 + 7e40032 commit cc68a3b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ def no_sync():
142142
f"-stopatheight={PAUSE_HEIGHT}", *self.extra_args[1]])
143143

144144
# Finally connect the nodes and let them sync.
145-
self.connect_nodes(0, 1)
145+
#
146+
# Set `wait_for_connect=False` to avoid a race between performing connection
147+
# assertions and the -stopatheight tripping.
148+
self.connect_nodes(0, 1, wait_for_connect=False)
146149

147150
n1.wait_until_stopped(timeout=5)
148151

@@ -156,7 +159,15 @@ def no_sync():
156159
self.connect_nodes(0, 1)
157160

158161
self.log.info(f"Ensuring snapshot chain syncs to tip. ({FINAL_HEIGHT})")
159-
wait_until_helper(lambda: n1.getchainstates()['snapshot']['blocks'] == FINAL_HEIGHT)
162+
163+
def check_for_final_height():
164+
chainstates = n1.getchainstates()
165+
# The background validation may have completed before we run our first
166+
# check, so accept a final blockheight from either chainstate type.
167+
cs = chainstates.get('snapshot') or chainstates.get('normal')
168+
return cs['blocks'] == FINAL_HEIGHT
169+
170+
wait_until_helper(check_for_final_height)
160171
self.sync_blocks(nodes=(n0, n1))
161172

162173
self.log.info("Ensuring background validation completes")

test/functional/test_framework/test_framework.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,14 @@ def restart_node(self, i, extra_args=None):
586586
def wait_for_node_exit(self, i, timeout):
587587
self.nodes[i].process.wait(timeout)
588588

589-
def connect_nodes(self, a, b, *, peer_advertises_v2=None):
589+
def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool = True):
590+
"""
591+
Kwargs:
592+
wait_for_connect: if True, block until the nodes are verified as connected. You might
593+
want to disable this when using -stopatheight with one of the connected nodes,
594+
since there will be a race between the actual connection and performing
595+
the assertions before one node shuts down.
596+
"""
590597
from_connection = self.nodes[a]
591598
to_connection = self.nodes[b]
592599
from_num_peers = 1 + len(from_connection.getpeerinfo())
@@ -603,6 +610,9 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None):
603610
# compatibility with older clients
604611
from_connection.addnode(ip_port, "onetry")
605612

613+
if not wait_for_connect:
614+
return
615+
606616
# poll until version handshake complete to avoid race conditions
607617
# with transaction relaying
608618
# See comments in net_processing:

0 commit comments

Comments
 (0)