From bc69070416c62a88d8f4029280ec10d6f9ec8d20 Mon Sep 17 00:00:00 2001 From: David Gumberg Date: Tue, 27 May 2025 16:46:00 -0700 Subject: [PATCH] refactor: Wallet stats logging in its own function This will avoid repetition when wallet creation and loading are separated. --- src/wallet/wallet.cpp | 7 +------ src/wallet/wallet.h | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a0138381d81..8ee2302c121 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3093,12 +3093,7 @@ std::shared_ptr 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 27ce8957ff2..e4072c44a85 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 GetActiveScriptPubKeyMans() const; bool IsActiveScriptPubKeyMan(const ScriptPubKeyMan& spkm) const;