This benchmark is based on a large diverse UTXO pool. The UTXOs are pseudorandomly generated and assigned one of the four relevant output types P2PKH, P2SH-P2WPKH, P2WPKH, and P2TR UTXOs. Smaller amounts are more likely to be generated than larger amounts. This UTXO pool is used to run coin selection for pseudorandom selection targets. Altogether, this gives us a deterministic benchmark with a som
| 48 | // Altogether, this gives us a deterministic benchmark with a somewhat |
| 49 | // representative coin selection scenario. |
| 50 | static void CoinSelection(benchmark::Bench& bench) |
| 51 | { |
| 52 | const auto test_setup = MakeNoLogFileContext<TestingSetup>(); |
| 53 | CWallet wallet(test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()); |
| 54 | std::vector<std::unique_ptr<CWalletTx>> wtxs; |
| 55 | LOCK(wallet.cs_wallet); |
| 56 | |
| 57 | // Keep selection deterministic for benchmark stability |
| 58 | FastRandomContext det_rand{/*fDeterministic=*/true}; |
| 59 | |
| 60 | // Generate coin amounts biased towards smaller amounts |
| 61 | for (int i = 0; i < 400; ++i) { |
| 62 | CAmount amount; |
| 63 | int p{det_rand.randrange(100)}; |
| 64 | if (p < 50) { |
| 65 | amount = 10'000 + det_rand.randrange(90'000); |
| 66 | } else if (p < 75) { |
| 67 | amount = 100'000 + det_rand.randrange(900'000); |
| 68 | } else if (p < 95) { |
| 69 | amount = 1'000'000 + det_rand.randrange(9'000'000); |
| 70 | } else { |
| 71 | amount = 10'000'000 + det_rand.randrange(90'000'000); |
| 72 | } |
| 73 | addCoin(amount, wtxs); |
| 74 | } |
| 75 | |
| 76 | // Create coins from the amounts assigning them various output types |
| 77 | wallet::CoinsResult available_coins; |
| 78 | for (const auto& wtx : wtxs) { |
| 79 | const auto txout = wtx->tx->vout.at(0); |
| 80 | OutputType outtype; |
| 81 | int input_bytes; |
| 82 | int y{det_rand.randrange(100)}; |
| 83 | if (y < 35) { |
| 84 | outtype = OutputType::LEGACY; |
| 85 | input_bytes = 148; |
| 86 | } else if (y < 55) { |
| 87 | outtype = OutputType::P2SH_SEGWIT; |
| 88 | input_bytes = 91; |
| 89 | } else if (y < 90) { |
| 90 | outtype = OutputType::BECH32; |
| 91 | input_bytes = 68; |
| 92 | } else { |
| 93 | outtype = OutputType::BECH32M; |
| 94 | input_bytes = 58; |
| 95 | } |
| 96 | CAmount fees = 20 * input_bytes; |
| 97 | available_coins.coins[outtype].emplace_back(COutPoint(wtx->GetHash(), 0), txout, /*depth=*/6 * 24, /*input_bytes=*/input_bytes, /*solvable=*/true, /*safe=*/true, wtx->GetTxTime(), /*from_me=*/true, /*fees=*/fees); |
| 98 | } |
| 99 | |
| 100 | const CoinEligibilityFilter filter_standard(/*conf_mine=*/1, /*conf_theirs=*/6, /*max_ancestors=*/0); |
| 101 | |
| 102 | constexpr size_t NUM_TARGETS{10}; |
| 103 | std::vector<CAmount> targets; |
| 104 | targets.reserve(NUM_TARGETS); |
| 105 | for (size_t i{0}; i < NUM_TARGETS; ++i) { |
| 106 | targets.push_back(10'000'000 + det_rand.randrange(90'000'000)); |
| 107 | } |
nothing calls this directly
no test coverage detected