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

Method ReportHeadersPresync

src/validation.cpp:4282–4305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4280}
4281
4282void ChainstateManager::ReportHeadersPresync(int64_t height, int64_t timestamp)
4283{
4284 AssertLockNotHeld(GetMutex());
4285 {
4286 LOCK(GetMutex());
4287 // Don't report headers presync progress if we already have a post-minchainwork header chain.
4288 // This means we lose reporting for potentially legitimate, but unlikely, deep reorgs, but
4289 // prevent attackers that spam low-work headers from filling our logs.
4290 if (m_best_header->nChainWork >= UintToArith256(GetConsensus().nMinimumChainWork)) return;
4291 // Rate limit headers presync updates to 4 per second, as these are not subject to DoS
4292 // protection.
4293 auto now = MockableSteadyClock::now();
4294 if (now < m_last_presync_update + std::chrono::milliseconds{250}) return;
4295 m_last_presync_update = now;
4296 }
4297 bool initial_download = IsInitialBlockDownload();
4298 GetNotifications().headerTip(GetSynchronizationState(initial_download, m_blockman.m_blockfiles_indexed), height, timestamp, /*presync=*/true);
4299 if (initial_download) {
4300 int64_t blocks_left{(NodeClock::now() - NodeSeconds{std::chrono::seconds{timestamp}}) / GetConsensus().PowTargetSpacing()};
4301 blocks_left = std::max<int64_t>(0, blocks_left);
4302 const double progress{100.0 * height / (height + blocks_left)};
4303 LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
4304 }
4305}
4306
4307/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
4308bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock, bool min_pow_checked)

Callers 1

ProcessMessageMethod · 0.80

Calls 4

UintToArith256Function · 0.85
GetSynchronizationStateFunction · 0.85
PowTargetSpacingMethod · 0.80
headerTipMethod · 0.45

Tested by

no test coverage detected