4
4
5
5
#include < bench/bench.h>
6
6
#include < interfaces/chain.h>
7
- #include < wallet/wallet.h>
8
7
#include < wallet/coinselection.h>
8
+ #include < wallet/wallet.h>
9
9
10
10
#include < set>
11
11
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 )
13
13
{
14
- int nInput = 0 ;
15
-
16
14
static int nextLockTime = 0 ;
17
15
CMutableTransaction tx;
18
16
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))));
26
20
}
27
21
28
22
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
@@ -36,14 +30,21 @@ static void CoinSelection(benchmark::State& state)
36
30
{
37
31
auto chain = interfaces::MakeChain ();
38
32
const CWallet wallet (*chain, WalletLocation (), WalletDatabase::CreateDummy ());
33
+ std::vector<std::unique_ptr<CWalletTx>> wtxs;
39
34
LOCK (wallet.cs_wallet );
40
35
41
36
// Add coins.
42
- std::vector<OutputGroup> groups;
43
37
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 );
45
47
}
46
- addCoin (3 * COIN, wallet, groups);
47
48
48
49
const CoinEligibilityFilter filter_standard (1 , 6 , 0 );
49
50
const CoinSelectionParams coin_selection_params (true , 34 , 148 , CFeeRate (0 ), 0 );
0 commit comments