`-upgradewallet` from pre-HD Split not working as expected #16193

issue instagibbs opened this issue on June 12, 2019
  1. instagibbs commented at 1:08 PM on June 12, 2019: member

    I expected the internal keypool to be filled, and for change addresses to immediately be drawn from that pool. Looking for replication/explanation in case I missed something. Just tested this on master.

    1. Create wallet using 0.14.3(or anything pre-split, maybe?)
    2. Stop
    3. Load wallet using master with -upgradewallet
    4. Query wallet for details
    getwalletinfo
    {
      "walletname": "test.dat",
      "walletversion": 169900,
      "balance": 0.00000000,
      "unconfirmed_balance": 0.00000000,
      "immature_balance": 0.00000000,
      "txcount": 0,
      "keypoololdest": 1560344352,
      "keypoolsize": 2000,
      "keypoolsize_hd_internal": 0,
      "paytxfee": 0.00000000,
      "hdseedid": "a9e2788e2871531d9b54b1fc85ff822dffcc2707",
      "private_keys_enabled": true,
      "scanning": false
    }
    

    As you can see, there are 2000 keys now, and knowledge that internal exists, but it's empty. I ask for a change key:

    getrawchangeaddress
    2N1ZX1ZLgRABqcec4XDVMJmMFRNqnJZBfpA
    

    which I save for later, and check keypools again:

    getwalletinfo
    {
      "walletname": "test.dat",
      "walletversion": 169900,
      "balance": 0.00000000,
      "unconfirmed_balance": 0.00000000,
      "immature_balance": 0.00000000,
      "txcount": 0,
      "keypoololdest": 1560344352,
      "keypoolsize": 1999,
      "keypoolsize_hd_internal": 1,
      "paytxfee": 0.00000000,
      "hdseedid": "a9e2788e2871531d9b54b1fc85ff822dffcc2707",
      "private_keys_enabled": true,
      "scanning": false
    }
    

    The internal keypool grew by one, and external shrunk by 1.

    getaddressinfo 2N1ZX1ZLgRABqcec4XDVMJmMFRNqnJZBfpA
    {
      "address": "2N1ZX1ZLgRABqcec4XDVMJmMFRNqnJZBfpA",
      "scriptPubKey": "a9145b36b3eb5ae046fcaae77a25d6cd93155f33c9ba87",
      "ismine": true,
      "solvable": true,
      "desc": "sh(wpkh([510ad933/0'/0'/1']022a1576b06ca44fbfd3956afe0b5a4933fbeda8a66c308de8074b7b186fa5b4b8))#936fhdgy",
      "iswatchonly": false,
      "isscript": true,
      "iswitness": false,
      "script": "witness_v0_keyhash",
      "hex": "001458aed9491c976d7bce0d0323ff8d1bc139a338bb",
      "pubkey": "022a1576b06ca44fbfd3956afe0b5a4933fbeda8a66c308de8074b7b186fa5b4b8",
      "embedded": {
        "isscript": false,
        "iswitness": true,
        "witness_version": 0,
        "witness_program": "58aed9491c976d7bce0d0323ff8d1bc139a338bb",
        "pubkey": "022a1576b06ca44fbfd3956afe0b5a4933fbeda8a66c308de8074b7b186fa5b4b8",
        "address": "bcrt1qtzhdjjgujakhhnsdqv3llrgmcyu6xw9mvwxxwh",
        "scriptPubKey": "001458aed9491c976d7bce0d0323ff8d1bc139a338bb"
      },
      "ischange": true,
      "timestamp": 1560344273,
      "hdkeypath": "m/0'/0'/1'",
      "hdseedid": "a9e2788e2871531d9b54b1fc85ff822dffcc2707",
      "hdmasterfingerprint": "510ad933",
      "labels": [
      ]
    }
    

    That returned key appears to be an external key based on keypath, though it is marked as ischange.

    Grabbing more keys seems to continue this pattern:

    getwalletinfo
    {
      "walletname": "test.dat",
      "walletversion": 169900,
      "balance": 0.00000000,
      "unconfirmed_balance": 0.00000000,
      "immature_balance": 0.00000000,
      "txcount": 0,
      "keypoololdest": 1560344352,
      "keypoolsize": 1998,
      "keypoolsize_hd_internal": 2,
      "paytxfee": 0.00000000,
      "hdseedid": "a9e2788e2871531d9b54b1fc85ff822dffcc2707",
      "private_keys_enabled": true,
      "scanning": false
    }
    
  2. instagibbs renamed this:
    `-upgradwallet` from pre-HD Split not working
    `-upgradewallet` from pre-HD Split not working
    on Jun 12, 2019
  3. instagibbs renamed this:
    `-upgradewallet` from pre-HD Split not working
    `-upgradewallet` from pre-HD Split not working as expected
    on Jun 12, 2019
  4. instagibbs commented at 1:31 PM on June 12, 2019: member

    Hmm, after digging, it looks like it intentionally uses the pre-split pool first before returning internal keypool keys. Non-obvious. A test case demonstrating this behavior would be helpful.

  5. MarcoFalke commented at 2:41 PM on June 12, 2019: member

    Is this related to any of these?

    • ischange / listsinceblock/listtransactions bug #16160
  6. instagibbs commented at 2:59 PM on June 12, 2019: member

    I think those versions listed are all post-split, is ischange is detected purely based on lack of address stored in wallet, not due to where it came from in keypool or hd derivation.

  7. achow101 commented at 3:08 PM on June 12, 2019: member

    This is intended behavior. The pre-split keypool needs to be consumed before hd keys are derived.

    As for a test case, we can only do that once we get old wallet versions in the test suite.

  8. instagibbs commented at 3:24 PM on June 12, 2019: member

    What's the blocker on that?

  9. instagibbs commented at 1:23 PM on June 13, 2019: member

    I read some background on what it would take. Closing this for now, but I'd really like a comment-based explanation of this logic. It really makes little sense to me.

  10. instagibbs closed this on Jun 13, 2019

  11. darosior commented at 1:59 PM on July 7, 2019: member

    Maybe related #16091

  12. MarcoFalke locked this on Dec 16, 2021

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: 2026-04-13 21:14 UTC

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