31 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
32 g_setup = testing_setup.get();
39 return state.Invalid(*
result);
52 auto block{ConsumeDeserializable<CBlock>(fuzzed_data_provider,
TX_WITH_WITNESS)};
53 if (!block || block->vtx.size() == 0 ||
54 block->vtx.size() >= std::numeric_limits<uint16_t>::max()) {
66 std::set<uint16_t> available;
70 std::vector<CTransactionRef> extra_txn;
71 for (
size_t i = 1; i < block->vtx.size(); ++i) {
72 auto tx{block->vtx[i]};
74 bool add_to_extra_txn{fuzzed_data_provider.ConsumeBool()};
75 bool add_to_mempool{fuzzed_data_provider.ConsumeBool()};
77 if (add_to_extra_txn) {
78 extra_txn.emplace_back(tx);
82 if (add_to_mempool && !pool.exists(
GenTxid::Txid(tx->GetHash()))) {
89 auto init_status{pdb.InitData(cmpctblock, extra_txn)};
91 std::vector<CTransactionRef> missing;
94 bool skipped_missing{
false};
95 for (
size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
103 assert(!pdb.IsTxAvailable(i) || available.count(i) > 0);
106 bool skip{fuzzed_data_provider.ConsumeBool()};
107 if (!pdb.IsTxAvailable(i) && !skip) {
108 missing.push_back(block->vtx[i]);
111 skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
115 bool fail_check_block{fuzzed_data_provider.ConsumeBool()};
116 auto validation_result =
117 fuzzed_data_provider.PickValueInArray(
130 std::optional<BlockValidationResult>{validation_result} :
133 CBlock reconstructed_block;
134 auto fill_status{pdb.FillBlock(reconstructed_block, missing)};
135 switch (fill_status) {
138 assert(!fail_check_block);
139 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)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
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
AddToMempool(pool, CTxMemPoolEntry(tx, fee, nTime, nHeight, sequence, spendsCoinbase, sigOpCost, lp))
Parameters that influence chain consensus.
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
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
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
A block this one builds on is invalid.
block timestamp was > 2 hours in the future (or our clock is bad)
Seed with a compile time constant of zeros.
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)