Skip to content

Commit 713a920

Browse files
committed
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.
1 parent d4c18f7 commit 713a920

File tree

5 files changed

+10
-22
lines changed

5 files changed

+10
-22
lines changed

src/wallet/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ std::string GetWalletHelpString(bool showDebug)
2929
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet on startup"));
3030
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE));
3131
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));
32-
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));
3332
strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF));
3433
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup"));
3534
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT));

src/wallet/wallet.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,17 +3829,13 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38293829

38303830
if (fFirstRun)
38313831
{
3832-
// Create new keyUser and set as default key
3833-
if (gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET) && !walletInstance->IsHDEnabled()) {
3832+
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
3833+
walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY);
38343834

3835-
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
3836-
walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY);
3837-
3838-
// generate a new master key
3839-
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey();
3840-
if (!walletInstance->SetHDMasterKey(masterPubKey))
3841-
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
3842-
}
3835+
// generate a new master key
3836+
CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey();
3837+
if (!walletInstance->SetHDMasterKey(masterPubKey))
3838+
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
38433839

38443840
// Top up the keypool
38453841
if (!walletInstance->TopUpKeyPool()) {
@@ -3852,7 +3848,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38523848
else if (gArgs.IsArgSet("-usehd")) {
38533849
bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET);
38543850
if (walletInstance->IsHDEnabled() && !useHD) {
3855-
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile));
3851+
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet or create new non-HD wallets."), walletFile));
38563852
return nullptr;
38573853
}
38583854
if (!walletInstance->IsHDEnabled() && useHD) {

test/functional/keypool-topup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
2323
def set_test_params(self):
2424
self.setup_clean_chain = True
2525
self.num_nodes = 2
26-
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
26+
self.extra_args = [[], ['-keypool=100', '-keypoolmin=20']]
2727

2828
def run_test(self):
2929
self.tmpdir = self.options.tmpdir

test/functional/wallet-hd.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ class WalletHDTest(BitcoinTestFramework):
1515
def set_test_params(self):
1616
self.setup_clean_chain = True
1717
self.num_nodes = 2
18-
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']]
18+
self.extra_args = [[], ['-keypool=0']]
1919

2020
def run_test (self):
2121
tmpdir = self.options.tmpdir
2222

23-
# Make sure can't switch off usehd after wallet creation
24-
self.stop_node(1)
25-
self.assert_start_raises_init_error(1, ['-usehd=0'], 'already existing HD wallet')
26-
self.start_node(1)
27-
connect_nodes_bi(self.nodes, 0, 1)
28-
2923
# Make sure we use hd, keep masterkeyid
3024
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid']
3125
assert_equal(len(masterkeyid), 40)

test/functional/wallet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ class WalletTest(BitcoinTestFramework):
1010
def set_test_params(self):
1111
self.num_nodes = 4
1212
self.setup_clean_chain = True
13-
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
1413

1514
def setup_network(self):
16-
self.add_nodes(4, self.extra_args)
15+
self.add_nodes(4)
1716
self.start_node(0)
1817
self.start_node(1)
1918
self.start_node(2)

0 commit comments

Comments
 (0)