Skip to content

Commit ceb943d

Browse files
Eunovorkrux
andcommitted
test/wallet: ensure FastWalletRescanFilter is updated during scanning
The fixed non-range descriptor address ensured that the FastWalletRescanFilter would match all Blocks even if the filter wasn't properly updated. This commit moves the non-range descriptor tx to a different block, so that the filters must be updated after each TopUp for the test to pass. Co-authored-by: rkrux <rkrux.connect@gmail.com>
1 parent 4035231 commit ceb943d

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

test/functional/wallet_fast_rescan.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
KEYPOOL_SIZE = 100 # smaller than default size to speed-up test
17-
NUM_DESCRIPTORS = 9 # number of descriptors (8 default ranged ones + 1 fixed non-ranged one)
1817
NUM_BLOCKS = 6 # number of blocks to mine
1918

2019

@@ -33,41 +32,51 @@ def get_wallet_txids(self, node: TestNode, wallet_name: str) -> list[str]:
3332

3433
def run_test(self):
3534
node = self.nodes[0]
36-
wallet = MiniWallet(node)
35+
funding_wallet = MiniWallet(node)
3736

3837
self.log.info("Create descriptor wallet with backup")
3938
WALLET_BACKUP_FILENAME = node.datadir_path / 'wallet.bak'
4039
node.createwallet(wallet_name='topup_test')
4140
w = node.get_wallet_rpc('topup_test')
4241
fixed_key = get_generate_key()
43-
print(w.importdescriptors([{"desc": descsum_create(f"wpkh({fixed_key.privkey})"), "timestamp": "now"}]))
42+
w.importdescriptors([{"desc": descsum_create(f"wpkh({fixed_key.privkey})"), "timestamp": "now"}])
4443
descriptors = w.listdescriptors()['descriptors']
45-
assert_equal(len(descriptors), NUM_DESCRIPTORS)
4644
w.backupwallet(WALLET_BACKUP_FILENAME)
4745

46+
num_txs = 0
47+
48+
self.log.info("Create tx sending to non-ranged descriptors")
49+
self.log.info(f"Block 1/{NUM_BLOCKS}")
50+
spk = bytes.fromhex(fixed_key.p2wpkh_script)
51+
self.log.info(f"-> fixed non-range descriptor address {fixed_key.p2wpkh_addr}")
52+
funding_wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
53+
num_txs += 1
54+
self.generate(node, 1)
55+
4856
self.log.info("Create txs sending to end range address of each descriptor, triggering top-ups")
49-
for i in range(NUM_BLOCKS):
57+
fast_rescan_messages = []
58+
for i in range(1, NUM_BLOCKS):
5059
self.log.info(f"Block {i+1}/{NUM_BLOCKS}")
51-
for desc_info in w.listdescriptors()['descriptors']:
52-
if 'range' in desc_info:
53-
start_range, end_range = desc_info['range']
54-
addr = w.deriveaddresses(desc_info['desc'], [end_range, end_range])[0]
55-
spk = address_to_scriptpubkey(addr)
56-
self.log.info(f"-> range [{start_range},{end_range}], last address {addr}")
57-
else:
58-
spk = bytes.fromhex(fixed_key.p2wpkh_script)
59-
self.log.info(f"-> fixed non-range descriptor address {fixed_key.p2wpkh_addr}")
60-
wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
60+
ranged_descs = [desc for desc in descriptors if 'range' in desc]
61+
for desc_info in ranged_descs:
62+
start_range, end_range = desc_info['range']
63+
addr = w.deriveaddresses(desc_info['desc'], [end_range, end_range])[0]
64+
spk = address_to_scriptpubkey(addr)
65+
self.log.info(f"-> range [{start_range},{end_range}], last address {addr}")
66+
funding_wallet.send_to(from_node=node, scriptPubKey=spk, amount=10000)
67+
num_txs += 1
6168
self.generate(node, 1)
69+
chain_info = self.nodes[0].getblockchaininfo()
70+
fast_rescan_messages.append(f"Fast rescan: inspect block {chain_info['blocks']} [{chain_info['bestblockhash']}] (filter matched)")
6271

6372
self.log.info("Import wallet backup with block filter index")
64-
with node.assert_debug_log(['fast variant using block filters']):
73+
with node.assert_debug_log(['fast variant using block filters', *fast_rescan_messages]):
6574
node.restorewallet('rescan_fast', WALLET_BACKUP_FILENAME)
6675
txids_fast = self.get_wallet_txids(node, 'rescan_fast')
6776

6877
self.log.info("Import non-active descriptors with block filter index")
6978
node.createwallet(wallet_name='rescan_fast_nonactive', disable_private_keys=True, blank=True)
70-
with node.assert_debug_log(['fast variant using block filters']):
79+
with node.assert_debug_log(['fast variant using block filters', *fast_rescan_messages]):
7180
w = node.get_wallet_rpc('rescan_fast_nonactive')
7281
w.importdescriptors([{"desc": descriptor['desc'], "timestamp": 0} for descriptor in descriptors])
7382
txids_fast_nonactive = self.get_wallet_txids(node, 'rescan_fast_nonactive')
@@ -86,10 +95,10 @@ def run_test(self):
8695
txids_slow_nonactive = self.get_wallet_txids(node, 'rescan_slow_nonactive')
8796

8897
self.log.info("Verify that all rescans found the same txs in slow and fast variants")
89-
assert_equal(len(txids_slow), NUM_DESCRIPTORS * NUM_BLOCKS)
90-
assert_equal(len(txids_fast), NUM_DESCRIPTORS * NUM_BLOCKS)
91-
assert_equal(len(txids_slow_nonactive), NUM_DESCRIPTORS * NUM_BLOCKS)
92-
assert_equal(len(txids_fast_nonactive), NUM_DESCRIPTORS * NUM_BLOCKS)
98+
assert_equal(len(txids_slow), num_txs)
99+
assert_equal(len(txids_fast), num_txs)
100+
assert_equal(len(txids_slow_nonactive), num_txs)
101+
assert_equal(len(txids_fast_nonactive), num_txs)
93102
assert_equal(sorted(txids_slow), sorted(txids_fast))
94103
assert_equal(sorted(txids_slow_nonactive), sorted(txids_fast_nonactive))
95104

0 commit comments

Comments
 (0)