Skip to content

Commit 910d841

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 389d43d commit 910d841

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/bench/wallet_create_tx.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ void generateFakeBlock(const CChainParams& params,
4747
coinbase_tx.vin[0].prevout.SetNull();
4848
coinbase_tx.vout.resize(2);
4949
coinbase_tx.vout[0].scriptPubKey = coinbase_out_script;
50-
coinbase_tx.vout[0].nValue = 49 * COIN;
50+
coinbase_tx.vout[0].nValue = 48 * COIN;
5151
coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
5252
coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output
5353
coinbase_tx.vout[1].nValue = 1 * COIN;
54+
55+
// Fill the coinbase with outputs that don't belong to the wallet in order to benchmark
56+
// AvailableCoins' behavior with unnecessary TXOs
57+
for (int i = 0; i < 50; ++i) {
58+
coinbase_tx.vout.push_back(CTxOut(1 * COIN / 50, CScript(OP_TRUE)));
59+
}
60+
5461
block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
5562

5663
block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
@@ -105,14 +112,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
105112

106113
// Check available balance
107114
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
108-
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
115+
assert(bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
109116

110117
wallet::CCoinControl coin_control;
111118
coin_control.m_allow_other_inputs = allow_other_inputs;
112119

113120
CAmount target = 0;
114121
if (preset_inputs) {
115-
// Select inputs, each has 49 BTC
122+
// Select inputs, each has 48 BTC
116123
wallet::CoinFilterParams filter_coins;
117124
filter_coins.max_count = preset_inputs->num_of_internal_inputs;
118125
const auto& res = WITH_LOCK(wallet.cs_wallet,
@@ -144,8 +151,8 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
144151
{
145152
LOCK(wallet.cs_wallet);
146153
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
147-
wallet.SetupDescriptorScriptPubKeyMans();
148154
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
155+
wallet.SetupDescriptorScriptPubKeyMans();
149156
}
150157

151158
// Generate destinations
@@ -166,7 +173,7 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
166173

167174
// Check available balance
168175
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
169-
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
176+
assert(bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
170177

171178
bench.epochIterations(2).run([&] {
172179
LOCK(wallet.cs_wallet);
@@ -185,4 +192,4 @@ static void WalletAvailableCoins(benchmark::Bench& bench) { AvailableCoins(bench
185192

186193
BENCHMARK(WalletCreateTxUseOnlyPresetInputs, benchmark::PriorityLevel::LOW)
187194
BENCHMARK(WalletCreateTxUsePresetInputsAndCoinSelection, benchmark::PriorityLevel::LOW)
188-
BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
195+
BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);

0 commit comments

Comments
 (0)