Skip to content

Commit c88e87c

Browse files
committed
Remove nFileVersion from CWalletScanState
nFileVersion is not the actual file version and is not used except in one place. So it is removed from CWalletScanState and changed so that it is just read at the place it is needed. Furthermore, the "version" record now only indicates the version of the highest versioned client that has opened a wallet file so the variable name is changed accordingly
1 parent c3b1cb9 commit c88e87c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/wallet/walletdb.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class CWalletScanState {
165165
unsigned int m_unknown_records{0};
166166
bool fIsEncrypted{false};
167167
bool fAnyUnordered{false};
168-
int nFileVersion{0};
169168
std::vector<uint256> vWalletUpgrade;
170169

171170
CWalletScanState() {
@@ -376,12 +375,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
376375

377376
pwallet->LoadKeyPool(nIndex, keypool);
378377
}
379-
else if (strType == "version")
380-
{
381-
ssValue >> wss.nFileVersion;
382-
if (wss.nFileVersion == 10300)
383-
wss.nFileVersion = 300;
384-
}
385378
else if (strType == "cscript")
386379
{
387380
uint160 hash;
@@ -419,7 +412,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
419412
return false;
420413
}
421414
} else if (strType != "bestblock" && strType != "bestblock_nomerkle" &&
422-
strType != "minversion" && strType != "acentry") {
415+
strType != "minversion" && strType != "acentry" && strType != "version") {
423416
wss.m_unknown_records++;
424417
}
425418
} catch (...)
@@ -512,7 +505,11 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
512505
if (result != DBErrors::LOAD_OK)
513506
return result;
514507

515-
pwallet->WalletLogPrintf("nFileVersion = %d\n", wss.nFileVersion);
508+
// Last client version to open this wallet, was previously the file version number
509+
int last_client = CLIENT_VERSION;
510+
ReadVersion(last_client);
511+
512+
pwallet->WalletLogPrintf("nFileVersion = %d\n", last_client);
516513

517514
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n",
518515
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
@@ -525,10 +522,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
525522
WriteTx(pwallet->mapWallet.at(hash));
526523

527524
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
528-
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
525+
if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000))
529526
return DBErrors::NEED_REWRITE;
530527

531-
if (wss.nFileVersion < CLIENT_VERSION) // Update
528+
if (last_client < CLIENT_VERSION) // Update
532529
WriteVersion(CLIENT_VERSION);
533530

534531
if (wss.fAnyUnordered)

0 commit comments

Comments
 (0)