@@ -132,11 +132,51 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
132
132
});
133
133
}
134
134
135
+ static void AvailableCoins (benchmark::Bench& bench, const std::vector<OutputType>& output_type)
136
+ {
137
+ const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
138
+ CWallet wallet{test_setup->m_node .chain .get (), " " , gArgs , CreateMockWalletDatabase ()};
139
+ {
140
+ LOCK (wallet.cs_wallet );
141
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
142
+ wallet.SetupDescriptorScriptPubKeyMans ();
143
+ if (wallet.LoadWallet () != DBErrors::LOAD_OK) assert (false );
144
+ }
145
+
146
+ // Generate destinations
147
+ std::vector<CScript> dest_wallet;
148
+ for (auto type : output_type) {
149
+ dest_wallet.emplace_back (GetScriptForDestination (getNewDestination (wallet, type)));
150
+ }
151
+
152
+ // Generate chain; each coinbase will have two outputs to fill-up the wallet
153
+ const auto & params = Params ();
154
+ unsigned int chain_size = 1000 ;
155
+ for (unsigned int i = 0 ; i < chain_size / dest_wallet.size (); ++i) {
156
+ for (const auto & dest : dest_wallet) {
157
+ generateFakeBlock (params, test_setup->m_node , wallet, dest);
158
+ }
159
+ }
160
+
161
+ // Check available balance
162
+ auto bal = wallet::GetAvailableBalance (wallet); // Cache
163
+ assert (bal == 50 * COIN * (chain_size - COINBASE_MATURITY));
164
+
165
+ bench.epochIterations (2 ).run ([&] {
166
+ LOCK (wallet.cs_wallet );
167
+ const auto & res = wallet::AvailableCoins (wallet);
168
+ assert (res.All ().size () == (chain_size - COINBASE_MATURITY) * 2 );
169
+ });
170
+ }
171
+
135
172
static void WalletCreateTxUseOnlyPresetInputs (benchmark::Bench& bench) { WalletCreateTx (bench, OutputType::BECH32, /* allow_other_inputs=*/ false ,
136
173
{{/* num_of_internal_inputs=*/ 4 }}); }
137
174
138
175
static void WalletCreateTxUsePresetInputsAndCoinSelection (benchmark::Bench& bench) { WalletCreateTx (bench, OutputType::BECH32, /* allow_other_inputs=*/ true ,
139
176
{{/* num_of_internal_inputs=*/ 4 }}); }
140
177
178
+ static void WalletAvailableCoins (benchmark::Bench& bench) { AvailableCoins (bench, {OutputType::BECH32M}); }
179
+
141
180
BENCHMARK (WalletCreateTxUseOnlyPresetInputs, benchmark::PriorityLevel::LOW)
142
181
BENCHMARK(WalletCreateTxUsePresetInputsAndCoinSelection, benchmark::PriorityLevel::LOW)
182
+ BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
0 commit comments