@@ -435,21 +435,13 @@ void CWallet::chainStateFlushed(const CBlockLocator& loc)
435435 batch.WriteBestBlock (loc);
436436}
437437
438- void CWallet::SetMinVersion (enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit )
438+ void CWallet::SetMinVersion (enum WalletFeature nVersion, WalletBatch* batch_in)
439439{
440440 LOCK (cs_wallet);
441441 if (nWalletVersion >= nVersion)
442442 return ;
443-
444- // when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way
445- if (fExplicit && nVersion > nWalletMaxVersion)
446- nVersion = FEATURE_LATEST;
447-
448443 nWalletVersion = nVersion;
449444
450- if (nVersion > nWalletMaxVersion)
451- nWalletMaxVersion = nVersion;
452-
453445 {
454446 WalletBatch* batch = batch_in ? batch_in : new WalletBatch (*database);
455447 if (nWalletVersion > 40000 )
@@ -459,18 +451,6 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in,
459451 }
460452}
461453
462- bool CWallet::SetMaxVersion (int nVersion)
463- {
464- LOCK (cs_wallet);
465- // cannot downgrade below current version
466- if (nWalletVersion > nVersion)
467- return false ;
468-
469- nWalletMaxVersion = nVersion;
470-
471- return true ;
472- }
473-
474454std::set<uint256> CWallet::GetConflicts (const uint256& txid) const
475455{
476456 std::set<uint256> result;
@@ -655,7 +635,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
655635 }
656636
657637 // Encryption was introduced in version 0.4.0
658- SetMinVersion (FEATURE_WALLETCRYPT, encrypted_batch, true );
638+ SetMinVersion (FEATURE_WALLETCRYPT, encrypted_batch);
659639
660640 if (!encrypted_batch->TxnCommit ()) {
661641 delete encrypted_batch;
@@ -4120,31 +4100,30 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
41204100bool CWallet::UpgradeWallet (int version, bilingual_str& error, std::vector<bilingual_str>& warnings)
41214101{
41224102 int prev_version = GetVersion ();
4123- int & nMaxVersion = version;
4124- if (nMaxVersion == 0 ) // the -upgradewallet without argument case
4103+ if (version == 0 ) // the -upgradewallet without argument case
41254104 {
41264105 WalletLogPrintf (" Performing wallet upgrade to %i\n " , FEATURE_LATEST);
4127- nMaxVersion = FEATURE_LATEST;
4128- SetMinVersion (FEATURE_LATEST); // permanently upgrade the wallet immediately
4106+ version = FEATURE_LATEST;
41294107 } else {
4130- WalletLogPrintf (" Allowing wallet upgrade up to %i\n " , nMaxVersion );
4108+ WalletLogPrintf (" Allowing wallet upgrade up to %i\n " , version );
41314109 }
4132- if (nMaxVersion < GetVersion () )
4110+ if (version < prev_version )
41334111 {
41344112 error = _ (" Cannot downgrade wallet" );
41354113 return false ;
41364114 }
4137- SetMaxVersion (nMaxVersion);
41384115
41394116 LOCK (cs_wallet);
41404117
41414118 // Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
4142- int max_version = GetVersion ();
4143- if (!CanSupportFeature (FEATURE_HD_SPLIT) && max_version >= FEATURE_HD_SPLIT && max_version < FEATURE_PRE_SPLIT_KEYPOOL) {
4119+ if (!CanSupportFeature (FEATURE_HD_SPLIT) && version >= FEATURE_HD_SPLIT && version < FEATURE_PRE_SPLIT_KEYPOOL) {
41444120 error = _ (" Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified." );
41454121 return false ;
41464122 }
41474123
4124+ // Permanently upgrade to the version
4125+ SetMinVersion (GetClosestWalletFeature (version));
4126+
41484127 for (auto spk_man : GetActiveScriptPubKeyMans ()) {
41494128 if (!spk_man->Upgrade (prev_version, version, error)) {
41504129 return false ;
0 commit comments