refactor: wallet: Factor out `WriteVersion()` from `PopulateWalletFromDB()`
What changed, and why it matters
This is a small, safe code cleanup in Bitcoin Core's wallet database code. It moves the logic that writes the wallet's version marker into its own reusable function, with no change to what data is actually written. There is no security issue here.
No action required. This is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors WalletBatch by extracting a WriteVersion(int client_version) helper that wraps m_batch->Write(DBKeys::VERSION, CLIENT_VERSION). The existing call site in LoadWallet() is updated to use the new helper. The behavior is identical: the same key and the same constant value are written. The change is preparatory for a follow-up commit that will remove PopulateWalletFromDB() from wallet creation and needs to preserve the version write.
Changed components
src/wallet/walletdb.cppsrc/wallet/walletdb.hInspect captured patch +4 / −1
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 9ca4d2da..38756828 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -1175,7 +1175,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
return result;
if (!has_last_client || last_client != CLIENT_VERSION) // Update
- m_batch->Write(DBKeys::VERSION, CLIENT_VERSION);
+ this->WriteVersion(CLIENT_VERSION);
if (any_unordered)
result = pwallet->ReorderTransactions();
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index a867a28b..788d4486 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -265,6 +265,9 @@ public:
DBErrors LoadWallet(CWallet* pwallet);
+ //! Write the given client_version.
+ bool WriteVersion(int client_version) { return m_batch->Write(DBKeys::VERSION, CLIENT_VERSION); }
+
//! Delete records of the given types
bool EraseRecords(const std::unordered_set<std::string>& types);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.