30 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
31 g_setup = testing_setup.get();
38 return state.Invalid(*result);
49 auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider,
TX_WITH_WITNESS)};
50 if (!block || block->vtx.size() == 0 ||
51 block->vtx.size() >= std::numeric_limits<uint16_t>::max()) {
63 std::set<uint16_t> available;
67 std::vector<CTransactionRef> extra_txn;
68 for (
size_t i = 1; i < block->vtx.size(); ++i) {
69 auto tx{block->vtx[i]};
71 bool add_to_extra_txn{fuzzed_data_provider.ConsumeBool()};
72 bool add_to_mempool{fuzzed_data_provider.ConsumeBool()};
74 if (add_to_extra_txn) {
75 extra_txn.emplace_back(tx);
79 if (add_to_mempool && !pool.exists(
GenTxid::Txid(tx->GetHash()))) {
86 auto init_status{pdb.InitData(cmpctblock, extra_txn)};
88 std::vector<CTransactionRef> missing;
91 bool skipped_missing{
false};
92 for (
size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
100 assert(!pdb.IsTxAvailable(i) || available.count(i) > 0);
103 bool skip{fuzzed_data_provider.ConsumeBool()};
104 if (!pdb.IsTxAvailable(i) && !skip) {
105 missing.push_back(block->vtx[i]);
108 skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
112 bool fail_check_block{fuzzed_data_provider.ConsumeBool()};
113 auto validation_result =
114 fuzzed_data_provider.PickValueInArray(
128 std::optional<BlockValidationResult>{validation_result} :
131 CBlock reconstructed_block;
132 auto fill_status{pdb.FillBlock(reconstructed_block, missing)};
133 switch (fill_status) {
136 assert(!fail_check_block);
137 assert(block->GetHash() == reconstructed_block.GetHash());
We don't have the previous block the checked one is built on.
invalid proof of work or time too old
the block header may be on a too-little-work chain
PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional< BlockValidationResult > result)
initial value. Block has not yet been rejected
std::function< bool(const CBlock &, BlockValidationState &, const Consensus::Params &, bool, bool)> CheckBlockFn
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
this block was cached as being invalid and we didn't store the reason why
the block failed to meet one of our checkpoints
Parameters that influence chain consensus.
invalid by consensus rules (excluding any below reasons)
FUZZ_TARGET(partially_downloaded_block,.init=initialize_pdb)
the block's data didn't match the data committed to by the PoW
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
A block this one builds on is invalid.
Invalid by a change to consensus rules more recent than SegWit.
block timestamp was > 2 hours in the future (or our clock is bad)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Testing setup that configures a complete environment.
static GenTxid Txid(const uint256 &hash)
#define Assert(val)
Identity function.
static constexpr TransactionSerParams TX_WITH_WITNESS
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)