|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | 4 |
|
5 | 5 | #include <consensus/validation.h> |
| 6 | +#include <miner.h> |
6 | 7 | #include <test/fuzz/FuzzedDataProvider.h> |
7 | 8 | #include <test/fuzz/fuzz.h> |
8 | 9 | #include <test/fuzz/util.h> |
@@ -77,6 +78,29 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr |
77 | 78 | ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999))); |
78 | 79 | } |
79 | 80 |
|
| 81 | +void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, CChainState& chainstate) |
| 82 | +{ |
| 83 | + WITH_LOCK(::cs_main, tx_pool.check(chainstate)); |
| 84 | + { |
| 85 | + BlockAssembler::Options options; |
| 86 | + options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT); |
| 87 | + options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider)}; |
| 88 | + auto assembler = BlockAssembler{chainstate, *static_cast<CTxMemPool*>(&tx_pool), ::Params(), options}; |
| 89 | + auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE); |
| 90 | + Assert(block_template->block.vtx.size() >= 1); |
| 91 | + } |
| 92 | + const auto info_all = tx_pool.infoAll(); |
| 93 | + if (!info_all.empty()) { |
| 94 | + const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx; |
| 95 | + WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK)); |
| 96 | + std::vector<uint256> all_txids; |
| 97 | + tx_pool.queryHashes(all_txids); |
| 98 | + assert(all_txids.size() < info_all.size()); |
| 99 | + WITH_LOCK(::cs_main, tx_pool.check(chainstate)); |
| 100 | + } |
| 101 | + SyncWithValidationInterfaceQueue(); |
| 102 | +} |
| 103 | + |
80 | 104 | void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chainstate) |
81 | 105 | { |
82 | 106 | const auto time = ConsumeTime(fuzzed_data_provider, |
@@ -245,17 +269,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool) |
245 | 269 | } |
246 | 270 | } |
247 | 271 | } |
248 | | - WITH_LOCK(::cs_main, tx_pool.check(chainstate)); |
249 | | - const auto info_all = tx_pool.infoAll(); |
250 | | - if (!info_all.empty()) { |
251 | | - const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx; |
252 | | - WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK)); |
253 | | - std::vector<uint256> all_txids; |
254 | | - tx_pool.queryHashes(all_txids); |
255 | | - assert(all_txids.size() < info_all.size()); |
256 | | - WITH_LOCK(::cs_main, tx_pool.check(chainstate)); |
257 | | - } |
258 | | - SyncWithValidationInterfaceQueue(); |
| 272 | + Finish(fuzzed_data_provider, tx_pool, chainstate); |
259 | 273 | } |
260 | 274 |
|
261 | 275 | FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool) |
@@ -308,8 +322,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool) |
308 | 322 | if (accepted) { |
309 | 323 | txids.push_back(tx->GetHash()); |
310 | 324 | } |
311 | | - |
312 | | - SyncWithValidationInterfaceQueue(); |
313 | 325 | } |
| 326 | + Finish(fuzzed_data_provider, tx_pool, chainstate); |
314 | 327 | } |
315 | 328 | } // namespace |
0 commit comments