MCPcopy Create free account
hub / github.com/ElementsProject/elements / ProcessNewBlockHeaders

Method ProcessNewBlockHeaders

src/validation.cpp:4039–4073  ·  view source on GitHub ↗

Exposed wrapper for AcceptBlockHeader

Source from the content-addressed store, hash-verified

4037
4038// Exposed wrapper for AcceptBlockHeader
4039bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex, bool* all_duplicate)
4040{
4041 AssertLockNotHeld(cs_main);
4042 {
4043 LOCK(cs_main);
4044 if (all_duplicate) {
4045 *all_duplicate = true;
4046 }
4047 bool duplicate = false;
4048 for (const CBlockHeader& header : headers) {
4049 CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
4050 bool accepted{AcceptBlockHeader(header, state, chainparams, &pindex, &duplicate)};
4051 ActiveChainstate().CheckBlockIndex();
4052
4053 if (all_duplicate) {
4054 (*all_duplicate) &= duplicate; // False if any are false
4055 }
4056 if (!accepted) {
4057 return false;
4058 }
4059 if (ppindex) {
4060 *ppindex = pindex;
4061 }
4062 }
4063 }
4064 if (NotifyHeaderTip(ActiveChainstate())) {
4065 if (ActiveChainstate().IsInitialBlockDownload() && ppindex && *ppindex) {
4066 const CBlockIndex& last_accepted{**ppindex};
4067 const int64_t blocks_left{(GetTime() - last_accepted.GetBlockTime()) / chainparams.GetConsensus().nPowTargetSpacing};
4068 const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)};
4069 LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
4070 }
4071 }
4072 return true;
4073}
4074
4075/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
4076bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock)

Callers 6

ProcessHeadersMessageMethod · 0.80
ProcessMessageMethod · 0.80
BuildChainMethod · 0.80
FinalizeBlockMethod · 0.80
FUZZ_TARGET_INITFunction · 0.80
submitheaderFunction · 0.80

Calls 4

GetTimeFunction · 0.85
CheckBlockIndexMethod · 0.80
GetBlockTimeMethod · 0.45

Tested by 3

BuildChainMethod · 0.64
FinalizeBlockMethod · 0.64
FUZZ_TARGET_INITFunction · 0.64