Exposed wrapper for AcceptBlockHeader
| 4250 | |
| 4251 | // Exposed wrapper for AcceptBlockHeader |
| 4252 | bool ChainstateManager::ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex) |
| 4253 | { |
| 4254 | AssertLockNotHeld(cs_main); |
| 4255 | { |
| 4256 | LOCK(cs_main); |
| 4257 | for (const CBlockHeader& header : headers) { |
| 4258 | CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast |
| 4259 | bool accepted{AcceptBlockHeader(header, state, &pindex, min_pow_checked)}; |
| 4260 | CheckBlockIndex(); |
| 4261 | |
| 4262 | if (!accepted) { |
| 4263 | return false; |
| 4264 | } |
| 4265 | if (ppindex) { |
| 4266 | *ppindex = pindex; |
| 4267 | } |
| 4268 | } |
| 4269 | } |
| 4270 | if (NotifyHeaderTip()) { |
| 4271 | if (IsInitialBlockDownload() && ppindex && *ppindex) { |
| 4272 | const CBlockIndex& last_accepted{**ppindex}; |
| 4273 | int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()}; |
| 4274 | blocks_left = std::max<int64_t>(0, blocks_left); |
| 4275 | const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)}; |
| 4276 | LogInfo("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress); |
| 4277 | } |
| 4278 | } |
| 4279 | return true; |
| 4280 | } |
| 4281 | |
| 4282 | void ChainstateManager::ReportHeadersPresync(int64_t height, int64_t timestamp) |
| 4283 | { |