wallet, bench: Use TestingSetup in CoinSelection benchmark
What changed, and why it matters
This commit changes only a benchmark test file used to measure wallet coin-selection performance. It swaps a manually created test chain for the standard TestingSetup helper and wraps the code in a wallet namespace. There is no change to production wallet code, consensus rules, networking, or any code that handles real user funds. It is a test-code cleanup with no security relevance.
No security action needed. Treat as normal code-quality/test-maintenance change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies src/bench/coin_selection.cpp. It removes a local NodeContext and MakeChain() setup in the CoinSelection benchmark and replaces it with MakeNoLogFileContext
Changed components
src/bench/coin_selection.cppInspect captured patch +6 / −16
diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp
index 2f108a31..6d0d89e4 100644
--- a/src/bench/coin_selection.cpp
+++ b/src/bench/coin_selection.cpp
@@ -12,8 +12,10 @@
#include <primitives/transaction.h>
#include <random.h>
#include <sync.h>
+#include <test/util/setup_common.h>
#include <util/result.h>
#include <wallet/coinselection.h>
+#include <wallet/context.h>
#include <wallet/spend.h>
#include <wallet/test/util.h>
#include <wallet/transaction.h>
@@ -26,19 +28,7 @@
#include <utility>
#include <vector>
-using node::NodeContext;
-using wallet::AttemptSelection;
-using wallet::CHANGE_LOWER;
-using wallet::COutput;
-using wallet::CWallet;
-using wallet::CWalletTx;
-using wallet::CoinEligibilityFilter;
-using wallet::CoinSelectionParams;
-using wallet::CreateMockableWalletDatabase;
-using wallet::OutputGroup;
-using wallet::SelectCoinsBnB;
-using wallet::TxStateInactive;
-
+namespace wallet {
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
{
static int nextLockTime = 0;
@@ -58,9 +48,8 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<st
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CoinSelection(benchmark::Bench& bench)
{
- NodeContext node;
- auto chain = interfaces::MakeChain(node);
- CWallet wallet(chain.get(), "", CreateMockableWalletDatabase());
+ const auto test_setup = MakeNoLogFileContext<TestingSetup>();
+ CWallet wallet(test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase());
std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet);
@@ -139,3 +128,4 @@ static void BnBExhaustion(benchmark::Bench& bench)
BENCHMARK(CoinSelection);
BENCHMARK(BnBExhaustion);
+}; // namespace wallet
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.