While it seems fine to mine the transaction related to the non-ranged descriptor in a separate block, I think it’d be thorough to mine a block with transaction(s) unrelated to the wallet at all so that the fast rescan doesn’t fetch it, which can be asserted for in the debug log. Consider the following diff:
0diff --git a/test/functional/wallet_fast_rescan.py b/test/functional/wallet_fast_rescan.py
1index a917a9db32..93078386df 100755
2--- a/test/functional/wallet_fast_rescan.py
3+++ b/test/functional/wallet_fast_rescan.py
4@@ -14,7 +15,7 @@ from test_framework.wallet_util import get_generate_key
5
6
7 KEYPOOL_SIZE = 100 # smaller than default size to speed-up test
8-NUM_BLOCKS = 6 # number of blocks to mine
9+NUM_BLOCKS = 7 # number of blocks to mine
10
11
12 class WalletFastRescanTest(BitcoinTestFramework):
13@@ -32,7 +33,7 @@ class WalletFastRescanTest(BitcoinTestFramework):
14
15 def run_test(self):
16 node = self.nodes[0]
17- wallet = MiniWallet(node)
18+ funding_wallet = MiniWallet(node)
19
20 self.log.info("Create descriptor wallet with backup")
21 WALLET_BACKUP_FILENAME = node.datadir_path / 'wallet.bak'
22@@ -45,7 +46,8 @@ class WalletFastRescanTest(BitcoinTestFramework):
23
24 self.log.info("Create txs sending to end range address of each descriptor, triggering top-ups")
25 num_txs = 0
26- for i in range(NUM_BLOCKS-1):
27+ fast_rescan_messages = []
28+ for i in range(NUM_BLOCKS-2):
29 self.log.info(f"Block {i+1}/{NUM_BLOCKS}")
30 for desc_info in w.listdescriptors()['descriptors']:
31 if 'range' in desc_info:
32@@ -53,28 +55,39 @@ class WalletFastRescanTest(BitcoinTestFramework):
33 addr = w.deriveaddresses(desc_info['desc'], [end_range, end_range])[0]
34 spk = address_to_scriptpubkey(addr)
35 self.log.info(f"-> range [{start_range},{end_range}], last address {addr}")
36- wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
37+ funding_wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
38 num_txs += 1
39 self.generate(node, 1)
40+ chain_info = self.nodes[0].getblockchaininfo()
41+ fast_rescan_messages.append(f"Fast rescan: inspect block {chain_info['blocks']} [{chain_info['bestblockhash']}] (filter matched)")
42
43 self.log.info("Create txs sending to non-ranged descriptors")
44- self.log.info(f"Block {NUM_BLOCKS}/{NUM_BLOCKS}")
45+ self.log.info(f"Block {NUM_BLOCKS-1}/{NUM_BLOCKS}")
46 for desc_info in w.listdescriptors()['descriptors']:
47 if 'range' not in desc_info:
48 spk = bytes.fromhex(fixed_key.p2wpkh_script)
49 self.log.info(f"-> fixed non-range descriptor address {fixed_key.p2wpkh_addr}")
50- wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
51+ funding_wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
52 num_txs += 1
53 self.generate(node, 1)
54+ chain_info = self.nodes[0].getblockchaininfo()
55+ fast_rescan_messages.append(f"Fast rescan: inspect block {chain_info['blocks']} [{chain_info['bestblockhash']}] (filter matched)")
56+
57+ self.log.info("Create tx unrelated to the wallet under consideration")
58+ self.log.info(f"Block {NUM_BLOCKS}/{NUM_BLOCKS}")
59+ funding_wallet.send_self_transfer(from_node=node)
60+ self.generate(node, 1)
61
62 self.log.info("Import wallet backup with block filter index")
63- with node.assert_debug_log(['fast variant using block filters']):
64+ with node.assert_debug_log(['fast variant using block filters', *fast_rescan_messages]):
65 node.restorewallet('rescan_fast', WALLET_BACKUP_FILENAME)
66 txids_fast = self.get_wallet_txids(node, 'rescan_fast')
67
68 self.log.info("Import non-active descriptors with block filter index")
69 node.createwallet(wallet_name='rescan_fast_nonactive', disable_private_keys=True, blank=True)
70- with node.assert_debug_log(['fast variant using block filters']):
71+ with node.assert_debug_log(['fast variant using block filters', *fast_rescan_messages]):
72 w = node.get_wallet_rpc('rescan_fast_nonactive')
73 w.importdescriptors([{"desc": descriptor['desc'], "timestamp": 0} for descriptor in descriptors])
74 txids_fast_nonactive = self.get_wallet_txids(node, 'rescan_fast_nonactive')