| 4280 | } |
| 4281 | |
| 4282 | void 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 */ |
| 4308 | bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock, bool min_pow_checked) |
no test coverage detected