migratewallet crashes (wallet/scriptpubkeyman.cpp:1915: std::optional wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO’ failed.) #28057

issue maflcko openend this issue on July 9, 2023
  1. maflcko commented at 10:34 am on July 9, 2023: member

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    crash

    Expected behaviour

    no crash

    Steps to reproduce

    • Compile 79e8247ddb166f9b980f40249b7372a502402a4d
    • Type migratewallet

    Relevant log output

    0wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
    1Aborted (core dumped)
    

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    current master

    Operating system and version

    Linux

    Machine specifications

    No response

  2. maflcko added the label Wallet on Jul 9, 2023
  3. maflcko commented at 10:39 am on July 9, 2023: member

    Now trying to start the program just fails on startup:

    0Error: Unrecognized descriptor found. Loading wallet ....../wallet.dat
    1
    2The wallet might had been created on a newer version.
    3Please try running the latest software version.
    
  4. furszy commented at 3:22 pm on July 9, 2023: member

    To recover from the error, use the wallet backup. Can find it inside the directory of the wallet that you are trying to migrate e.g. /wallets/wallet_name/wallet_name-<timestamp>.legacy.bak.

    The issue seems to be related to one of your imported scripts. Would be good to gather more information about the script type. So we can check under which circumstances the legacy spkm IsMine return false for a script contained by the wallet.

    If you can, try applying this patch and re-run the migration process:

     0diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
     1--- a/src/wallet/scriptpubkeyman.cpp	(revision 79e8247ddb166f9b980f40249b7372a502402a4d)
     2+++ b/src/wallet/scriptpubkeyman.cpp	(date 1688915136527)
     3@@ -1912,6 +1912,9 @@
     4         for (const CScript& desc_spk : desc_spks) {
     5             auto del_it = spks.find(desc_spk);
     6             assert(del_it != spks.end());
     7+            if (IsMine(desc_spk) != ISMINE_NO) {
     8+                assert(desc);
     9+                LogPrintf("%s: not mine script: %s\n", __func__, desc->ToString());
    10+            }
    11             assert(IsMine(desc_spk) != ISMINE_NO);
    12             it = spks.erase(del_it);
    13         }
    
  5. maflcko commented at 8:14 am on July 10, 2023: member

    I tried on 25.0, where it will just fill the storage at full speed in a never ending loop (aborted after 30 minutes)

    Untitled_w

  6. maflcko commented at 8:20 am on July 10, 2023: member

    The wallet version is 139900, not sure if relevant.

    02023-07-10T08:19:38Z [qt-rpcconsole] [wallet/scriptpubkeyman.cpp:1917] [MigrateToDescriptor] MigrateToDescriptor: not mine script: addr(mqRzyzrW7DPGT1KZN2mLuyGPVUugpfEVPW)#4ndsysze
    1bitcoin-qt: wallet/scriptpubkeyman.cpp:1919: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
    
  7. furszy commented at 2:31 pm on July 10, 2023: member

    Could you provide the getaddressinfo mqRzyzrW7DPGT1KZN2mLuyGPVUugpfEVPW output please.

    And also, do you have steps to reproduce it? how did you import that address?

  8. maflcko commented at 2:38 pm on July 10, 2023: member

    No idea where it is from. Apparently it is from a “test_2” :sweat_smile:

     0{
     1  "address": "mqRzyzrW7DPGT1KZN2mLuyGPVUugpfEVPW",
     2  "scriptPubKey": "76a9146cc16c24e249bab4384d4a759fe53ab23227de1988ac",
     3  "ismine": false,
     4  "solvable": false,
     5  "iswatchonly": true,
     6  "isscript": false,
     7  "iswitness": false,
     8  "ischange": false,
     9  "timestamp": 0,
    10  "labels": [
    11    "test_2"
    12  ]
    13}
    
  9. furszy commented at 3:06 pm on July 10, 2023: member

    Ok, found the Unrecognized descriptor found error cause. You might have imported a hex script (with the p2sh flag enabled) and the migration process translated into a sh(addr(mqRzyzrW7DPGT1KZN2mLuyGPVUugpfEVPW))#0ezg4j29 descriptor. Which isn’t a valid descriptor because the addr() func can only appear at the top level.

    The assertion cause is still unknown but hey, one bug less at least :). Fixing it..

  10. fanquake added this to the milestone 25.1 on Jul 12, 2023
  11. achow101 referenced this in commit 7edce77ff3 on Jul 20, 2023
  12. furszy commented at 4:11 pm on July 20, 2023: member
    @MarcoFalke, could you please try this again on master now?
  13. maflcko commented at 5:12 pm on July 20, 2023: member

    Sure:

     02023-07-20T16:40:23Z [main] [init/common.cpp:153] [LogPackageVersion] Bitcoin Core version v25.99.0-d23fda05842b (release build)
     1
     2
     32023-07-20T16:40:56Z [qt-rpcconsole] [wallet/wallet.h:895] [WalletLogPrintf] [default wallet] Migrating wallet storage database from BerkeleyDB to SQLite.
     4
     5
     6
     72023-07-20T17:10:25Z [scheduler] [net.cpp:1523] [DumpAddresses] [net] Flushed 0 addresses to peers.dat  56ms
     8
     9
    10bitcoin-qt: wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
    11Aborted (core dumped)
    
  14. furszy commented at 2:09 pm on July 22, 2023: member
    I got creative and broke some stuff. @MarcoFalke, please try #28125.
  15. achow101 referenced this in commit abe4fedab7 on Sep 19, 2023
  16. maflcko closed this on Sep 20, 2023

  17. Frank-GER referenced this in commit c851b748b2 on Sep 25, 2023
  18. sidhujag referenced this in commit acdd6fb31d on Sep 26, 2023
  19. bitcoin locked this on Sep 19, 2024


maflcko furszy

Labels
Wallet

Milestone
25.1


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-22 03:12 UTC

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