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());
@ READ_STATUS_CHECKBLOCK_FAILED
#define Assert(val)
Identity function.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
static GenTxid Txid(const uint256 &hash)
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(partially_downloaded_block,.init=initialize_pdb)
PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional< BlockValidationResult > result)
static constexpr TransactionSerParams TX_WITH_WITNESS
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)