From fa3381897871ec6ca1714c4835aad592ff532373 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 10 Dec 2024 13:40:24 +0100 Subject: [PATCH 1/2] fuzz: Speed up *_package_eval fuzz targets a bit --- src/test/fuzz/package_eval.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/fuzz/package_eval.cpp b/src/test/fuzz/package_eval.cpp index 0373d2493fa..d55691ae561 100644 --- a/src/test/fuzz/package_eval.cpp +++ b/src/test/fuzz/package_eval.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2023 The Bitcoin Core developers +// Copyright (c) 2023-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -53,9 +53,9 @@ void initialize_tx_pool() } struct OutpointsUpdater final : public CValidationInterface { - std::set& m_mempool_outpoints; + std::unordered_set& m_mempool_outpoints; - explicit OutpointsUpdater(std::set& r) + explicit OutpointsUpdater(std::unordered_set& r) : m_mempool_outpoints{r} {} void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override @@ -195,8 +195,8 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool) MockTime(fuzzed_data_provider, chainstate); // All RBF-spendable outpoints outside of the unsubmitted package - std::set mempool_outpoints; - std::map outpoints_value; + std::unordered_set mempool_outpoints; + std::unordered_map outpoints_value; for (const auto& outpoint : g_outpoints_coinbase_init_mature) { Assert(mempool_outpoints.insert(outpoint).second); outpoints_value[outpoint] = 50 * COIN; @@ -222,7 +222,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool) // Make small packages const auto num_txs = outpoint_to_rbf ? 1 : (size_t) fuzzed_data_provider.ConsumeIntegralInRange(1, 4); - std::set package_outpoints; + std::unordered_set package_outpoints; while (txs.size() < num_txs) { // Create transaction to add to the mempool txs.emplace_back([&] { @@ -349,8 +349,8 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool) MockTime(fuzzed_data_provider, chainstate); // All RBF-spendable outpoints outside of the unsubmitted package - std::set mempool_outpoints; - std::map outpoints_value; + std::unordered_set mempool_outpoints; + std::unordered_map outpoints_value; for (const auto& outpoint : g_outpoints_coinbase_init_mature) { Assert(mempool_outpoints.insert(outpoint).second); outpoints_value[outpoint] = 50 * COIN; @@ -372,7 +372,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool) // Make packages of 1-to-26 transactions const auto num_txs = (size_t) fuzzed_data_provider.ConsumeIntegralInRange(1, 26); - std::set package_outpoints; + std::unordered_set package_outpoints; while (txs.size() < num_txs) { // Create transaction to add to the mempool txs.emplace_back([&] { From fafaad5edcd1b287efacbef6d008e5d6d93d43a8 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 10 Dec 2024 13:46:08 +0100 Subject: [PATCH 2/2] fuzz: [refactor] Avoid confusing c-style cast --- src/test/fuzz/package_eval.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/fuzz/package_eval.cpp b/src/test/fuzz/package_eval.cpp index d55691ae561..5fc14bd6848 100644 --- a/src/test/fuzz/package_eval.cpp +++ b/src/test/fuzz/package_eval.cpp @@ -220,7 +220,7 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool) std::optional outpoint_to_rbf{fuzzed_data_provider.ConsumeBool() ? GetChildEvictingPrevout(tx_pool) : std::nullopt}; // Make small packages - const auto num_txs = outpoint_to_rbf ? 1 : (size_t) fuzzed_data_provider.ConsumeIntegralInRange(1, 4); + const auto num_txs = outpoint_to_rbf ? 1 : fuzzed_data_provider.ConsumeIntegralInRange(1, 4); std::unordered_set package_outpoints; while (txs.size() < num_txs) { @@ -371,7 +371,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool) std::vector txs; // Make packages of 1-to-26 transactions - const auto num_txs = (size_t) fuzzed_data_provider.ConsumeIntegralInRange(1, 26); + const auto num_txs = fuzzed_data_provider.ConsumeIntegralInRange(1, 26); std::unordered_set package_outpoints; while (txs.size() < num_txs) { // Create transaction to add to the mempool