3 #include <chainparams.h> 11 #include <validation.h> 18 static const auto testing_setup = MakeNoLogFileContext<>(
24 const std::vector<CBlockHeader>& all_headers,
25 std::vector<CBlockHeader>& new_headers)
27 Assume(!new_headers.empty());
30 all_headers.empty() ? &genesis_header : &all_headers.back()};
32 for (
auto& header : new_headers) {
35 prev_header = &header;
61 const uint256 genesis_hash = genesis_header.GetHash();
66 fuzzed_data_provider.ConsumeIntegralInRange<
unsigned>(1, 1024),
71 std::vector<CBlockHeader> all_headers;
72 std::vector<CBlockHeader>::const_iterator redownloaded_it;
74 bool requested_more{
true};
76 while (requested_more) {
77 std::vector<CBlockHeader> headers;
81 if (presync || fuzzed_data_provider.ConsumeBool()) {
82 auto deser_headers = ConsumeDeserializable<std::vector<CBlockHeader>>(fuzzed_data_provider);
83 if (!deser_headers || deser_headers->empty())
return;
85 if (fuzzed_data_provider.ConsumeBool()) {
89 headers.swap(*deser_headers);
90 }
else if (
auto num_headers_left{std::distance(redownloaded_it, all_headers.cend())}; num_headers_left > 0) {
93 auto begin_it{redownloaded_it};
94 std::advance(redownloaded_it, fuzzed_data_provider.ConsumeIntegralInRange<
int>(1, num_headers_left));
95 headers.insert(headers.cend(), begin_it, redownloaded_it);
98 if (headers.empty())
return;
100 requested_more =
result.request_more;
102 if (
result.request_more) {
104 all_headers.insert(all_headers.cend(), headers.cbegin(), headers.cend());
108 redownloaded_it = all_headers.cbegin();
const CBlock & GenesisBlock() const
arith_uint256 UintToArith256(const uint256 &a)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.
#define Assume(val)
Assume is the identity function.
256-bit unsigned big integer.
int64_t GetMedianTimePast() const
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
Seed with a compile time constant of zeros.
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex