28 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
29 g_setup = testing_setup.get();
36 return state.Invalid(*result);
47 auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider)};
48 if (!block || block->vtx.size() == 0 ||
49 block->vtx.size() >= std::numeric_limits<uint16_t>::max()) {
59 std::set<uint16_t> available;
63 std::vector<std::pair<uint256, CTransactionRef>>
extra_txn;
64 for (
size_t i = 1; i < block->vtx.size(); ++i) {
65 auto tx{block->vtx[i]};
67 bool add_to_extra_txn{fuzzed_data_provider.ConsumeBool()};
68 bool add_to_mempool{fuzzed_data_provider.ConsumeBool()};
70 if (add_to_extra_txn) {
71 extra_txn.emplace_back(tx->GetWitnessHash(), tx);
82 auto init_status{pdb.InitData(cmpctblock,
extra_txn)};
84 std::vector<CTransactionRef> missing;
87 bool skipped_missing{
false};
88 for (
size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
96 assert(!pdb.IsTxAvailable(i) || available.count(i) > 0);
99 bool skip{fuzzed_data_provider.ConsumeBool()};
100 if (!pdb.IsTxAvailable(i) && !skip) {
101 missing.push_back(block->vtx[i]);
104 skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
108 bool fail_check_block{fuzzed_data_provider.ConsumeBool()};
109 auto validation_result =
110 fuzzed_data_provider.PickValueInArray(
124 std::optional<BlockValidationResult>{validation_result} :
127 CBlock reconstructed_block;
128 auto fill_status{pdb.FillBlock(reconstructed_block, missing)};
129 switch (fill_status) {
132 assert(!fail_check_block);
133 assert(block->GetHash() == reconstructed_block.GetHash());
@ READ_STATUS_CHECKBLOCK_FAILED
std::vector< std::pair< uint256, CTransactionRef > > extra_txn
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::function< bool(const CBlock &, BlockValidationState &, const Consensus::Params &, bool, bool)> CheckBlockFn
@ BLOCK_CHECKPOINT
the block failed to meet one of our checkpoints
@ BLOCK_RECENT_CONSENSUS_CHANGE
Invalid by a change to consensus rules more recent than SegWit.
@ BLOCK_HEADER_LOW_WORK
the block header may be on a too-little-work chain
@ BLOCK_INVALID_HEADER
invalid proof of work or time too old
@ BLOCK_CACHED_INVALID
this block was cached as being invalid and we didn't store the reason why
@ BLOCK_CONSENSUS
invalid by consensus rules (excluding any below reasons)
@ BLOCK_MISSING_PREV
We don't have the previous block the checked one is built on.
@ BLOCK_INVALID_PREV
A block this one builds on is invalid.
@ BLOCK_MUTATED
the block's data didn't match the data committed to by the PoW
@ BLOCK_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
@ BLOCK_RESULT_UNSET
initial value. Block has not yet been rejected
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
FUZZ_TARGET_INIT(partially_downloaded_block, initialize_pdb)
PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional< BlockValidationResult > result)
Parameters that influence chain consensus.
Testing setup that configures a complete environment.
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)