bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase
What changed, and why it matters
This commit is a small internal cleanup in Bitcoin Core's benchmark code. It swaps a test-only mock wallet database helper for a real in-memory SQLite database helper in five benchmark files. There is no change to production wallet code, no change to how real user wallets are stored, and no security fix or vulnerability introduced.
No security action required. Review as normal code-quality/refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit replaces CreateMockableWalletDatabase() with MakeInMemoryWalletDatabase() in src/bench/ files. CreateMockableWalletDatabase is a test/bench helper that returns a mock SQLite database with overridden Filename(), Format(), and an exposed WriteKey() method. MakeInMemoryWalletDatabase() uses the same in-memory SQLite path as production code. The change removes benchmark dependence on mock-specific behavior, except in wallet_migration.cpp which still needs the mock format signal. Includes are updated to pull in <wallet/sqlite.h> where needed. This is purely a refactoring of benchmark fixtures.
Changed components
src/bench/coin_selection.cppsrc/bench/wallet_balance.cppsrc/bench/wallet_create_tx.cppsrc/bench/wallet_encrypt.cppsrc/bench/wallet_ismine.cppInspect captured patch +12 / −8
diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp
index 4f203fe8..5c54cafc 100644
--- a/src/bench/coin_selection.cpp
+++ b/src/bench/coin_selection.cpp
@@ -16,7 +16,7 @@
#include <wallet/coinselection.h>
#include <wallet/db.h>
#include <wallet/spend.h>
-#include <wallet/test/util.h>
+#include <wallet/sqlite.h>
#include <wallet/transaction.h>
#include <wallet/wallet.h>
@@ -50,7 +50,7 @@ static void addCoin(const CAmount& nValue, std::vector<std::unique_ptr<CWalletTx
static void CoinSelection(benchmark::Bench& bench)
{
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
- CWallet wallet(test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase());
+ CWallet wallet(test_setup->m_node.chain.get(), "", MakeInMemoryWalletDatabase());
std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet);
diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp
index 958044e2..76d0fd39 100644
--- a/src/bench/wallet_balance.cpp
+++ b/src/bench/wallet_balance.cpp
@@ -17,6 +17,7 @@
#include <validation.h>
#include <wallet/db.h>
#include <wallet/receive.h>
+#include <wallet/sqlite.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>
#include <wallet/walletutil.h>
@@ -35,7 +36,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
// The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past.
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
- CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
+ CWallet wallet{test_setup->m_node.chain.get(), "", MakeInMemoryWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp
index 394f21ce..b0140910 100644
--- a/src/bench/wallet_create_tx.cpp
+++ b/src/bench/wallet_create_tx.cpp
@@ -29,6 +29,7 @@
#include <wallet/coinselection.h>
#include <wallet/db.h>
#include <wallet/spend.h>
+#include <wallet/sqlite.h>
#include <wallet/test/util.h>
#include <wallet/types.h>
#include <wallet/wallet.h>
@@ -44,7 +45,7 @@
using kernel::ChainstateRole;
using wallet::CWallet;
-using wallet::CreateMockableWalletDatabase;
+using wallet::MakeInMemoryWalletDatabase;
using wallet::WALLET_FLAG_DESCRIPTORS;
struct TipBlock
@@ -120,7 +121,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
- CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
+ CWallet wallet{test_setup->m_node.chain.get(), "", MakeInMemoryWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
@@ -175,7 +176,7 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
- CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
+ CWallet wallet{test_setup->m_node.chain.get(), "", MakeInMemoryWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
diff --git a/src/bench/wallet_encrypt.cpp b/src/bench/wallet_encrypt.cpp
index 81e64a28..7f6ff3af 100644
--- a/src/bench/wallet_encrypt.cpp
+++ b/src/bench/wallet_encrypt.cpp
@@ -16,6 +16,7 @@
#include <wallet/context.h>
#include <wallet/crypter.h>
#include <wallet/db.h>
+#include <wallet/sqlite.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>
#include <wallet/walletutil.h>
@@ -64,7 +65,7 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)
TestUnloadWallet(std::move(wallet));
}
- std::unique_ptr<WalletDatabase> database = CreateMockableWalletDatabase();
+ std::unique_ptr<WalletDatabase> database = MakeInMemoryWalletDatabase();
wallet = TestCreateWallet(std::move(database), context, create_flags);
{
diff --git a/src/bench/wallet_ismine.cpp b/src/bench/wallet_ismine.cpp
index 572a2717..4b059b34 100644
--- a/src/bench/wallet_ismine.cpp
+++ b/src/bench/wallet_ismine.cpp
@@ -14,6 +14,7 @@
#include <util/check.h>
#include <wallet/context.h>
#include <wallet/db.h>
+#include <wallet/sqlite.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>
#include <wallet/walletutil.h>
@@ -37,7 +38,7 @@ static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)
// Setup the wallet
// Loading the wallet will also create it
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
- auto database = CreateMockableWalletDatabase();
+ auto database = MakeInMemoryWalletDatabase();
auto wallet = TestCreateWallet(std::move(database), context, create_flags);
// For a descriptor wallet, fill with num_combo combo descriptors with random keys
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.