Skip to content

Commit d4f9ae0

Browse files
author
MarcoFalke
committed
Merge #19054: wallet: Skip hdKeypath of 'm' when determining inactive hd seeds
951bca6 tests: feature_backwards_compatibility.py test 0.16 up/downgrade (Andrew Chow) 3a03a11 Skip hdKeypath of 'm' (Andrew Chow) Pull request description: Previously the seed was stored with keypath 'm' so we need to skip this as well when determining inactive seeds. Fixes #19051 ACKs for top commit: Sjors: ACK 951bca6 instagibbs: re-utACK bitcoin/bitcoin@951bca6 ryanofsky: Code review ACK 951bca6. No significant changes since last review, just updated comment and some test tweaks Tree-SHA512: 930f77e7097c9cf4f1012e540bd2b1a72fd279262517f10c1531b2ad48c632ef95e0dd4edea81bcc3b3db306479d34e5e79e5d6c4ed31dfa4b77a4231436436e
2 parents f3d776b + 951bca6 commit d4f9ae0

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/wallet/walletdb.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
439439
// Extract some CHDChain info from this metadata if it has any
440440
if (keyMeta.nVersion >= CKeyMetadata::VERSION_WITH_HDDATA && !keyMeta.hd_seed_id.IsNull() && keyMeta.hdKeypath.size() > 0) {
441441
// Get the path from the key origin or from the path string
442-
// Not applicable when path is "s" as that indicates a seed
442+
// Not applicable when path is "s" or "m" as those indicate a seed
443+
// See https://github.com/bitcoin/bitcoin/pull/12924
443444
bool internal = false;
444445
uint32_t index = 0;
445-
if (keyMeta.hdKeypath != "s") {
446+
if (keyMeta.hdKeypath != "s" && keyMeta.hdKeypath != "m") {
446447
std::vector<uint32_t> path;
447448
if (keyMeta.has_key_origin) {
448449
// We have a key origin, so pull it from its path vector

test/functional/feature_backwards_compatibility.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ def run_test(self):
319319
info = wallet.getwalletinfo()
320320
assert info['keypoolsize'] == 1
321321

322+
# Create upgrade wallet in v0.16
323+
self.stop_node(-1)
324+
self.start_node(-1, extra_args=["-wallet=u1_v16"])
325+
wallet = node_v16.get_wallet_rpc("u1_v16")
326+
v16_addr = wallet.getnewaddress('', "bech32")
327+
v16_info = wallet.validateaddress(v16_addr)
328+
v16_pubkey = v16_info['pubkey']
329+
self.stop_node(-1)
330+
322331
self.log.info("Test wallet upgrade path...")
323332
# u1: regular wallet, created with v0.17
324333
node_v17.rpc.createwallet(wallet_name="u1_v17")
@@ -328,6 +337,30 @@ def run_test(self):
328337
hdkeypath = v17_info["hdkeypath"]
329338
pubkey = v17_info["pubkey"]
330339

340+
# Copy the 0.16 wallet to the last Bitcoin Core version and open it:
341+
shutil.copyfile(
342+
os.path.join(node_v16_wallets_dir, "wallets/u1_v16"),
343+
os.path.join(node_master_wallets_dir, "u1_v16")
344+
)
345+
load_res = node_master.loadwallet("u1_v16")
346+
# Make sure this wallet opens without warnings. See https://github.com/bitcoin/bitcoin/pull/19054
347+
assert_equal(load_res['warning'], '')
348+
wallet = node_master.get_wallet_rpc("u1_v16")
349+
info = wallet.getaddressinfo(v16_addr)
350+
descriptor = "wpkh([" + info["hdmasterfingerprint"] + hdkeypath[1:] + "]" + v16_pubkey + ")"
351+
assert_equal(info["desc"], descsum_create(descriptor))
352+
353+
# Now copy that same wallet back to 0.16 to make sure no automatic upgrade breaks it
354+
os.remove(os.path.join(node_v16_wallets_dir, "wallets/u1_v16"))
355+
shutil.copyfile(
356+
os.path.join(node_master_wallets_dir, "u1_v16"),
357+
os.path.join(node_v16_wallets_dir, "wallets/u1_v16")
358+
)
359+
self.start_node(-1, extra_args=["-wallet=u1_v16"])
360+
wallet = node_v16.get_wallet_rpc("u1_v16")
361+
info = wallet.validateaddress(v16_addr)
362+
assert_equal(info, v16_info)
363+
331364
# Copy the 0.17 wallet to the last Bitcoin Core version and open it:
332365
node_v17.unloadwallet("u1_v17")
333366
shutil.copytree(

0 commit comments

Comments
 (0)