Skip to content

Commit bda8ebe

Browse files
committed
wallet: don't read db every time that a new WalletBatch is created
Better to perform the action only one time (during 'LoadWallet'). Where the value is being used.
1 parent 26ec2f2 commit bda8ebe

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/wallet/bdb.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,6 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, b
315315
env = database.env.get();
316316
pdb = database.m_db.get();
317317
strFile = fs::PathToString(database.m_filename);
318-
if (!Exists(std::string("version"))) {
319-
bool fTmp = fReadOnly;
320-
fReadOnly = false;
321-
Write(std::string("version"), CLIENT_VERSION);
322-
fReadOnly = fTmp;
323-
}
324318
}
325319

326320
void BerkeleyDatabase::Open()

src/wallet/walletdb.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,8 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
885885

886886
// Last client version to open this wallet, was previously the file version number
887887
int last_client = CLIENT_VERSION;
888-
m_batch->Read(DBKeys::VERSION, last_client);
889-
890-
int wallet_version = pwallet->GetVersion();
891-
pwallet->WalletLogPrintf("Wallet File Version = %d\n", wallet_version > 0 ? wallet_version : last_client);
888+
bool has_last_client = m_batch->Read(DBKeys::VERSION, last_client);
889+
pwallet->WalletLogPrintf("Wallet file version = %d, last client version = %d\n", pwallet->GetVersion(), last_client);
892890

893891
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total. Unknown wallet records: %u\n",
894892
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys, wss.m_unknown_records);
@@ -909,7 +907,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
909907
if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000))
910908
return DBErrors::NEED_REWRITE;
911909

912-
if (last_client < CLIENT_VERSION) // Update
910+
if (!has_last_client || last_client < CLIENT_VERSION) // Update
913911
m_batch->Write(DBKeys::VERSION, CLIENT_VERSION);
914912

915913
if (wss.fAnyUnordered)

0 commit comments

Comments
 (0)