Only run UpgradeWallet if the wallet needs to be upgraded

This commit is contained in:
Andrew Chow 2019-04-22 00:09:39 -04:00
parent 9c16b1735f
commit 1833237123
2 changed files with 26 additions and 29 deletions

View File

@ -3830,9 +3830,11 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
}
}
if (!UpgradeWallet(walletInstance, fFirstRun, error, warnings)) {
if (gArgs.GetBoolArg("-upgradewallet", false)) {
if (!UpgradeWallet(walletInstance, error, warnings)) {
return nullptr;
}
}
if (fFirstRun)
{
@ -4095,11 +4097,9 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
return &address_book_it->second;
}
bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, bool fFirstRun, std::string& error, std::vector<std::string>& warnings)
bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, std::string& error, std::vector<std::string>& 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
{
@ -4115,10 +4115,7 @@ bool CWallet::UpgradeWallet(std::shared_ptr<CWallet> walletInstance, bool fFirst
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

View File

@ -1176,7 +1176,7 @@ public:
};
/** Upgrade the wallet */
static bool UpgradeWallet(std::shared_ptr<CWallet> wallet, bool first_run, std::string& error, std::vector<std::string>& warnings);
static bool UpgradeWallet(std::shared_ptr<CWallet> wallet, std::string& error, std::vector<std::string>& warnings);
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;