From 9c16b1735f8e530ce68d678e9ca0eceb2ceb3520 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Sat, 6 Apr 2019 12:55:34 -0400 Subject: Move wallet upgrading to its own function --- src/wallet/wallet.cpp | 80 ++++++++++++++++++++++++++++----------------------- src/wallet/wallet.h | 3 ++ 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 45f5542cad..c37bf0860c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3830,42 +3830,8 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } } - int prev_version = walletInstance->GetVersion(); - if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) - { - int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); - if (nMaxVersion == 0) // the -upgradewallet without argument case - { - walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); - nMaxVersion = FEATURE_LATEST; - walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately - } - else - walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); - if (nMaxVersion < walletInstance->GetVersion()) - { - error = _("Cannot downgrade wallet").translated; - return nullptr; - } - walletInstance->SetMaxVersion(nMaxVersion); - } - - // Upgrade to HD if explicit upgrade - if (gArgs.GetBoolArg("-upgradewallet", false)) { - LOCK(walletInstance->cs_wallet); - - // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT - int max_version = walletInstance->GetVersion(); - if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { - error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; - return nullptr; - } - - for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { - if (!spk_man->Upgrade(prev_version, error)) { - return nullptr; - } - } + if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) { + return nullptr; } if (fFirstRun) @@ -4129,6 +4095,48 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest return &address_book_it->second; } +bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, bool fFirstRun, std::string& error, std::vector& warnings) +{ + int prev_version = walletInstance->GetVersion(); + if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) + { + int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); + if (nMaxVersion == 0) // the -upgradewallet without argument case + { + walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); + nMaxVersion = FEATURE_LATEST; + walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately + } + else + walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); + if (nMaxVersion < walletInstance->GetVersion()) + { + error = _("Cannot downgrade wallet").translated; + return false; + } + walletInstance->SetMaxVersion(nMaxVersion); + } + + // Upgrade to HD if explicit upgrade + if (gArgs.GetBoolArg("-upgradewallet", false)) { + LOCK(walletInstance->cs_wallet); + + // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT + int max_version = walletInstance->GetVersion(); + if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { + error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; + return false; + } + + for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { + if (!spk_man->Upgrade(prev_version, error)) { + return false; + } + } + } + return true; +} + void CWallet::postInitProcess() { auto locked_chain = chain().lock(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6c54c72e76..776187fcac 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1175,6 +1175,9 @@ public: LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...); }; + /** Upgrade the wallet */ + static bool UpgradeWallet(std::shared_ptr wallet, bool first_run, std::string& error, std::vector& warnings); + //! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers std::set GetActiveScriptPubKeyMans() const; -- cgit v1.2.3 From 183323712398e26ddcf3a9dc048aaa9900a91f5a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 22 Apr 2019 00:09:39 -0400 Subject: Only run UpgradeWallet if the wallet needs to be upgraded --- src/wallet/wallet.cpp | 53 ++++++++++++++++++++++++--------------------------- src/wallet/wallet.h | 2 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c37bf0860c..83c35befd9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3830,8 +3830,10 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } } - if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) { - return nullptr; + if (gArgs.GetBoolArg("-upgradewallet", false)) { + if (!UpgradeWallet(walletInstance, error, warnings)) { + return nullptr; + } } if (fFirstRun) @@ -4095,38 +4097,33 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest return &address_book_it->second; } -bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, bool fFirstRun, std::string& error, std::vector& warnings) +bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, std::string& error, std::vector& warnings) { int prev_version = walletInstance->GetVersion(); - if (gArgs.GetBoolArg("-upgradewallet", fFirstRun)) + int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); + if (nMaxVersion == 0) // the -upgradewallet without argument case { - int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); - if (nMaxVersion == 0) // the -upgradewallet without argument case - { - walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); - nMaxVersion = FEATURE_LATEST; - walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately - } - else - walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); - if (nMaxVersion < walletInstance->GetVersion()) - { - error = _("Cannot downgrade wallet").translated; - return false; - } - walletInstance->SetMaxVersion(nMaxVersion); + walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); + nMaxVersion = FEATURE_LATEST; + walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately } + else + walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); + if (nMaxVersion < walletInstance->GetVersion()) + { + error = _("Cannot downgrade wallet").translated; + return false; + } + walletInstance->SetMaxVersion(nMaxVersion); - // Upgrade to HD if explicit upgrade - if (gArgs.GetBoolArg("-upgradewallet", false)) { - LOCK(walletInstance->cs_wallet); + LOCK(walletInstance->cs_wallet); - // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT - int max_version = walletInstance->GetVersion(); - if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { - error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; - return false; - } + // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT + int max_version = walletInstance->GetVersion(); + if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { + error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; + return false; + } for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { if (!spk_man->Upgrade(prev_version, error)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 776187fcac..669e3a33f2 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1176,7 +1176,7 @@ public: }; /** Upgrade the wallet */ - static bool UpgradeWallet(std::shared_ptr wallet, bool first_run, std::string& error, std::vector& warnings); + static bool UpgradeWallet(std::shared_ptr wallet, std::string& error, std::vector& warnings); //! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers std::set GetActiveScriptPubKeyMans() const; -- cgit v1.2.3 From c988f27937bc79c90f4eed48552c72f1b66dc044 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 22 Apr 2019 00:18:35 -0400 Subject: Have UpgradeWallet take the version to upgrade to and an error message out parameter --- src/wallet/wallet.cpp | 6 +++--- src/wallet/wallet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 83c35befd9..a6cd543205 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3831,7 +3831,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } if (gArgs.GetBoolArg("-upgradewallet", false)) { - if (!UpgradeWallet(walletInstance, error, warnings)) { + if (!UpgradeWallet(walletInstance, gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) { return nullptr; } } @@ -4097,10 +4097,10 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest return &address_book_it->second; } -bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, std::string& error, std::vector& warnings) +bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, int version, std::string& error, std::vector& warnings) { int prev_version = walletInstance->GetVersion(); - int nMaxVersion = gArgs.GetArg("-upgradewallet", 0); + int nMaxVersion = version; if (nMaxVersion == 0) // the -upgradewallet without argument case { walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 669e3a33f2..a4787a8b21 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1176,7 +1176,7 @@ public: }; /** Upgrade the wallet */ - static bool UpgradeWallet(std::shared_ptr wallet, std::string& error, std::vector& warnings); + static bool UpgradeWallet(std::shared_ptr wallet, int version, std::string& error, std::vector& warnings); //! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers std::set GetActiveScriptPubKeyMans() const; -- cgit v1.2.3 From 1e48796c99b63aa8fa8451ce7b0c20759ea43500 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 22 Apr 2019 00:23:33 -0400 Subject: Make UpgradeWallet a member function of CWallet --- src/wallet/wallet.cpp | 29 ++++++++++++++--------------- src/wallet/wallet.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a6cd543205..c16fb80b9e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3831,7 +3831,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } if (gArgs.GetBoolArg("-upgradewallet", false)) { - if (!UpgradeWallet(walletInstance, gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) { + if (!UpgradeWallet(gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) { return nullptr; } } @@ -4097,38 +4097,37 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest return &address_book_it->second; } -bool CWallet::UpgradeWallet(std::shared_ptr walletInstance, int version, std::string& error, std::vector& warnings) +bool CWallet::UpgradeWallet(int version, std::string& error, std::vector& warnings) { - int prev_version = walletInstance->GetVersion(); + int prev_version = GetVersion(); int nMaxVersion = version; if (nMaxVersion == 0) // the -upgradewallet without argument case { - walletInstance->WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); + WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); nMaxVersion = FEATURE_LATEST; - walletInstance->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately + SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately } else - walletInstance->WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); - if (nMaxVersion < walletInstance->GetVersion()) + WalletLogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); + if (nMaxVersion < GetVersion()) { error = _("Cannot downgrade wallet").translated; return false; } - walletInstance->SetMaxVersion(nMaxVersion); + SetMaxVersion(nMaxVersion); - LOCK(walletInstance->cs_wallet); + LOCK(cs_wallet); // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT - int max_version = walletInstance->GetVersion(); - if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { + int max_version = GetVersion(); + if (!CanSupportFeature(FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; return false; } - for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { - if (!spk_man->Upgrade(prev_version, error)) { - return false; - } + for (auto spk_man : GetActiveScriptPubKeyMans()) { + if (!spk_man->Upgrade(prev_version, error)) { + return false; } } return true; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a4787a8b21..a40c7ffe08 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1176,7 +1176,7 @@ public: }; /** Upgrade the wallet */ - static bool UpgradeWallet(std::shared_ptr wallet, int version, std::string& error, std::vector& warnings); + bool UpgradeWallet(int version, std::string& error, std::vector& warnings); //! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers std::set GetActiveScriptPubKeyMans() const; -- cgit v1.2.3 From 92263cce5b6c6b66296dadda5f29724611db0160 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Sat, 6 Apr 2019 12:56:06 -0400 Subject: Add upgradewallet RPC --- src/rpc/client.cpp | 1 + src/wallet/rpcwallet.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 84719d4ca4..2d78d38592 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -153,6 +153,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "logging", 0, "include" }, { "logging", 1, "exclude" }, { "disconnectnode", 1, "nodeid" }, + { "upgradewallet", 0, "version" }, // Echo with conversion (For testing only) { "echojson", 0, "arg0" }, { "echojson", 1, "arg1" }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e98e928a1d..3d2360cb9a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4245,6 +4245,45 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request) return result; } +static UniValue upgradewallet(const JSONRPCRequest& request) +{ + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + CWallet* const pwallet = wallet.get(); + + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { + return NullUniValue; + } + + RPCHelpMan{"upgradewallet", + "\nUpgrade the wallet. Upgrades to the latest version if no version number is specified\n" + "New keys may be generated and a new wallet backup will need to be made.", + { + {"version", RPCArg::Type::NUM, /* default */ strprintf("%d", FEATURE_LATEST), "The version number to upgrade to. Default is the latest wallet version"} + }, + RPCResults{}, + RPCExamples{ + HelpExampleCli("upgradewallet", "169900") + + HelpExampleRpc("upgradewallet", "169900") + } + }.Check(request); + + RPCTypeCheck(request.params, {UniValue::VNUM}, true); + + EnsureWalletIsUnlocked(pwallet); + + int version = 0; + if (!request.params[0].isNull()) { + version = request.params[0].get_int(); + } + + std::string error; + std::vector warnings; + if (!pwallet->UpgradeWallet(version, error, warnings)) { + throw JSONRPCError(RPC_WALLET_ERROR, error); + } + return error; +} + UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp UniValue importprivkey(const JSONRPCRequest& request); @@ -4313,6 +4352,7 @@ static const CRPCCommand commands[] = { "wallet", "signmessage", &signmessage, {"address","message"} }, { "wallet", "signrawtransactionwithwallet", &signrawtransactionwithwallet, {"hexstring","prevtxs","sighashtype"} }, { "wallet", "unloadwallet", &unloadwallet, {"wallet_name"} }, + { "wallet", "upgradewallet", &upgradewallet, {"version"} }, { "wallet", "walletcreatefundedpsbt", &walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, { "wallet", "walletlock", &walletlock, {} }, { "wallet", "walletpassphrase", &walletpassphrase, {"passphrase","timeout"} }, -- cgit v1.2.3 From 0d32d661481f099af572e7a08a50e17bcc165c44 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Sat, 6 Apr 2019 12:56:15 -0400 Subject: Remove -upgradewallet startup option --- src/wallet/init.cpp | 7 ------- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/wallet.cpp | 8 +------- test/functional/wallet_multiwallet.py | 17 ----------------- 4 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 50f064b305..aee705a26c 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -57,7 +57,6 @@ void WalletInit::AddWalletOptions() const gArgs.AddArg("-salvagewallet", "Attempt to recover private keys from a corrupt wallet on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); gArgs.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); gArgs.AddArg("-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), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); - gArgs.AddArg("-upgradewallet", "Upgrade wallet to latest format on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); gArgs.AddArg("-wallet=", "Specify wallet database path. Can be specified multiple times to load multiple wallets. Path is interpreted relative to if it is not absolute, and will be created if it does not exist (as a directory containing a wallet.dat file and log files). For backwards compatibility this will also accept names of existing data files in .)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET); gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); gArgs.AddArg("-walletdir=", "Specify directory to hold wallets (default: /wallets if it exists, otherwise )", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET); @@ -116,12 +115,6 @@ bool WalletInit::ParameterInteraction() const } } - if (is_multiwallet) { - if (gArgs.GetBoolArg("-upgradewallet", false)) { - return InitError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet")); - } - } - if (gArgs.GetBoolArg("-sysperms", false)) return InitError("-sysperms is not allowed in combination with enabled wallet functionality"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3d2360cb9a..5a74de2790 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2586,7 +2586,7 @@ static UniValue loadwallet(const JSONRPCRequest& request) RPCHelpMan{"loadwallet", "\nLoads a wallet from a wallet file or directory." "\nNote that all wallet command-line options used when starting bitcoind will be" - "\napplied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).\n", + "\napplied to the new wallet (eg -zapwallettxes, rescan, etc).\n", { {"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet directory or .dat file."}, }, @@ -4021,7 +4021,7 @@ UniValue sethdseed(const JSONRPCRequest& request) // Do not do anything to non-HD wallets if (!pwallet->CanSupportFeature(FEATURE_HD)) { - throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set a HD seed on a non-HD wallet. Start with -upgradewallet in order to upgrade a non-HD wallet to HD"); + throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set a HD seed on a non-HD wallet. Use the upgradewallet RPC in order to upgrade a non-HD wallet to HD"); } EnsureWalletIsUnlocked(pwallet); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c16fb80b9e..081bb4320b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3830,12 +3830,6 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } } - if (gArgs.GetBoolArg("-upgradewallet", false)) { - if (!UpgradeWallet(gArgs.GetBoolArg("-upgradewallet", 0), error, warnings)) { - return nullptr; - } - } - if (fFirstRun) { // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key @@ -4121,7 +4115,7 @@ bool CWallet::UpgradeWallet(int version, std::string& error, std::vector= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) { - error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use -upgradewallet=169900 or -upgradewallet with no version specified.").translated; + error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified.").translated; return false; } diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index a2c502f280..d450f66bb9 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -125,10 +125,6 @@ class MultiWalletTest(BitcoinTestFramework): self.nodes[0].assert_start_raises_init_error(['-salvagewallet', '-wallet=w1', '-wallet=w2'], "Error: -salvagewallet is only allowed with a single wallet file") self.nodes[0].assert_start_raises_init_error(['-salvagewallet=1', '-wallet=w1', '-wallet=w2'], "Error: -salvagewallet is only allowed with a single wallet file") - self.log.info("Do not allow -upgradewallet with multiwallet") - self.nodes[0].assert_start_raises_init_error(['-upgradewallet', '-wallet=w1', '-wallet=w2'], "Error: -upgradewallet is only allowed with a single wallet file") - self.nodes[0].assert_start_raises_init_error(['-upgradewallet=1', '-wallet=w1', '-wallet=w2'], "Error: -upgradewallet is only allowed with a single wallet file") - # if wallets/ doesn't exist, datadir should be the default wallet dir wallet_dir2 = data_dir('walletdir') os.rename(wallet_dir(), wallet_dir2) @@ -332,18 +328,5 @@ class MultiWalletTest(BitcoinTestFramework): self.nodes[0].unloadwallet(wallet) self.nodes[1].loadwallet(wallet) - # Fail to load if wallet is downgraded - shutil.copytree(os.path.join(self.options.data_wallets_dir, 'high_minversion'), wallet_dir('high_minversion')) - self.restart_node(0, extra_args=['-upgradewallet={}'.format(FEATURE_LATEST)]) - assert {'name': 'high_minversion'} in self.nodes[0].listwalletdir()['wallets'] - self.log.info("Fail -upgradewallet that results in downgrade") - assert_raises_rpc_error( - -4, - 'Wallet loading failed: Error loading {}: Wallet requires newer version of {}'.format( - wallet_dir('high_minversion', 'wallet.dat'), self.config['environment']['PACKAGE_NAME']), - lambda: self.nodes[0].loadwallet(filename='high_minversion'), - ) - - if __name__ == '__main__': MultiWalletTest().main() -- cgit v1.2.3