wallet: fix crash during watch-only wallet migration #31374

pull furszy wants to merge 3 commits into bitcoin:master from furszy:2024_migration_watch-only_crash_fix changing 2 files +67 −3
  1. furszy commented at 4:41 pm on November 26, 2024: member

    The crash occurs because we assume the cached scripts structure will not be empty, but it can be empty for watch-only wallets that start blank.

    This also adds test coverage for standalone imported keys, which were also crashing because pubkey imports are treated the same way as hex script imports through importaddress().

    Testing Notes: This can be verified by cherry-picking and running any of the test commits on master. It will crash there but pass on this branch.

  2. wallet: fix crash during watch-only wallet migration
    The crash occurs because we assume the cached scripts
    structure will not be empty, but it can be empty for
    watch-only wallets that start blank.
    4a18a537ad
  3. DrahtBot commented at 4:41 pm on November 26, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31374.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Stale ACK brunoerg

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #30328 (wallet: Remove IsMine from migration code by achow101)

    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.

  4. DrahtBot added the label Wallet on Nov 26, 2024
  5. test: add coverage for migrating watch-only script ea9528fb96
  6. furszy force-pushed on Nov 26, 2024
  7. DrahtBot added the label CI failed on Nov 26, 2024
  8. DrahtBot commented at 4:46 pm on November 26, 2024: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/33553306813

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  9. DrahtBot removed the label CI failed on Nov 26, 2024
  10. in test/functional/wallet_migration.py:1076 in bdd42ed8de outdated
    1071+        expected_descs = [pk_desc, pkh_desc, sh_wpkh_desc, wpkh_desc]
    1072+
    1073+        migrated_desc = []
    1074+        for desc_info in wo_wallet.listdescriptors()['descriptors']:
    1075+            desc = desc_info['desc']
    1076+            if pubkey.hex() in desc:
    


    brunoerg commented at 1:51 pm on December 3, 2024:

    In bdd42ed8de8a92ae3e69e7b2dfceae7330f32676: I think it can be simplified. See:

     0diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py
     1index 928ab4acb4..06bc4e1fbb 100755
     2--- a/test/functional/wallet_migration.py
     3+++ b/test/functional/wallet_migration.py
     4@@ -1070,12 +1070,7 @@ class WalletMigrationTest(BitcoinTestFramework):
     5         wpkh_desc = descsum_create(f'wpkh({pubkey_hex})')
     6         expected_descs = [pk_desc, pkh_desc, sh_wpkh_desc, wpkh_desc]
     7 
     8-        migrated_desc = []
     9-        for desc_info in wo_wallet.listdescriptors()['descriptors']:
    10-            desc = desc_info['desc']
    11-            if pubkey.hex() in desc:
    12-                migrated_desc.append(desc)
    13-
    14+        migrated_desc = [item['desc'] for item in wo_wallet.listdescriptors()['descriptors']]
    15         # Verify all expected descriptors were migrated
    16         assert_equal(expected_descs, migrated_desc)
    17         wallet.unloadwallet()
    

    I don’t see why we need to check if pubkey is into the descriptors, we expect all of them to have it.


    furszy commented at 2:35 pm on December 3, 2024:

    I don’t see why we need to check if pubkey is into the descriptors, we expect all of them to have it.

    Thanks. I just blindly re-used the code I applied for the first check. Suggestion applied, and also inlined the first check too.

  11. brunoerg approved
  12. brunoerg commented at 2:05 pm on December 3, 2024: contributor

    ACK bdd42ed8de8a92ae3e69e7b2dfceae7330f32676

    I verified that wallet_migration test fails on master. Also, I ran the spkm_migration fuzz target (from #29694) for over 24 hours and did not got any crash.

  13. test: add coverage for migrating standalone imported keys 0d5bf47ff7
  14. furszy force-pushed on Dec 3, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-03 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me