44
55#include < bench/bench.h>
66#include < interfaces/chain.h>
7- #include < wallet/wallet.h>
87#include < wallet/coinselection.h>
8+ #include < wallet/wallet.h>
99
1010#include < set>
1111
12- static void addCoin (const CAmount& nValue, const CWallet& wallet, std::vector<OutputGroup>& groups )
12+ static void addCoin (const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs )
1313{
14- int nInput = 0 ;
15-
1614 static int nextLockTime = 0 ;
1715 CMutableTransaction tx;
1816 tx.nLockTime = nextLockTime++; // so all transactions get different hashes
19- tx.vout .resize (nInput + 1 );
20- tx.vout [nInput].nValue = nValue;
21- CWalletTx* wtx = new CWalletTx (&wallet, MakeTransactionRef (std::move (tx)));
22-
23- int nAge = 6 * 24 ;
24- COutput output (wtx, nInput, nAge, true /* spendable */ , true /* solvable */ , true /* safe */ );
25- groups.emplace_back (output.GetInputCoin (), 6 , false , 0 , 0 );
17+ tx.vout .resize (1 );
18+ tx.vout [0 ].nValue = nValue;
19+ wtxs.push_back (MakeUnique<CWalletTx>(&wallet, MakeTransactionRef (std::move (tx))));
2620}
2721
2822// Simple benchmark for wallet coin selection. Note that it maybe be necessary
@@ -36,14 +30,21 @@ static void CoinSelection(benchmark::State& state)
3630{
3731 auto chain = interfaces::MakeChain ();
3832 const CWallet wallet (*chain, WalletLocation (), WalletDatabase::CreateDummy ());
33+ std::vector<std::unique_ptr<CWalletTx>> wtxs;
3934 LOCK (wallet.cs_wallet );
4035
4136 // Add coins.
42- std::vector<OutputGroup> groups;
4337 for (int i = 0 ; i < 1000 ; ++i) {
44- addCoin (1000 * COIN, wallet, groups);
38+ addCoin (1000 * COIN, wallet, wtxs);
39+ }
40+ addCoin (3 * COIN, wallet, wtxs);
41+
42+ // Create groups
43+ std::vector<OutputGroup> groups;
44+ for (const auto & wtx : wtxs) {
45+ COutput output (wtx.get (), 0 /* iIn */ , 6 * 24 /* nDepthIn */ , true /* spendable */ , true /* solvable */ , true /* safe */ );
46+ groups.emplace_back (output.GetInputCoin (), 6 , false , 0 , 0 );
4547 }
46- addCoin (3 * COIN, wallet, groups);
4748
4849 const CoinEligibilityFilter filter_standard (1 , 6 , 0 );
4950 const CoinSelectionParams coin_selection_params (true , 34 , 148 , CFeeRate (0 ), 0 );
0 commit comments