| 115 | }; |
| 116 | |
| 117 | static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type, bool allow_other_inputs, std::optional<PreSelectInputs> preset_inputs) |
| 118 | { |
| 119 | const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); |
| 120 | |
| 121 | // Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process. |
| 122 | FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()}; |
| 123 | CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()}; |
| 124 | { |
| 125 | LOCK(wallet.cs_wallet); |
| 126 | wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
| 127 | wallet.SetupDescriptorScriptPubKeyMans(); |
| 128 | } |
| 129 | |
| 130 | // Generate destinations |
| 131 | const auto dest{getNewDestination(wallet, output_type)}; |
| 132 | |
| 133 | // Generate chain; each coinbase will have two outputs to fill-up the wallet |
| 134 | const auto& params = Params(); |
| 135 | const CScript coinbase_out{GetScriptForDestination(dest)}; |
| 136 | unsigned int chain_size = 5000; // 5k blocks means 10k UTXO for the wallet (minus 200 due COINBASE_MATURITY) |
| 137 | for (unsigned int i = 0; i < chain_size; ++i) { |
| 138 | generateFakeBlock(params, test_setup->m_node, wallet, coinbase_out); |
| 139 | } |
| 140 | |
| 141 | // Check available balance |
| 142 | auto bal = WITH_LOCK(wallet.cs_wallet, return wallet::AvailableCoins(wallet).GetTotalAmount()); // Cache |
| 143 | assert(bal == 49 * COIN * (chain_size - COINBASE_MATURITY)); |
| 144 | |
| 145 | wallet::CCoinControl coin_control; |
| 146 | coin_control.m_allow_other_inputs = allow_other_inputs; |
| 147 | |
| 148 | CAmount target = 0; |
| 149 | if (preset_inputs) { |
| 150 | // Select inputs, each has 48 BTC |
| 151 | wallet::CoinFilterParams filter_coins; |
| 152 | filter_coins.max_count = preset_inputs->num_of_internal_inputs; |
| 153 | const auto& res = WITH_LOCK(wallet.cs_wallet, |
| 154 | return wallet::AvailableCoins(wallet, /*coinControl=*/nullptr, /*feerate=*/std::nullopt, filter_coins)); |
| 155 | for (int i=0; i < preset_inputs->num_of_internal_inputs; i++) { |
| 156 | const auto& coin{res.coins.at(output_type)[i]}; |
| 157 | target += coin.txout.nValue; |
| 158 | coin_control.Select(coin.outpoint); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // If automatic coin selection is enabled, add the value of another UTXO to the target |
| 163 | if (coin_control.m_allow_other_inputs) target += 50 * COIN; |
| 164 | std::vector<wallet::CRecipient> recipients = {{dest, target, true}}; |
| 165 | |
| 166 | bench.run([&] { |
| 167 | LOCK(wallet.cs_wallet); |
| 168 | const auto& tx_res = CreateTransaction(wallet, recipients, /*change_pos=*/std::nullopt, coin_control); |
| 169 | assert(tx_res); |
| 170 | }); |
| 171 | } |
| 172 | |
| 173 | static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type) |
| 174 | { |
no test coverage detected