@@ -71,10 +71,17 @@ void generateFakeBlock(const CChainParams& params,
71
71
coinbase_tx.vin [0 ].prevout .SetNull ();
72
72
coinbase_tx.vout .resize (2 );
73
73
coinbase_tx.vout [0 ].scriptPubKey = coinbase_out_script;
74
- coinbase_tx.vout [0 ].nValue = 49 * COIN;
74
+ coinbase_tx.vout [0 ].nValue = 48 * COIN;
75
75
coinbase_tx.vin [0 ].scriptSig = CScript () << ++tip.tip_height << OP_0;
76
76
coinbase_tx.vout [1 ].scriptPubKey = coinbase_out_script; // extra output
77
77
coinbase_tx.vout [1 ].nValue = 1 * COIN;
78
+
79
+ // Fill the coinbase with outputs that don't belong to the wallet in order to benchmark
80
+ // AvailableCoins' behavior with unnecessary TXOs
81
+ for (int i = 0 ; i < 50 ; ++i) {
82
+ coinbase_tx.vout .emplace_back (1 * COIN / 50 , CScript (OP_TRUE));
83
+ }
84
+
78
85
block.vtx = {MakeTransactionRef (std::move (coinbase_tx))};
79
86
80
87
block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
@@ -129,14 +136,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
129
136
130
137
// Check available balance
131
138
auto bal = WITH_LOCK (wallet.cs_wallet , return wallet::AvailableCoins (wallet).GetTotalAmount ()); // Cache
132
- assert (bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
139
+ assert (bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
133
140
134
141
wallet::CCoinControl coin_control;
135
142
coin_control.m_allow_other_inputs = allow_other_inputs;
136
143
137
144
CAmount target = 0 ;
138
145
if (preset_inputs) {
139
- // Select inputs, each has 49 BTC
146
+ // Select inputs, each has 48 BTC
140
147
wallet::CoinFilterParams filter_coins;
141
148
filter_coins.max_count = preset_inputs->num_of_internal_inputs ;
142
149
const auto & res = WITH_LOCK (wallet.cs_wallet ,
@@ -152,7 +159,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
152
159
if (coin_control.m_allow_other_inputs ) target += 50 * COIN;
153
160
std::vector<wallet::CRecipient> recipients = {{dest, target, true }};
154
161
155
- bench.epochIterations ( 5 ). run ([&] {
162
+ bench.run ([&] {
156
163
LOCK (wallet.cs_wallet );
157
164
const auto & tx_res = CreateTransaction (wallet, recipients, /* change_pos=*/ std::nullopt, coin_control);
158
165
assert (tx_res);
@@ -189,9 +196,9 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
189
196
190
197
// Check available balance
191
198
auto bal = WITH_LOCK (wallet.cs_wallet , return wallet::AvailableCoins (wallet).GetTotalAmount ()); // Cache
192
- assert (bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
199
+ assert (bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
193
200
194
- bench.epochIterations ( 2 ). run ([&] {
201
+ bench.run ([&] {
195
202
LOCK (wallet.cs_wallet );
196
203
const auto & res = wallet::AvailableCoins (wallet);
197
204
assert (res.All ().size () == (chain_size - COINBASE_MATURITY) * 2 );
0 commit comments