Skip to content

Commit e02f2d3

Browse files
committed
bench: Have AvailableCoins benchmark include a lot of unrelated utxos
One of the main issues with AvailableCoins is its performance when txs have unrelated outputs, so update the benchmark to check the performance of that.
1 parent f27898c commit e02f2d3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/bench/wallet_create_tx.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ void generateFakeBlock(const CChainParams& params,
7171
coinbase_tx.vin[0].prevout.SetNull();
7272
coinbase_tx.vout.resize(2);
7373
coinbase_tx.vout[0].scriptPubKey = coinbase_out_script;
74-
coinbase_tx.vout[0].nValue = 49 * COIN;
74+
coinbase_tx.vout[0].nValue = 48 * COIN;
7575
coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
7676
coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output
7777
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+
7885
block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
7986

8087
block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
@@ -129,14 +136,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
129136

130137
// Check available balance
131138
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));
133140

134141
wallet::CCoinControl coin_control;
135142
coin_control.m_allow_other_inputs = allow_other_inputs;
136143

137144
CAmount target = 0;
138145
if (preset_inputs) {
139-
// Select inputs, each has 49 BTC
146+
// Select inputs, each has 48 BTC
140147
wallet::CoinFilterParams filter_coins;
141148
filter_coins.max_count = preset_inputs->num_of_internal_inputs;
142149
const auto& res = WITH_LOCK(wallet.cs_wallet,
@@ -152,7 +159,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
152159
if (coin_control.m_allow_other_inputs) target += 50 * COIN;
153160
std::vector<wallet::CRecipient> recipients = {{dest, target, true}};
154161

155-
bench.epochIterations(5).run([&] {
162+
bench.run([&] {
156163
LOCK(wallet.cs_wallet);
157164
const auto& tx_res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
158165
assert(tx_res);
@@ -189,9 +196,9 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
189196

190197
// Check available balance
191198
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));
193200

194-
bench.epochIterations(2).run([&] {
201+
bench.run([&] {
195202
LOCK(wallet.cs_wallet);
196203
const auto& res = wallet::AvailableCoins(wallet);
197204
assert(res.All().size() == (chain_size - COINBASE_MATURITY) * 2);

0 commit comments

Comments
 (0)