Skip to content

Commit bd7398c

Browse files
committed
wallet: have ScriptPubKeyMan::Upgrade check against the new version
Instead of using CanSupportFeature and relying on nWalletMaxVersion, take the new version we are upgrading to and use IsSupportedFeature with that and the previous wallet version.
1 parent 5f72054 commit bd7398c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,12 @@ bool LegacyScriptPubKeyMan::CanGetAddresses(bool internal) const
438438
return keypool_has_keys;
439439
}
440440

441-
bool LegacyScriptPubKeyMan::Upgrade(int prev_version, bilingual_str& error)
441+
bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual_str& error)
442442
{
443443
LOCK(cs_KeyStore);
444444
bool hd_upgrade = false;
445445
bool split_upgrade = false;
446-
if (m_storage.CanSupportFeature(FEATURE_HD) && !IsHDEnabled()) {
446+
if (IsFeatureSupported(new_version, FEATURE_HD) && !IsHDEnabled()) {
447447
WalletLogPrintf("Upgrading wallet to HD\n");
448448
m_storage.SetMinVersion(FEATURE_HD);
449449

@@ -453,7 +453,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, bilingual_str& error)
453453
hd_upgrade = true;
454454
}
455455
// Upgrade to HD chain split if necessary
456-
if (m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) {
456+
if (IsFeatureSupported(new_version, FEATURE_HD_SPLIT)) {
457457
WalletLogPrintf("Upgrading wallet to use HD chain split\n");
458458
m_storage.SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL);
459459
split_upgrade = FEATURE_HD_SPLIT > prev_version;

src/wallet/scriptpubkeyman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class ScriptPubKeyMan
206206
virtual bool CanGetAddresses(bool internal = false) const { return false; }
207207

208208
/** Upgrades the wallet to the specified version */
209-
virtual bool Upgrade(int prev_version, bilingual_str& error) { return false; }
209+
virtual bool Upgrade(int prev_version, int new_version, bilingual_str& error) { return false; }
210210

211211
virtual bool HavePrivateKeys() const { return false; }
212212

@@ -371,7 +371,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
371371

372372
bool SetupGeneration(bool force = false) override;
373373

374-
bool Upgrade(int prev_version, bilingual_str& error) override;
374+
bool Upgrade(int prev_version, int new_version, bilingual_str& error) override;
375375

376376
bool HavePrivateKeys() const override;
377377

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,7 @@ const CAddressBookData* CWallet::FindAddressBookEntry(const CTxDestination& dest
41204120
bool CWallet::UpgradeWallet(int version, bilingual_str& error, std::vector<bilingual_str>& warnings)
41214121
{
41224122
int prev_version = GetVersion();
4123-
int nMaxVersion = version;
4123+
int& nMaxVersion = version;
41244124
if (nMaxVersion == 0) // the -upgradewallet without argument case
41254125
{
41264126
WalletLogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
@@ -4146,7 +4146,7 @@ bool CWallet::UpgradeWallet(int version, bilingual_str& error, std::vector<bilin
41464146
}
41474147

41484148
for (auto spk_man : GetActiveScriptPubKeyMans()) {
4149-
if (!spk_man->Upgrade(prev_version, error)) {
4149+
if (!spk_man->Upgrade(prev_version, version, error)) {
41504150
return false;
41514151
}
41524152
}

0 commit comments

Comments
 (0)