MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ConsumeHeader

Function ConsumeHeader

src/test/fuzz/p2p_headers_presync.cpp:102–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102CBlockHeader ConsumeHeader(FuzzedDataProvider& fuzzed_data_provider, const uint256& prev_hash, uint32_t prev_nbits)
103{
104 CBlockHeader header;
105 header.nNonce = 0;
106 // Either use the previous difficulty or let the fuzzer choose. The upper target in the
107 // range comes from the bits value of the genesis block, which is 0x1d00ffff. The lower
108 // target comes from the bits value of mainnet block 840000, which is 0x17034219.
109 // Calling lower_target.SetCompact(0x17034219) and upper_target.SetCompact(0x1d00ffff)
110 // should return the values below.
111 //
112 // RPC commands to verify:
113 // getblockheader 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
114 // getblockheader 0000000000000000000320283a032748cef8227873ff4872689bf23f1cda83a5
115 if (fuzzed_data_provider.ConsumeBool()) {
116 header.nBits = prev_nbits;
117 } else {
118 arith_uint256 lower_target = UintToArith256(uint256{"0000000000000000000342190000000000000000000000000000000000000000"});
119 arith_uint256 upper_target = UintToArith256(uint256{"00000000ffff0000000000000000000000000000000000000000000000000000"});
120 arith_uint256 target = ConsumeArithUInt256InRange(fuzzed_data_provider, lower_target, upper_target);
121 header.nBits = target.GetCompact();
122 }
123 header.nTime = TicksSinceEpoch<std::chrono::seconds>(ConsumeTime(fuzzed_data_provider));
124 header.hashPrevBlock = prev_hash;
125 header.nVersion = fuzzed_data_provider.ConsumeIntegral<int32_t>();
126 return header;
127}
128
129CBlock ConsumeBlock(FuzzedDataProvider& fuzzed_data_provider, const uint256& prev_hash, uint32_t prev_nbits)
130{

Callers 2

ConsumeBlockFunction · 0.85

Calls 5

UintToArith256Function · 0.85
ConsumeTimeFunction · 0.85
ConsumeBoolMethod · 0.80
GetCompactMethod · 0.80

Tested by

no test coverage detected