diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-04-22 00:09:39 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2020-04-13 13:21:01 -0400 |
commit | 183323712398e26ddcf3a9dc048aaa9900a91f5a (patch) | |
tree | 08abb2af1305c8248e251de3e233c39d2b42df4f /src/wallet/wallet.cpp | |
parent | 9c16b1735f8e530ce68d678e9ca0eceb2ceb3520 (diff) |
Only run UpgradeWallet if the wallet needs to be upgraded
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 53 |
1 files changed, 25 insertions, 28 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> 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<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 { - 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)) { |