From d4c18f7330b1a967b8144df3d49a857514310a55 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 5 Sep 2017 15:37:45 -0700 Subject: [PATCH 1/2] Bump wallet version number to 159900 --- src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d1d2060b0c..7cc25eb79b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3832,8 +3832,8 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) // Create new keyUser and set as default key if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET) && !walletInstance->IsHDEnabled()) { - // ensure this wallet.dat can only be opened by clients supporting HD with chain split - walletInstance->SetMinVersion(FEATURE_HD_SPLIT); + // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key + walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY); // generate a new master key CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 73ad3bdeca..5bd0bcd32d 100644 --- a/src/wallet/wallet.h +++ b/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_NO_DEFAULT_KEY = 159900, // Wallet without a default key written + FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version }; From 713a92073b3b391f48d4fa146bd334893ec94b8f Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 5 Sep 2017 15:54:11 -0700 Subject: [PATCH 2/2] Remove usehd option and warn when it is used Removed the -usehd option so wallets cannot be made to be non-hd anymore. A warning will be displayed when the option is set. --- src/wallet/init.cpp | 1 - src/wallet/wallet.cpp | 18 +++++++----------- test/functional/keypool-topup.py | 2 +- test/functional/wallet-hd.py | 8 +------- test/functional/wallet.py | 3 +-- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 18365b1b72..f5ca2a78ba 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -29,7 +29,6 @@ std::string GetWalletHelpString(bool showDebug) 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("-txconfirmtarget=", 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("-upgradewallet", _("Upgrade wallet to latest format on startup")); strUsage += HelpMessageOpt("-wallet=", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT)); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7cc25eb79b..10a1c7fa92 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3829,17 +3829,13 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) if (fFirstRun) { - // Create new keyUser and set as default key - if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET) && !walletInstance->IsHDEnabled()) { + // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key + walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY); - // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key - walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY); - - // generate a new master key - CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); - if (!walletInstance->SetHDMasterKey(masterPubKey)) - throw std::runtime_error(std::string(__func__) + ": Storing master key failed"); - } + // generate a new master key + CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); + if (!walletInstance->SetHDMasterKey(masterPubKey)) + throw std::runtime_error(std::string(__func__) + ": Storing master key failed"); // Top up the keypool if (!walletInstance->TopUpKeyPool()) { @@ -3852,7 +3848,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) else if (gArgs.IsArgSet("-usehd")) { bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET); 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; } if (!walletInstance->IsHDEnabled() && useHD) { diff --git a/test/functional/keypool-topup.py b/test/functional/keypool-topup.py index b87433a9c5..160a0f7ae5 100755 --- a/test/functional/keypool-topup.py +++ b/test/functional/keypool-topup.py @@ -23,7 +23,7 @@ class KeypoolRestoreTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True 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): self.tmpdir = self.options.tmpdir diff --git a/test/functional/wallet-hd.py b/test/functional/wallet-hd.py index a6b96b7455..3af04c2279 100755 --- a/test/functional/wallet-hd.py +++ b/test/functional/wallet-hd.py @@ -15,17 +15,11 @@ class WalletHDTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 2 - self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']] + self.extra_args = [[], ['-keypool=0']] def run_test (self): 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 masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid'] assert_equal(len(masterkeyid), 40) diff --git a/test/functional/wallet.py b/test/functional/wallet.py index 27089e8845..a643684c7f 100755 --- a/test/functional/wallet.py +++ b/test/functional/wallet.py @@ -10,10 +10,9 @@ class WalletTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 4 self.setup_clean_chain = True - self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)] def setup_network(self): - self.add_nodes(4, self.extra_args) + self.add_nodes(4) self.start_node(0) self.start_node(1) self.start_node(2)