Skip to content

Commit 9600f9c

Browse files
meshcolliderknst
authored andcommitted
Merge bitcoin#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@a66a7a1) jonatack: ACK a66a7a1 meshcollider: Code review ACK a66a7a1 Tree-SHA512: 3df746421a008708eaa3bbbdd12b9ddd3e2ec111d54625a212dca7414b971cc1f6e2b1757b3232c31a2f637d1b1ef43bf3ffa4ac4216646cf1e92db5f79954f1
1 parent a1e3885 commit 9600f9c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/wallet/walletdb.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
605605
ssValue >> ser_xpub;
606606
CExtPubKey xpub;
607607
xpub.Decode(ser_xpub.data());
608-
if (wss.m_descriptor_caches.count(desc_id)) {
609-
wss.m_descriptor_caches[desc_id] = DescriptorCache();
610-
}
611608
if (parent) {
612609
wss.m_descriptor_caches[desc_id].CacheParentExtPubKey(key_exp_index, xpub);
613610
} else {

test/functional/wallet_importdescriptors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ def run_test(self):
9898
labels=["Descriptor import test"])
9999
assert_equal(w1.getwalletinfo()['keypoolsize'], 0)
100100

101+
# Check persistence of data and that loading works correctly
102+
w1.unloadwallet()
103+
self.nodes[1].loadwallet('w1')
104+
test_address(w1,
105+
key.p2pkh_addr,
106+
solvable=True,
107+
ismine=True,
108+
labels=["Descriptor import test"])
109+
101110
self.log.info("Internal addresses cannot have labels")
102111
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + ")"),
103112
"timestamp": "now",
@@ -365,6 +374,10 @@ def run_test(self):
365374
self.sync_all()
366375
assert_equal(wmulti_pub.getbalance(), wmulti_priv.getbalance())
367376

377+
# Make sure that descriptor wallets containing multiple xpubs in a single descriptor load correctly
378+
wmulti_pub.unloadwallet()
379+
self.nodes[1].loadwallet('wmulti_pub')
380+
368381
self.log.info("Multisig with distributed keys")
369382
self.nodes[1].createwallet(wallet_name="wmulti_priv1", descriptors=True)
370383
wmulti_priv1 = self.nodes[1].get_wallet_rpc("wmulti_priv1")

0 commit comments

Comments
 (0)