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;
60 const uint256 genesis_hash = genesis_header.GetHash();
65 fuzzed_data_provider.ConsumeIntegralInRange<
unsigned>(1, 1024),
70 std::vector<CBlockHeader> all_headers;
71 std::vector<CBlockHeader>::const_iterator redownloaded_it;
73 bool requested_more{
true};
75 while (requested_more) {
76 std::vector<CBlockHeader> headers;
80 if (presync || fuzzed_data_provider.ConsumeBool()) {
81 auto deser_headers = ConsumeDeserializable<std::vector<CBlockHeader>>(fuzzed_data_provider);
82 if (!deser_headers || deser_headers->empty())
return;
84 if (fuzzed_data_provider.ConsumeBool()) {
88 headers.swap(*deser_headers);
89 }
else if (
auto num_headers_left{std::distance(redownloaded_it, all_headers.cend())}; num_headers_left > 0) {
92 auto begin_it{redownloaded_it};
93 std::advance(redownloaded_it, fuzzed_data_provider.ConsumeIntegralInRange<
int>(1, num_headers_left));
94 headers.insert(headers.cend(), begin_it, redownloaded_it);
97 if (headers.empty())
return;
98 auto result = headers_sync.
ProcessNextHeaders(headers, fuzzed_data_provider.ConsumeBool());
101 if (result.request_more) {
103 all_headers.insert(all_headers.cend(), headers.cbegin(), headers.cend());
107 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(const std::vector< 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
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.
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