30 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
31 g_setup = testing_setup.get();
38 return state.Invalid(*result);
50 auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider,
TX_WITH_WITNESS)};
51 if (!block || block->vtx.size() == 0 ||
52 block->vtx.size() >= std::numeric_limits<uint16_t>::max()) {
64 std::set<uint16_t> available;
68 std::vector<CTransactionRef> extra_txn;
69 for (
size_t i = 1; i < block->vtx.size(); ++i) {
70 auto tx{block->vtx[i]};
72 bool add_to_extra_txn{fuzzed_data_provider.ConsumeBool()};
73 bool add_to_mempool{fuzzed_data_provider.ConsumeBool()};
75 if (add_to_extra_txn) {
76 extra_txn.emplace_back(tx);
80 if (add_to_mempool && !pool.exists(
GenTxid::Txid(tx->GetHash()))) {
87 auto init_status{pdb.InitData(cmpctblock, extra_txn)};
89 std::vector<CTransactionRef> missing;
92 bool skipped_missing{
false};
93 for (
size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
101 assert(!pdb.IsTxAvailable(i) || available.count(i) > 0);
104 bool skip{fuzzed_data_provider.ConsumeBool()};
105 if (!pdb.IsTxAvailable(i) && !skip) {
106 missing.push_back(block->vtx[i]);
109 skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
113 bool fail_check_block{fuzzed_data_provider.ConsumeBool()};
114 auto validation_result =
115 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_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.
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
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
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)