Skip to content

Commit 4c40a92

Browse files
committed
Merge bitcoin#34728: test: Fix intermittent issue in wallet_assumeutxo.py
faa68ed test: Fix intermittent issue in wallet_assumeutxo.py (MarcoFalke) Pull request description: The test has many issues: * It fails intermittently, due to the use of `-stopatheight` (bitcoin#34710) * Using `-stopatheight` is expensive, because it requires two restarts, making the test slow * The overwritten `def setup_network` does not store the extra args via the `add_nodes` call, so if code is added in the future to restart a node, it may not pick up its global extra args. Fix all issues by: * Adding and using a fast `dumb_sync_blocks` util helper to achieve what `-stopatheight` doesn't achieve * Calling `self.add_nodes(self.num_nodes, self.extra_args)` in the overridden `setup_network` Can be tested via this diff: ```diff diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index ab0e5cc..49384c1 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -61,2 +61,3 @@ kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state if (m_stop_at_height && index.nHeight >= m_stop_at_height) { + LogInfo("Send shutdown signal after reaching stop height"); if (!m_shutdown_request()) { diff --git a/src/util/tokenpipe.cpp b/src/util/tokenpipe.cpp index c982fa6..a5565ebd36 100644 --- a/src/util/tokenpipe.cpp +++ b/src/util/tokenpipe.cpp @@ -4,2 +4,3 @@ #include <util/tokenpipe.h> +#include <util/time.h> @@ -60,2 +61,3 @@ int TokenPipeEnd::TokenRead() ssize_t result = read(m_fd, &token, 1); + UninterruptibleSleep(500ms); if (result < 0) { ``` On master: The test fails On this pull: The test passes Fixes bitcoin#34710 ACKs for top commit: kevkevinpal: ACK [faa68ed](bitcoin@faa68ed) achow101: ACK faa68ed w0xlt: ACK faa68ed Tree-SHA512: 6fcd52b6f6a5fa5a5e41e7b3cf5c733af62af9c60271e7d22c266aca90f2af67f91ffe80a3ed8b8d1a91d001700870f493207998bac988c4e3671a3a0dba7ba7
2 parents e09b816 + faa68ed commit 4c40a92

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

test/functional/test_framework/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,16 @@ def find_vout_for_address(node, txid, addr):
721721
raise RuntimeError("Vout not found for address: txid=%s, addr=%s" % (txid, addr))
722722

723723

724+
def dumb_sync_blocks(*, src, dst, height=None):
725+
"""Sync blocks between `src` and `dst` nodes via RPC submitblock up to height."""
726+
height = height or src.getblockcount()
727+
for i in range(dst.getblockcount() + 1, height + 1):
728+
block_hash = src.getblockhash(i)
729+
block = src.getblock(blockhash=block_hash, verbose=0)
730+
dst.submitblock(block)
731+
assert_equal(dst.getblockcount(), height)
732+
733+
724734
def sync_txindex(test_framework, node):
725735
test_framework.log.debug("Waiting for node txindex to sync")
726736
sync_start = int(time.time())

test/functional/wallet_assumeutxo.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from test_framework.util import (
1313
assert_equal,
1414
assert_greater_than,
15-
assert_greater_than_or_equal,
1615
assert_raises_rpc_error,
16+
dumb_sync_blocks,
1717
ensure_for,
1818
)
1919
from test_framework.wallet import MiniWallet
@@ -42,8 +42,8 @@ def set_test_params(self):
4242
def setup_network(self):
4343
"""Start with the nodes disconnected so that one can generate a snapshot
4444
including blocks the other hasn't yet seen."""
45-
self.add_nodes(4)
46-
self.start_nodes(extra_args=self.extra_args)
45+
self.add_nodes(self.num_nodes, self.extra_args)
46+
self.start_nodes()
4747

4848
def import_descriptor(self, node, wallet_name, key, timestamp):
4949
import_request = [{"desc": descsum_create("pkh(" + key.pubkey + ")"),
@@ -227,32 +227,18 @@ def loading_error(height):
227227

228228
PAUSE_HEIGHT = FINAL_HEIGHT - 40
229229

230-
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
231-
self.restart_node(1, extra_args=[
232-
f"-stopatheight={PAUSE_HEIGHT}", *self.extra_args[1]])
230+
self.log.info(f"Unload wallets and sync node up to height {PAUSE_HEIGHT}")
231+
n1.unloadwallet("w")
232+
n1.unloadwallet(wallet_name)
233+
dumb_sync_blocks(src=n0, dst=n1, height=PAUSE_HEIGHT)
233234

234-
# Finally connect the nodes and let them sync.
235-
#
236-
# Set `wait_for_connect=False` to avoid a race between performing connection
237-
# assertions and the -stopatheight tripping.
238-
self.connect_nodes(0, 1, wait_for_connect=False)
239-
240-
n1.wait_until_stopped(timeout=5)
241-
242-
self.log.info(
243-
"Restarted node before snapshot validation completed, reloading...")
244-
self.restart_node(1, extra_args=self.extra_args[1])
245-
246-
self.log.info("Verify node state after restart during background sync")
235+
self.log.info("Verify node state during background sync")
247236
# Verify there are still two chainstates (background validation not complete)
248237
chainstates = n1.getchainstates()['chainstates']
249238
assert_equal(len(chainstates), 2)
250239
# The background chainstate should still be at START_HEIGHT
251240
assert_equal(chainstates[0]['blocks'], START_HEIGHT)
252-
# The snapshot chainstate should be at least PAUSE_HEIGHT. It may be
253-
# higher because stopatheight may allow additional blocks to be
254-
# processed during shutdown (per stopatheight documentation).
255-
assert_greater_than_or_equal(chainstates[1]['blocks'], PAUSE_HEIGHT)
241+
assert_equal(chainstates[1]["blocks"], PAUSE_HEIGHT)
256242

257243
# After restart, wallets that existed before cannot be loaded because
258244
# the wallet loading code checks if required blocks are available for

0 commit comments

Comments
 (0)