diff options
author | MacroFake <falke.marco@gmail.com> | 2022-06-30 18:38:11 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-06-30 18:38:20 +0200 |
commit | c892cb7d8d8de0d4e1d414346ae4bad016f61917 (patch) | |
tree | 227393c1ff0c66ffd0354c19718aa22029332dfa /src | |
parent | 5d68d6840d9ca82754dc66e96d1cf1444b830c9d (diff) | |
parent | c318211ddd48d44dd81dded553afeee3bc41c89e (diff) | |
download | bitcoin-c892cb7d8d8de0d4e1d414346ae4bad016f61917.tar.xz |
Merge bitcoin/bitcoin#25383: wallet: don't read db every time that a new 'WalletBatch' is created
c318211ddd48d44dd81dded553afeee3bc41c89e walletdb: fix last client version update (furszy)
bda8ebe608e6572eaaf40cd28dab6954241c9b0d wallet: don't read db every time that a new WalletBatch is created (furszy)
Pull request description:
Found it while was working on #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 c318211ddd48d44dd81dded553afeee3bc41c89e
w0xlt:
reACK https://github.com/bitcoin/bitcoin/pull/25383/commits/c318211ddd48d44dd81dded553afeee3bc41c89e
Tree-SHA512: 7fb780c656e169e8eb21e7212242494a647f6506d6da2cca828703713d440d29c82bec9e7d2c410f37b49361226ccd80846d3eeb8168383d0c2a11d85d73bee2
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/bdb.cpp | 6 | ||||
-rw-r--r-- | src/wallet/walletdb.cpp | 10 |
2 files changed, 4 insertions, 12 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index f8230f7a1d..dbd768a758 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -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() diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index a04446c840..8afd3f416d 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -883,12 +883,10 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet) if (result != DBErrors::LOAD_OK) return result; - // Last client version to open this wallet, was previously the file version number + // Last client version to open this wallet 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); @@ -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) |