Allow -upgradewallet to upgradewallets to HD and use a keypool of presplit keys…

Authored by Andrew Chow <achow101-github@achow101.com> on Mar 31 2018, 17:37.


Allow -upgradewallet to upgradewallets to HD and use a keypool of presplit keys after upgrading to hd chain split

(commit #1)
Changes the maximum upgradewallet version to the latest wallet version
number, 190700. Non-HD wallets will be upgraded to use HD derivation.
Non HD chain split wallets will be upgraded to HD chain split.

(commit #2)
After upgrading to HD chain split, we want to continue to use keys
from the old keypool. To do this, before we generate any new keys after
upgrading, we mark all of the keypool entries as being pre-chain
split and move them to a separate pre chain split keypool. Keys are
fetched from that keypool until it is emptied. Only then are the new
internal and external keypools used.

Since upgradewallet is effectively run during a first run, all of the
first run initial setup stuff is combined with the upgrade to HD

Partial backport of Core PR12560 (3/4)

Depends on D4202

Test Plan:
Recommend to perform testing on regtest or else this process may take a very long time.

make check
./bitcoind -upgradewallet
./bitcoin-cli getwalletinfo > preupgradewalletinfo
./bitcoin-cli generate 1
Kill bitcoind
./bitcoind -printtoconsole -upgradewallet

bitcoind should output to console the two following lines:

Performing wallet upgrade to 190700
Upgrading wallet to use HD chain split

Compare previous preupgradewalletinfo with ./bitcoin-cli getwalletinfo post upgrade


  "walletname": "",
  "walletversion": 160300,
  "balance": 0.00000000,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 0.00000000,
  "txcount": 0,
  "keypoololdest": 1551725443,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 1000,
  "paytxfee": 0.00000000,
  "hdmasterkeyid": "c13ec93790a56f74edd2da42d231317eb6dbf02b"

post upgrade wallet info:

  "walletname": "",
  "walletversion": 190700,
  "balance": 0.00000000,
  "unconfirmed_balance": 0.00000000,
  "immature_balance": 50.00000000,
  "txcount": 1,
  "keypoololdest": 1551725443,
  "keypoolsize": 1000,
  "keypoolsize_hd_internal": 1000,
  "paytxfee": 0.00000000,
  "hdmasterkeyid": "c13ec93790a56f74edd2da42d231317eb6dbf02b"

The newly upgraded wallet should not be able to be downgraded to a previous version

Kill bitcoind
./bitcoind -upgradewallet=160300

This should fail and cause bitcoind to shutdown with the following line:

Error: Cannot downgrade wallet

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4206


nakihitoOct 7 2019, 18:02
nakihitoOct 7 2019, 23:08
Restricted Owners Package
Differential Revision
D4206: Allow -upgradewallet to upgradewallets to HD and use a keypool of presplit keys after upgrading to hd chain split
rSTAGINGfb43752bb641: Remove redundant assignments (dead stores)