bench: Utilize setup() for WalletLoading and use a real database
What changed, and why it matters
This change only modifies a benchmark test file. It swaps a fake/mock database for a real SQLite database when measuring how fast wallet loading runs, and moves wallet setup work outside the timed portion so the benchmark is more accurate. There is no change to production wallet code, network behavior, or user-facing functionality, and no security issue is evident.
No security action needed. Review as ordinary benchmark refactoring if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates src/bench/wallet_loading.cpp. It replaces CreateMockableWalletDatabase()/DuplicateMockDatabase() with MakeWalletDatabase() using SQLite, and uses the benchmark framework’s setup() callback to unload/re-open the database before each timed epoch. The timed run now only calls TestLoadWallet(). This is a test-infrastructure quality improvement, not a functional code change.
Changed components
src/bench/wallet_loading.cppInspect captured patch +18 / −11
diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp
index 20997ff8..09028acd 100644
--- a/src/bench/wallet_loading.cpp
+++ b/src/bench/wallet_loading.cpp
@@ -42,7 +42,12 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench)
// Setup the wallet
// Loading the wallet will also create it
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
- auto database = CreateMockableWalletDatabase();
+ DatabaseStatus status;
+ DatabaseOptions options;
+ options.require_format = DatabaseFormat::SQLITE;
+ options.require_create = true;
+ bilingual_str error;
+ auto database = MakeWalletDatabase("", options, status, error);
auto wallet = TestCreateWallet(std::move(database), context, create_flags);
// Generate a bunch of transactions and addresses to put into the wallet
@@ -50,18 +55,20 @@ static void WalletLoadingDescriptors(benchmark::Bench& bench)
AddTx(*wallet);
}
- database = DuplicateMockDatabase(wallet->GetDatabase());
+ options.require_create = false;
+ options.require_existing = true;
- // reload the wallet for the actual benchmark
- TestUnloadWallet(std::move(wallet));
-
- bench.epochs(5).run([&] {
- wallet = TestLoadWallet(std::move(database), context);
+ bench.epochs(5)
+ .setup([&] {
+ TestUnloadWallet(std::move(wallet));
+ database = MakeWalletDatabase("", options, status, error);
+ })
+ .run([&] {
+ wallet = TestLoadWallet(std::move(database), context);
+ });
- // Cleanup
- database = DuplicateMockDatabase(wallet->GetDatabase());
- TestUnloadWallet(std::move(wallet));
- });
+ // Cleanup
+ TestUnloadWallet(std::move(wallet));
}
BENCHMARK(WalletLoadingDescriptors);
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.