@@ -435,21 +435,13 @@ void CWallet::chainStateFlushed(const CBlockLocator& loc)
435
435
batch.WriteBestBlock (loc);
436
436
}
437
437
438
- void CWallet::SetMinVersion (enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit )
438
+ void CWallet::SetMinVersion (enum WalletFeature nVersion, WalletBatch* batch_in)
439
439
{
440
440
LOCK (cs_wallet);
441
441
if (nWalletVersion >= nVersion)
442
442
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
-
448
443
nWalletVersion = nVersion;
449
444
450
- if (nVersion > nWalletMaxVersion)
451
- nWalletMaxVersion = nVersion;
452
-
453
445
{
454
446
WalletBatch* batch = batch_in ? batch_in : new WalletBatch (*database);
455
447
if (nWalletVersion > 40000 )
@@ -459,18 +451,6 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in,
459
451
}
460
452
}
461
453
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
-
474
454
std::set<uint256> CWallet::GetConflicts (const uint256& txid) const
475
455
{
476
456
std::set<uint256> result;
@@ -655,7 +635,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
655
635
}
656
636
657
637
// Encryption was introduced in version 0.4.0
658
- SetMinVersion (FEATURE_WALLETCRYPT, encrypted_batch, true );
638
+ SetMinVersion (FEATURE_WALLETCRYPT, encrypted_batch);
659
639
660
640
if (!encrypted_batch->TxnCommit ()) {
661
641
delete encrypted_batch;
@@ -4120,31 +4100,30 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
4120
4100
bool CWallet::UpgradeWallet (int version, bilingual_str& error, std::vector<bilingual_str>& warnings)
4121
4101
{
4122
4102
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
4125
4104
{
4126
4105
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;
4129
4107
} else {
4130
- WalletLogPrintf (" Allowing wallet upgrade up to %i\n " , nMaxVersion );
4108
+ WalletLogPrintf (" Allowing wallet upgrade up to %i\n " , version );
4131
4109
}
4132
- if (nMaxVersion < GetVersion () )
4110
+ if (version < prev_version )
4133
4111
{
4134
4112
error = _ (" Cannot downgrade wallet" );
4135
4113
return false ;
4136
4114
}
4137
- SetMaxVersion (nMaxVersion);
4138
4115
4139
4116
LOCK (cs_wallet);
4140
4117
4141
4118
// 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) {
4144
4120
error = _ (" Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified." );
4145
4121
return false ;
4146
4122
}
4147
4123
4124
+ // Permanently upgrade to the version
4125
+ SetMinVersion (GetClosestWalletFeature (version));
4126
+
4148
4127
for (auto spk_man : GetActiveScriptPubKeyMans ()) {
4149
4128
if (!spk_man->Upgrade (prev_version, version, error)) {
4150
4129
return false ;
0 commit comments