Previously the seed was stored with keypath 'm' so we need to skip this as well when determining inactive seeds.
Fixes #19051
Are there steps to test for people that are not me? Or, alternatively, is it possible to write a test for this?
I think this can be tested in feature_backwards_compatibility.py. I'll see if I can write a test.
Otherwise we would need to directly modify the wallet.dat file.
0.16 uses the old 'm' for the hd seed, so I've updated feature_backwards_compatibility.py to do an up/downgrade test with a 0.16 wallet. This test also checks that there is no warning when loading the wallet. It catches this error.
443 | @@ -444,7 +444,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, 444 | // Not applicable when path is "s" as that indicates a seed 445 | bool internal = false; 446 | uint32_t index = 0; 447 | - if (keyMeta.hdKeypath != "s") { 448 | + if (keyMeta.hdKeypath != "s" && keyMeta.hdKeypath != "m") {
In commit "Skip hdKeypath of 'm'" (57acd1b27fb6cf46b919a05e3fe50a1c2947321f)
Would be good to update "Not applicable when..." comment above
Done
339 | @@ -331,6 +340,29 @@ def run_test(self): 340 | hdkeypath = v17_info["hdkeypath"] 341 | pubkey = v17_info["pubkey"] 342 | 343 | + # Copy the 0.16 wallet to the last Bitcoin Core version and open it:
In commit "tests: feature_backwards_compatibility.py test 0.16 up/downgrade" (7a872702965755ce28f1f17a8d0e0eb93ae4c907)
Implemention seems ideal for this PR, but for future cleanup it could be nice for someone to write some python helper functions and get rid of duplicate code in the 0.16, 0.17, and 0.19 test cases.
Code review ACK 7a872702965755ce28f1f17a8d0e0eb93ae4c907. Simple bugfix, and it's nice how the new 0.16 test can potentially catch not just this bug, but other similar bugs from loading these wallets.
Does this mean that older hd wallets opened prior to this fix have been corrupted?
Also, post-fix does this mean that the #17681 functionality (following old hd chains forward) will silently not work for these wallets (since their hd keys just get skipped)?
Does this mean that older hd wallets opened prior to this fix have been corrupted?
Also, post-fix does this mean that the #17681 functionality (following old hd chains forward) will silently not work for these wallets (since their hd keys just get skipped)?
No to both. #17681 functionality works regardless of this fix, regardless of age of the HD wallet. This fix is to merely remove an erroneous warning for those older HD wallets.
This fix does not skip any HD keys at all. It just skips the keymeta record for the HD seed when it is computing the inactive HD chain from those keymetadata records. The record for the HD seed is not used in that process, hence this patch to skip it.
440 | @@ -441,10 +441,10 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, 441 | // Extract some CHDChain info from this metadata if it has any 442 | if (keyMeta.nVersion >= CKeyMetadata::VERSION_WITH_HDDATA && !keyMeta.hd_seed_id.IsNull() && keyMeta.hdKeypath.size() > 0) { 443 | // Get the path from the key origin or from the path string 444 | - // Not applicable when path is "s" as that indicates a seed 445 | + // Not applicable when path is "s" or "m" as those indicates a seed
nit: "indicate"
Let's point to https://github.com/bitcoin/bitcoin/commit/c75c351419dac3dfe9578604ea5b2f7599452b4a#diff-b2bb174788c7409b671c46ccc86034bdL1470 here or in the functional test.
Fixed typo. Added a reference to the PR.
321 | @@ -322,6 +322,15 @@ def run_test(self): 322 | info = wallet.getwalletinfo() 323 | assert info['keypoolsize'] == 1 324 | 325 | + # Create upgrade wallet in v0.16 326 | + self.stop_node(5)
Use -1 instead. Maybe cherry-pick 99d9f7cf7b7460c976d6ca7508e77b4ee31bf576
Done
344 | + shutil.copyfile( 345 | + os.path.join(node_v16_wallets_dir, "wallets/u1_v16"), 346 | + os.path.join(node_master_wallets_dir, "u1_v16") 347 | + ) 348 | + load_res = node_master.loadwallet("u1_v16") 349 | + assert_equal(load_res['warning'], '')
nit: refer to this PR in a comment
Done
Concept ACK. When I run the new test without 5fb09ed it catches a warning.
For future reference, the change from ~"s" to "m"~ "m" to "s" was introduced in #12924 (cc @jnewbery, @jonasschnelli). At the time this change wasn't a problem, because the data was serialised, but afaik not used anywhere.
Previously the seed was stored with keypath 'm' so we need to skip this
as well when determining inactive seeds.
ACK 951bca61d7376be44fad0775e8abb06ff667e4bf
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Code review ACK 951bca61d7376be44fad0775e8abb06ff667e4bf. No significant changes since last review, just updated comment and some test tweaks