Skip to content

Commit 037ee56

Browse files
MacroFakevijaydasmp
authored andcommitted
Merge bitcoin#25383: wallet: don't read db every time that a new 'WalletBatch' is created
c318211 walletdb: fix last client version update (furszy) bda8ebe wallet: don't read db every time that a new WalletBatch is created (furszy) Pull request description: Found it while was working on bitcoin#25297. We are performing a db read operation every time that a new `WalletBatch` is created, inside the constructor, just to check if the client version field is inside the db or not. As the client version field does not change in the entire db lifecycle, this operation can be done only once: The first time that the db is accessed/opened and the client version value can be cached. ACKs for top commit: achow101: ACK c318211 w0xlt: reACK bitcoin@c318211 Tree-SHA512: 7fb780c656e169e8eb21e7212242494a647f6506d6da2cca828703713d440d29c82bec9e7d2c410f37b49361226ccd80846d3eeb8168383d0c2a11d85d73bee2
1 parent 794d346 commit 037ee56

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/wallet/bdb.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,6 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, b
324324
env = database.env.get();
325325
pdb = database.m_db.get();
326326
strFile = database.strFile;
327-
if (!Exists(std::string("version"))) {
328-
bool fTmp = fReadOnly;
329-
fReadOnly = false;
330-
Write(std::string("version"), CLIENT_VERSION);
331-
fReadOnly = fTmp;
332-
}
333327
}
334328

335329
void BerkeleyDatabase::Open()

src/wallet/walletdb.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
879879
if (result != DBErrors::LOAD_OK)
880880
return result;
881881

882-
// Last client version to open this wallet, was previously the file version number
882+
// Last client version to open this wallet
883883
int last_client = CLIENT_VERSION;
884-
m_batch->Read(DBKeys::VERSION, last_client);
885-
886-
int wallet_version = pwallet->GetVersion();
887-
pwallet->WalletLogPrintf("Wallet File Version = %d\n", wallet_version > 0 ? wallet_version : last_client);
884+
bool has_last_client = m_batch->Read(DBKeys::VERSION, last_client);
885+
pwallet->WalletLogPrintf("Wallet file version = %d, last client version = %d\n", pwallet->GetVersion(), last_client);
888886

889887
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u total; Watch scripts: %u; HD PubKeys: %u; Metadata: %u; Unknown wallet records: %u\n",
890888
wss.nKeys, wss.nCKeys, wss.nKeys + wss.nCKeys,
@@ -906,7 +904,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
906904
if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000))
907905
return DBErrors::NEED_REWRITE;
908906

909-
if (last_client < CLIENT_VERSION) // Update
907+
if (!has_last_client || last_client != CLIENT_VERSION) // Update
910908
m_batch->Write(DBKeys::VERSION, CLIENT_VERSION);
911909

912910
if (wss.fAnyUnordered)

0 commit comments

Comments
 (0)