Skip to content

Commit 160800a

Browse files
committed
Merge #19441: walletdb: don't reinitialize desc cache with multiple cache entries
a66a7a1 walletdb: don't reinitialize desc cache with multiple cache entries (Andrew Chow) Pull request description: When loading descriptor caches, we would accidentally reinitialize the descriptor cache when seeing that one already exists. This should have only been initializing the cache when one does not exist. However this code itself is unnecessary as the act of looking up the cache to add to it will initialize it if it didn't already exist. This issue could be hit by trying to load a wallet that had imported a multisig descriptor. The wallet would fail to load. A test has been added to wallet_importdescriptors.py to catch this case. Another test case has also been added to check that loading a wallet with only single key descriptors works. ACKs for top commit: hugohn: tACK [a66a7a1](bitcoin/bitcoin@a66a7a1) jonatack: ACK a66a7a1 meshcollider: Code review ACK a66a7a1 Tree-SHA512: 3df746421a008708eaa3bbbdd12b9ddd3e2ec111d54625a212dca7414b971cc1f6e2b1757b3232c31a2f637d1b1ef43bf3ffa4ac4216646cf1e92db5f79954f1
2 parents 5f96bce + a66a7a1 commit 160800a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/wallet/walletdb.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
592592
ssValue >> ser_xpub;
593593
CExtPubKey xpub;
594594
xpub.Decode(ser_xpub.data());
595-
if (wss.m_descriptor_caches.count(desc_id)) {
596-
wss.m_descriptor_caches[desc_id] = DescriptorCache();
597-
}
598595
if (parent) {
599596
wss.m_descriptor_caches[desc_id].CacheParentExtPubKey(key_exp_index, xpub);
600597
} else {

test/functional/wallet_importdescriptors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ def run_test(self):
141141
success=True)
142142
assert_equal(w1.getwalletinfo()['keypoolsize'], 0)
143143

144+
test_address(w1,
145+
key.p2sh_p2wpkh_addr,
146+
ismine=True,
147+
solvable=True)
148+
149+
# Check persistence of data and that loading works correctly
150+
w1.unloadwallet()
151+
self.nodes[1].loadwallet('w1')
144152
test_address(w1,
145153
key.p2sh_p2wpkh_addr,
146154
ismine=True,
@@ -370,6 +378,10 @@ def run_test(self):
370378
self.sync_all()
371379
assert_equal(wmulti_pub.getbalance(), wmulti_priv.getbalance())
372380

381+
# Make sure that descriptor wallets containing multiple xpubs in a single descriptor load correctly
382+
wmulti_pub.unloadwallet()
383+
self.nodes[1].loadwallet('wmulti_pub')
384+
373385
self.log.info("Multisig with distributed keys")
374386
self.nodes[1].createwallet(wallet_name="wmulti_priv1", descriptors=True)
375387
wmulti_priv1 = self.nodes[1].get_wallet_rpc("wmulti_priv1")

0 commit comments

Comments
 (0)