diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -12,21 +12,15 @@ #include static void addCoin(const Amount nValue, const CWallet &wallet, - std::vector &groups) { - int nInput = 0; - + std::vector> &wtxs) { static int nextLockTime = 0; CMutableTransaction tx; // so all transactions get different hashes tx.nLockTime = nextLockTime++; - tx.vout.resize(nInput + 1); - tx.vout[nInput].nValue = nValue; - CWalletTx *wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx))); - - int nAge = 6 * 24; - COutput output(wtx, nInput, nAge, true /* spendable */, true /* solvable */, - true /* safe */); - groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0); + tx.vout.resize(1); + tx.vout[0].nValue = nValue; + wtxs.push_back(std::make_unique( + &wallet, MakeTransactionRef(std::move(tx)))); } // Simple benchmark for wallet coin selection. Note that it maybe be necessary @@ -42,15 +36,23 @@ auto chain = interfaces::MakeChain(); const CWallet wallet(Params(), *chain, WalletLocation(), WalletDatabase::CreateDummy()); - + std::vector> wtxs; LOCK(wallet.cs_wallet); // Add coins. - std::vector groups; for (int i = 0; i < 1000; ++i) { - addCoin(1000 * COIN, wallet, groups); + addCoin(1000 * COIN, wallet, wtxs); + } + addCoin(3 * COIN, wallet, wtxs); + + // Create groups + std::vector groups; + for (const auto &wtx : wtxs) { + COutput output(wtx.get(), 0 /* iIn */, 6 * 24 /* nDepthIn */, + true /* spendable */, true /* solvable */, + true /* safe */); + groups.emplace_back(output.GetInputCoin(), 6, false, 0, 0); } - addCoin(3 * COIN, wallet, groups); const CoinEligibilityFilter filter_standard(1, 6, 0); const CoinSelectionParams coin_selection_params(