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.
This commit is contained in:
1 parent
f27898c8bf
commit
e02f2d331c
1 file changed
+13
-6
@@ -71,10 +71,17 @@ void generateFakeBlock(const CChainParams& params,
|
|||||||
coinbase_tx.vin[0].prevout.SetNull();
|
coinbase_tx.vin[0].prevout.SetNull();
|
||||||
coinbase_tx.vout.resize(2);
|
coinbase_tx.vout.resize(2);
|
||||||
coinbase_tx.vout[0].scriptPubKey = coinbase_out_script;
|
coinbase_tx.vout[0].scriptPubKey = coinbase_out_script;
|
||||||
coinbase_tx.vout[0].nValue = 49 * COIN;
|
coinbase_tx.vout[0].nValue = 48 * COIN;
|
||||||
coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
|
coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0;
|
||||||
coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output
|
coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output
|
||||||
coinbase_tx.vout[1].nValue = 1 * COIN;
|
coinbase_tx.vout[1].nValue = 1 * COIN;
|
||||||
|
|
||||||
|
// Fill the coinbase with outputs that don't belong to the wallet in order to benchmark
|
||||||
|
// AvailableCoins' behavior with unnecessary TXOs
|
||||||
|
for (int i = 0; i < 50; ++i) {
|
||||||
|
coinbase_tx.vout.emplace_back(1 * COIN / 50, CScript(OP_TRUE));
|
||||||
|
}
|
||||||
|
|
||||||
block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
|
block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
|
||||||
|
|
||||||
block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
|
block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
|
||||||
@@ -129,14 +136,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
|
|||||||
|
|
||||||
// Check available balance
|
// Check available balance
|
||||||
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
|
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
|
||||||
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
|
assert(bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
|
||||||
|
|
||||||
wallet::CCoinControl coin_control;
|
wallet::CCoinControl coin_control;
|
||||||
coin_control.m_allow_other_inputs = allow_other_inputs;
|
coin_control.m_allow_other_inputs = allow_other_inputs;
|
||||||
|
|
||||||
CAmount target = 0;
|
CAmount target = 0;
|
||||||
if (preset_inputs) {
|
if (preset_inputs) {
|
||||||
// Select inputs, each has 49 BTC
|
// Select inputs, each has 48 BTC
|
||||||
wallet::CoinFilterParams filter_coins;
|
wallet::CoinFilterParams filter_coins;
|
||||||
filter_coins.max_count = preset_inputs->num_of_internal_inputs;
|
filter_coins.max_count = preset_inputs->num_of_internal_inputs;
|
||||||
const auto& res = WITH_LOCK(wallet.cs_wallet,
|
const auto& res = WITH_LOCK(wallet.cs_wallet,
|
||||||
@@ -152,7 +159,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
|
|||||||
if (coin_control.m_allow_other_inputs) target += 50 * COIN;
|
if (coin_control.m_allow_other_inputs) target += 50 * COIN;
|
||||||
std::vector<wallet::CRecipient> recipients = {{dest, target, true}};
|
std::vector<wallet::CRecipient> recipients = {{dest, target, true}};
|
||||||
|
|
||||||
bench.epochIterations(5).run([&] {
|
bench.run([&] {
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
const auto& tx_res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
|
const auto& tx_res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control);
|
||||||
assert(tx_res);
|
assert(tx_res);
|
||||||
@@ -189,9 +196,9 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
|
|||||||
|
|
||||||
// Check available balance
|
// Check available balance
|
||||||
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
|
auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache
|
||||||
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
|
assert(bal == 49 * COIN * (chain_size - COINBASE_MATURITY));
|
||||||
|
|
||||||
bench.epochIterations(2).run([&] {
|
bench.run([&] {
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
const auto& res = wallet::AvailableCoins(wallet);
|
const auto& res = wallet::AvailableCoins(wallet);
|
||||||
assert(res.All().size() == (chain_size - COINBASE_MATURITY) * 2);
|
assert(res.All().size() == (chain_size - COINBASE_MATURITY) * 2);
|
||||||
|
|||||||
Reference in new issue
Block a user