Skip to content

Commit

Permalink
wallet: don't read db every time that a new WalletBatch is created
Browse files Browse the repository at this point in the history
Better to perform the action only one time (during 'LoadWallet').
Where the value is being used.
  • Loading branch information
furszy committed Jun 16, 2022
1 parent 26ec2f2 commit bda8ebe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/wallet/bdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,6 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, b
env = database.env.get();
pdb = database.m_db.get();
strFile = fs::PathToString(database.m_filename);
if (!Exists(std::string("version"))) {
bool fTmp = fReadOnly;
fReadOnly = false;
Write(std::string("version"), CLIENT_VERSION);
fReadOnly = fTmp;
}
}

void BerkeleyDatabase::Open()
Expand Down
8 changes: 3 additions & 5 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,8 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)

// Last client version to open this wallet, was previously the file version number
int last_client = CLIENT_VERSION;
m_batch->Read(DBKeys::VERSION, last_client);

int wallet_version = pwallet->GetVersion();
pwallet->WalletLogPrintf("Wallet File Version = %d\n", wallet_version > 0 ? wallet_version : last_client);
bool has_last_client = m_batch->Read(DBKeys::VERSION, last_client);
pwallet->WalletLogPrintf("Wallet file version = %d, last client version = %d\n", pwallet->GetVersion(), last_client);

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

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

if (wss.fAnyUnordered)
Expand Down

0 comments on commit bda8ebe

Please sign in to comment.