bench: Utilize setup() in WalletCreate to cleanup previous wallets
What changed, and why it matters
This is a small code-quality change to a benchmark test that measures how long it takes to create a Bitcoin wallet. It moves wallet cleanup from inside the timed loop to a setup/teardown phase so the benchmark only measures wallet creation. There is no user-facing behavior change and no security relevance.
No security action needed; treat as normal benchmark maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors src/bench/wallet_create.cpp so that RemoveWallet/WaitForDeleteWallet/filesystem cleanup is performed in a bench.setup() lambda and once after bench.run(), rather than inside the benchmarked lambda. This changes what is being measured (creation only, not cleanup) but does not alter CreateWallet/RemoveWallet semantics, error handling, or any production code path.
Changed components
src/bench/wallet_create.cppInspect captured patch +10 / −6
diff --git a/src/bench/wallet_create.cpp b/src/bench/wallet_create.cpp
index d29ef339..11244fe8 100644
--- a/src/bench/wallet_create.cpp
+++ b/src/bench/wallet_create.cpp
@@ -47,17 +47,21 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
const auto wallet_path = test_setup->m_path_root / "test_wallet";
const auto wallet_name = fs::PathToString(wallet_path);
- bench.run([&] {
- auto wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
- assert(status == DatabaseStatus::SUCCESS);
- assert(wallet != nullptr);
-
+ std::shared_ptr<CWallet> wallet;
+ auto cleanup{[&] {
+ if (!wallet) return;
// Release wallet
- RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
+ RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt);
WaitForDeleteWallet(std::move(wallet));
fs::remove(wallet_path / "wallet.dat");
fs::remove(wallet_path);
+ }};
+ bench.setup(cleanup).run([&] {
+ wallet = CreateWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
+ assert(status == DatabaseStatus::SUCCESS);
+ assert(wallet != nullptr);
});
+ cleanup();
}
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
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.