refactor: Wallet stats logging in its own function
What changed, and why it matters
This commit is a simple code cleanup: it moves three existing wallet logging lines into a new helper function called LogStats(). There is no change to what is logged, no change to security behavior, and no bug fix.
No security action needed; this is a routine refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors wallet statistics logging in CWallet::Create by extracting repeated WalletLogPrintf calls into a new inline method LogStats() in wallet.h. The new method is annotated EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) and calls AssertLockHeld(cs_wallet). The WITH_LOCK macro in wallet.cpp preserves the existing locking behavior. No functional or security-relevant changes are introduced.
Changed components
src/wallet/wallet.cppsrc/wallet/wallet.hInspect captured patch +9 / −6
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index a0138381..8ee2302c 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3093,12 +3093,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
return nullptr;
}
- {
- LOCK(walletInstance->cs_wallet);
- walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());
- walletInstance->WalletLogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size());
- walletInstance->WalletLogPrintf("m_address_book.size() = %u\n", walletInstance->m_address_book.size());
- }
+ WITH_LOCK(walletInstance->cs_wallet, walletInstance->LogStats());
return walletInstance;
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 27ce8957..e4072c44 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -940,6 +940,14 @@ public:
LogInfo("[%s] %s", LogName(), tfm::format(wallet_fmt, params...));
};
+ void LogStats() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
+ {
+ AssertLockHeld(cs_wallet);
+ WalletLogPrintf("setKeyPool.size() = %u\n", GetKeyPoolSize());
+ WalletLogPrintf("mapWallet.size() = %u\n", mapWallet.size());
+ WalletLogPrintf("m_address_book.size() = %u\n", m_address_book.size());
+ };
+
//! Returns all unique ScriptPubKeyMans in m_internal_spk_managers and m_external_spk_managers
std::set<ScriptPubKeyMan*> GetActiveScriptPubKeyMans() const;
bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan& spkm) const;
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.