Skip to content

Commit febf3a8

Browse files
committed
Merge #15588: Log the actual wallet file version and no longer publicly expose the "version" record
35e60e7 Remove ReadVersion and WriteVersion (Andrew Chow) b3d4f6c Log the actual wallet file version (Andrew Chow) c88e87c Remove nFileVersion from CWalletScanState (Andrew Chow) Pull request description: The wallet file version is stored in the "minversion" record, not the "version" record. However "version" is no longer used anywhere except to record the highest versioned client which has opened a wallet file (which is currently only used to check whether this was most recently opened by a 0.4.0 or 0.5.0rc1 client which had a broken wallet encryption implementation). Furthermore, "version" was logged to the debug.log which is confusing because it is not the actual wallet file version. This PR changes it so that this confusion largely no longer exists. The wallet file version logging is changed to use "minversion" and reading and writing the "version" record is no longer publicly exposed to prevent potential confusion about whether the actual file version is being read or written. Lastly, in the one place it is actually used, the variable name is changed from nFileVersion to last_client to better reflect what that record actually represents. ACKs for top commit: jb55: ACK 35e60e7, I compiled locally as a quick sanity check. ryanofsky: utACK 35e60e7. This code still pretty confusing, but a little simpler now. And the previous log statement was really misleading and useless compared to the new one here. meshcollider: Looks good, thanks! utACK 35e60e7 Tree-SHA512: f782b2f215d07fbc9b806322bda8085445b81c02b65ca674a8c6a3e1de505a0abd050669afe0ead4778816144a1c18462e13930071cedb7227a058aeb39493f7
2 parents 1139e3c + 35e60e7 commit febf3a8

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
585585
if (fCreate && !Exists(std::string("version"))) {
586586
bool fTmp = fReadOnly;
587587
fReadOnly = false;
588-
WriteVersion(CLIENT_VERSION);
588+
Write(std::string("version"), CLIENT_VERSION);
589589
fReadOnly = fTmp;
590590
}
591591
}

src/wallet/db.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,6 @@ class BerkeleyBatch
399399
return (ret == 0);
400400
}
401401

402-
bool ReadVersion(int& nVersion)
403-
{
404-
nVersion = 0;
405-
return Read(std::string("version"), nVersion);
406-
}
407-
408-
bool WriteVersion(int nVersion)
409-
{
410-
return Write(std::string("version"), nVersion);
411-
}
412-
413402
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
414403
};
415404

src/wallet/walletdb.cpp

Lines changed: 10 additions & 22 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 (const std::exception& e) {
@@ -519,7 +512,12 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
519512
if (result != DBErrors::LOAD_OK)
520513
return result;
521514

522-
pwallet->WalletLogPrintf("nFileVersion = %d\n", wss.nFileVersion);
515+
// Last client version to open this wallet, was previously the file version number
516+
int last_client = CLIENT_VERSION;
517+
m_batch.Read(std::string("version"), last_client);
518+
519+
int wallet_version = pwallet->GetVersion();
520+
pwallet->WalletLogPrintf("Wallet File Version = %d\n", wallet_version > 0 ? wallet_version : last_client);
523521

524522
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n",
525523
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
@@ -532,11 +530,11 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
532530
WriteTx(pwallet->mapWallet.at(hash));
533531

534532
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
535-
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))
533+
if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000))
536534
return DBErrors::NEED_REWRITE;
537535

538-
if (wss.nFileVersion < CLIENT_VERSION) // Update
539-
WriteVersion(CLIENT_VERSION);
536+
if (last_client < CLIENT_VERSION) // Update
537+
m_batch.Write(std::string("version"), CLIENT_VERSION);
540538

541539
if (wss.fAnyUnordered)
542540
result = pwallet->ReorderTransactions();
@@ -779,13 +777,3 @@ bool WalletBatch::TxnAbort()
779777
{
780778
return m_batch.TxnAbort();
781779
}
782-
783-
bool WalletBatch::ReadVersion(int& nVersion)
784-
{
785-
return m_batch.ReadVersion(nVersion);
786-
}
787-
788-
bool WalletBatch::WriteVersion(int nVersion)
789-
{
790-
return m_batch.WriteVersion(nVersion);
791-
}

src/wallet/walletdb.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ class WalletBatch
249249
bool TxnCommit();
250250
//! Abort current transaction
251251
bool TxnAbort();
252-
//! Read wallet version
253-
bool ReadVersion(int& nVersion);
254-
//! Write wallet version
255-
bool WriteVersion(int nVersion);
256252
private:
257253
BerkeleyBatch m_batch;
258254
WalletDatabase& m_database;

0 commit comments

Comments
 (0)