mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 16:22:41 +02:00
bench: add benchmark for wallet 'AvailableCoins' function.
This commit is contained in:
@@ -132,11 +132,51 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
|
||||
});
|
||||
}
|
||||
|
||||
static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type)
|
||||
{
|
||||
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||
CWallet wallet{test_setup->m_node.chain.get(), "", gArgs, CreateMockWalletDatabase()};
|
||||
{
|
||||
LOCK(wallet.cs_wallet);
|
||||
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||
wallet.SetupDescriptorScriptPubKeyMans();
|
||||
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
|
||||
}
|
||||
|
||||
// Generate destinations
|
||||
std::vector<CScript> dest_wallet;
|
||||
for (auto type : output_type) {
|
||||
dest_wallet.emplace_back(GetScriptForDestination(getNewDestination(wallet, type)));
|
||||
}
|
||||
|
||||
// Generate chain; each coinbase will have two outputs to fill-up the wallet
|
||||
const auto& params = Params();
|
||||
unsigned int chain_size = 1000;
|
||||
for (unsigned int i = 0; i < chain_size / dest_wallet.size(); ++i) {
|
||||
for (const auto& dest : dest_wallet) {
|
||||
generateFakeBlock(params, test_setup->m_node, wallet, dest);
|
||||
}
|
||||
}
|
||||
|
||||
// Check available balance
|
||||
auto bal = wallet::GetAvailableBalance(wallet); // Cache
|
||||
assert(bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
|
||||
|
||||
bench.epochIterations(2).run([&] {
|
||||
LOCK(wallet.cs_wallet);
|
||||
const auto& res = wallet::AvailableCoins(wallet);
|
||||
assert(res.All().size() == (chain_size - COINBASE_MATURITY) * 2);
|
||||
});
|
||||
}
|
||||
|
||||
static void WalletCreateTxUseOnlyPresetInputs(benchmark::Bench& bench) { WalletCreateTx(bench, OutputType::BECH32, /*allow_other_inputs=*/false,
|
||||
{{/*num_of_internal_inputs=*/4}}); }
|
||||
|
||||
static void WalletCreateTxUsePresetInputsAndCoinSelection(benchmark::Bench& bench) { WalletCreateTx(bench, OutputType::BECH32, /*allow_other_inputs=*/true,
|
||||
{{/*num_of_internal_inputs=*/4}}); }
|
||||
|
||||
static void WalletAvailableCoins(benchmark::Bench& bench) { AvailableCoins(bench, {OutputType::BECH32M}); }
|
||||
|
||||
BENCHMARK(WalletCreateTxUseOnlyPresetInputs, benchmark::PriorityLevel::LOW)
|
||||
BENCHMARK(WalletCreateTxUsePresetInputsAndCoinSelection, benchmark::PriorityLevel::LOW)
|
||||
BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
|
Reference in New Issue
Block a user