Skip to content

Commit ef525e8

Browse files
committed
Merge bitcoin#31457: fuzz: Speed up *_package_eval fuzz targets a bit
fac3d93 fuzz: Speed up *_package_eval fuzz targets a bit (MarcoFalke) fa40fd0 fuzz: [refactor] Avoid confusing c-style cast (MarcoFalke) Pull request description: Each target is at least 10% faster for me when running over the current set of qa-assets, which seems nice. The changes `outpoints_value` from a map to an unordered map, which is safe, because the element order is not used in the fuzz test and the map is only used for lookup. (`mempool_outpoints` can't be changed, because the order matters here. Using unordered_set here may result in a non-deterministic fuzz target, given the same fuzz input.) ACKs for top commit: l0rinc: ACK fac3d93 dergoegge: Code review ACK fac3d93 Tree-SHA512: 8ae5d4e281505aff76a4003d6e9ea388dbb73860e167385bd6a0a201b3acc939db29ee212594952a9e80e85b3cc4cd726ce6dd49551f74013cb4da8a15cbdfb3
2 parents 7d76c97 + fac3d93 commit ef525e8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/test/fuzz/package_eval.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
201201

202202
// All RBF-spendable outpoints outside of the unsubmitted package
203203
std::set<COutPoint> mempool_outpoints;
204-
std::map<COutPoint, CAmount> outpoints_value;
204+
std::unordered_map<COutPoint, CAmount, SaltedOutpointHasher> outpoints_value;
205205
for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
206206
Assert(mempool_outpoints.insert(outpoint).second);
207207
outpoints_value[outpoint] = 50 * COIN;
@@ -225,7 +225,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
225225
std::optional<COutPoint> outpoint_to_rbf{fuzzed_data_provider.ConsumeBool() ? GetChildEvictingPrevout(tx_pool) : std::nullopt};
226226

227227
// Make small packages
228-
const auto num_txs = outpoint_to_rbf ? 1 : (size_t) fuzzed_data_provider.ConsumeIntegralInRange<int>(1, 4);
228+
const auto num_txs = outpoint_to_rbf ? 1 : fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4);
229229

230230
std::set<COutPoint> package_outpoints;
231231
while (txs.size() < num_txs) {
@@ -356,7 +356,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
356356

357357
// All RBF-spendable outpoints outside of the unsubmitted package
358358
std::set<COutPoint> mempool_outpoints;
359-
std::map<COutPoint, CAmount> outpoints_value;
359+
std::unordered_map<COutPoint, CAmount, SaltedOutpointHasher> outpoints_value;
360360
for (const auto& outpoint : g_outpoints_coinbase_init_mature) {
361361
Assert(mempool_outpoints.insert(outpoint).second);
362362
outpoints_value[outpoint] = 50 * COIN;
@@ -377,7 +377,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool)
377377
std::vector<CTransactionRef> txs;
378378

379379
// Make packages of 1-to-26 transactions
380-
const auto num_txs = (size_t) fuzzed_data_provider.ConsumeIntegralInRange<int>(1, 26);
380+
const auto num_txs = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 26);
381381
std::set<COutPoint> package_outpoints;
382382
while (txs.size() < num_txs) {
383383
// Create transaction to add to the mempool

0 commit comments

Comments
 (0)