mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge bitcoin/bitcoin#21798: fuzz: Create a block template in tx_pool targets
fa03d0acd6bd8bb6d3d5227512f042ff537ad993 fuzz: Create a block template in tx_pool targets (MarcoFalke) fa61ce5cf5c1d73d352173806571bcd7799ed2ee fuzz: Limit mocktime to MTP in tx_pool targets (MarcoFalke) fab646b8ea293bb2b03707c6ef6790982625e492 fuzz: Use correct variant of ConsumeRandomLengthString instead of hardcoding a maximum size (MarcoFalke) fae2c8bc54e6c0fe69a82bd1b232c52edd1acd34 fuzz: Allow to pass min/max to ConsumeTime (MarcoFalke) Pull request description: Relatively simple check to ensure a block can always be created from the mempool ACKs for top commit: practicalswift: Tested ACK fa03d0acd6bd8bb6d3d5227512f042ff537ad993 Tree-SHA512: e613376ccc88591cbe594db14ea21ebc9b2b191f6325b3aa4ee0cd379695352ad3b480e286134ef6ee30f043d486cf9792a1bc7e44445c41045ac8c3b931c7ff
This commit is contained in:
parent
c2bd834f3b
commit
4dd36f603a
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <consensus/validation.h>
|
||||
#include <miner.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
@ -77,6 +78,30 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
|
||||
ToString(fuzzed_data_provider.ConsumeIntegralInRange<unsigned>(0, 999)));
|
||||
}
|
||||
|
||||
void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, const NodeContext& node, CChainState& chainstate)
|
||||
{
|
||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
||||
{
|
||||
BlockAssembler::Options options;
|
||||
options.nBlockMaxSize = fuzzed_data_provider.ConsumeIntegralInRange(0U, MaxBlockSize(true));
|
||||
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider)};
|
||||
|
||||
auto assembler = BlockAssembler{chainstate, node, *static_cast<CTxMemPool*>(&tx_pool), ::Params(), options};
|
||||
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
|
||||
Assert(block_template->block.vtx.size() >= 1);
|
||||
}
|
||||
const auto info_all = tx_pool.infoAll();
|
||||
if (!info_all.empty()) {
|
||||
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
|
||||
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK));
|
||||
std::vector<uint256> all_txids;
|
||||
tx_pool.queryHashes(all_txids);
|
||||
assert(all_txids.size() < info_all.size());
|
||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
||||
}
|
||||
SyncWithValidationInterfaceQueue();
|
||||
}
|
||||
|
||||
void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chainstate)
|
||||
{
|
||||
const auto time = ConsumeTime(fuzzed_data_provider,
|
||||
@ -254,17 +279,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
|
||||
}
|
||||
}
|
||||
}
|
||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
||||
const auto info_all = tx_pool.infoAll();
|
||||
if (!info_all.empty()) {
|
||||
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
|
||||
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, /* dummy */ MemPoolRemovalReason::BLOCK));
|
||||
std::vector<uint256> all_txids;
|
||||
tx_pool.queryHashes(all_txids);
|
||||
assert(all_txids.size() < info_all.size());
|
||||
WITH_LOCK(::cs_main, tx_pool.check(chainstate));
|
||||
}
|
||||
SyncWithValidationInterfaceQueue();
|
||||
Finish(fuzzed_data_provider, tx_pool, node, chainstate);
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
|
||||
@ -318,8 +333,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
|
||||
if (accepted) {
|
||||
txids.push_back(tx->GetHash());
|
||||
}
|
||||
|
||||
SyncWithValidationInterfaceQueue();
|
||||
}
|
||||
Finish(fuzzed_data_provider, tx_pool, node, chainstate);
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user