aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-11-14 10:55:10 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2022-12-15 15:42:39 -0300
commit3a4f8bc24271d05765e9bf1e26558a28ab2e6b81 (patch)
tree19644729bb0381dd0e5efe1ea58cd24f9a588ef8 /src/bench
parent48174c0f287b19931ca110670610bd03a03eb914 (diff)
bench: add benchmark for wallet 'AvailableCoins' function.
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/wallet_create_tx.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp
index 207b22c584..e33b1509a6 100644
--- a/src/bench/wallet_create_tx.cpp
+++ b/src/bench/wallet_create_tx.cpp
@@ -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); \ No newline at end of file