Browse Source

Merge #11250: Bump wallet version to 159900 and remove the `usehd` option

713a92073 Remove usehd option and warn when it is used (Andrew Chow)
d4c18f733 Bump wallet version number to 159900 (Andrew Chow)

Pull request description:

  Bump the wallet version number to 159900 so that new wallets made without a default key will no longer work on previous versions at all. Also remove the `usehd` option to avoid weird interaction with wallet version numbers and HD-ness of wallets.

Tree-SHA512: dd7965505bfad6a926c79afd423236f509229a398a8398076f8d57d90a5974243f9459a61225c4daee560c796f427445c9e55a3ad528a3a97a9123ca6a1269ab
0.16
Wladimir J. van der Laan 7 years ago
parent
commit
c22a53cd63
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 1
      src/wallet/init.cpp
  2. 18
      src/wallet/wallet.cpp
  3. 2
      src/wallet/wallet.h
  4. 2
      test/functional/keypool-topup.py
  5. 8
      test/functional/wallet-hd.py
  6. 3
      test/functional/wallet.py

1
src/wallet/init.cpp

@ -30,7 +30,6 @@ std::string GetWalletHelpString(bool showDebug)
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet on startup")); strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet on startup"));
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE)); strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE));
strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET)); strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
strUsage += HelpMessageOpt("-usehd", _("Use hierarchical deterministic key generation (HD) after BIP32. Only has effect during wallet creation/first start") + " " + strprintf(_("(default: %u)"), DEFAULT_USE_HD_WALLET));
strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF)); strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF));
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup")); strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup"));
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT)); strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT));

18
src/wallet/wallet.cpp

@ -3826,17 +3826,13 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
if (fFirstRun) if (fFirstRun)
{ {
// Create new keyUser and set as default key // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET) && !walletInstance->IsHDEnabled()) { walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY);
// ensure this wallet.dat can only be opened by clients supporting HD with chain split // generate a new master key
walletInstance->SetMinVersion(FEATURE_HD_SPLIT); CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey();
if (!walletInstance->SetHDMasterKey(masterPubKey))
// generate a new master key throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey();
if (!walletInstance->SetHDMasterKey(masterPubKey))
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
}
// Top up the keypool // Top up the keypool
if (!walletInstance->TopUpKeyPool()) { if (!walletInstance->TopUpKeyPool()) {
@ -3849,7 +3845,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
else if (gArgs.IsArgSet("-usehd")) { else if (gArgs.IsArgSet("-usehd")) {
bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET); bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET);
if (walletInstance->IsHDEnabled() && !useHD) { if (walletInstance->IsHDEnabled() && !useHD) {
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile)); InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet or create new non-HD wallets."), walletFile));
return nullptr; return nullptr;
} }
if (!walletInstance->IsHDEnabled() && useHD) { if (!walletInstance->IsHDEnabled() && useHD) {

2
src/wallet/wallet.h

@ -96,6 +96,8 @@ enum WalletFeature
FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k) FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
}; };

2
test/functional/keypool-topup.py

@ -23,7 +23,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']] self.extra_args = [[], ['-keypool=100', '-keypoolmin=20']]
def run_test(self): def run_test(self):
self.tmpdir = self.options.tmpdir self.tmpdir = self.options.tmpdir

8
test/functional/wallet-hd.py

@ -15,17 +15,11 @@ class WalletHDTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']] self.extra_args = [[], ['-keypool=0']]
def run_test (self): def run_test (self):
tmpdir = self.options.tmpdir tmpdir = self.options.tmpdir
# Make sure can't switch off usehd after wallet creation
self.stop_node(1)
self.assert_start_raises_init_error(1, ['-usehd=0'], 'already existing HD wallet')
self.start_node(1)
connect_nodes_bi(self.nodes, 0, 1)
# Make sure we use hd, keep masterkeyid # Make sure we use hd, keep masterkeyid
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid']
assert_equal(len(masterkeyid), 40) assert_equal(len(masterkeyid), 40)

3
test/functional/wallet.py

@ -10,10 +10,9 @@ class WalletTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 4 self.num_nodes = 4
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
def setup_network(self): def setup_network(self):
self.add_nodes(4, self.extra_args) self.add_nodes(4)
self.start_node(0) self.start_node(0)
self.start_node(1) self.start_node(1)
self.start_node(2) self.start_node(2)

Loading…
Cancel
Save