Skip to content

Commit 663fd92

Browse files
committed
Merge #20266: wallet: fix change detection of imported internal descriptors
bd93fc9 Fix change detection of imported internal descriptors (Andrew Chow) Pull request description: Import internal descriptors were having address book entries added which meant they would be detected as non-change. Fix this and add a test for it. ACKs for top commit: laanwj: Code review ACK bd93fc9 meshcollider: utACK bd93fc9 promag: Code review ACK bd93fc9. Tree-SHA512: 8fa9e364be317627ec171eedffdb505976c0e7f1e55bc7e8cfdffa3aeea5db24d231f55166602cd0e97a5ba621acc871de0a765c75d0c65678f83e93c3b657c5
2 parents f70eb51 + bd93fc9 commit 663fd92

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
15591559
}
15601560

15611561
// Add descriptor to the wallet
1562-
auto spk_manager = pwallet->AddWalletDescriptor(w_desc, keys, label);
1562+
auto spk_manager = pwallet->AddWalletDescriptor(w_desc, keys, label, internal);
15631563
if (spk_manager == nullptr) {
15641564
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Could not add descriptor '%s'", descriptor));
15651565
}

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,7 +4511,7 @@ DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDes
45114511
return nullptr;
45124512
}
45134513

4514-
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label)
4514+
ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal)
45154515
{
45164516
if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
45174517
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n");
@@ -4568,7 +4568,7 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
45684568
}
45694569

45704570
CTxDestination dest;
4571-
if (ExtractDestination(script_pub_keys.at(0), dest)) {
4571+
if (!internal && ExtractDestination(script_pub_keys.at(0), dest)) {
45724572
SetAddressBook(dest, label, "receive");
45734573
}
45744574
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
12801280
DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
12811281

12821282
//! Add a descriptor to the wallet, return a ScriptPubKeyMan & associated output type
1283-
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label);
1283+
ScriptPubKeyMan* AddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const std::string& label, bool internal);
12841284
};
12851285

12861286
/**

test/functional/wallet_importdescriptors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- `test_address()` is called to call getaddressinfo for an address on node1
1616
and test the values returned."""
1717

18+
from test_framework.address import key_to_p2pkh
1819
from test_framework.test_framework import BitcoinTestFramework
1920
from test_framework.descriptors import descsum_create
2021
from test_framework.util import (
@@ -107,6 +108,17 @@ def run_test(self):
107108
error_code=-8,
108109
error_message="Internal addresses should not have a label")
109110

111+
self.log.info("Internal addresses should be detected as such")
112+
key = get_generate_key()
113+
addr = key_to_p2pkh(key.pubkey)
114+
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + ")"),
115+
"timestamp": "now",
116+
"internal": True},
117+
success=True)
118+
info = w1.getaddressinfo(addr)
119+
assert_equal(info["ismine"], True)
120+
assert_equal(info["ischange"], True)
121+
110122
# # Test importing of a P2SH-P2WPKH descriptor
111123
key = get_generate_key()
112124
self.log.info("Should not import a p2sh-p2wpkh descriptor without checksum")

0 commit comments

Comments
 (0)