Skip to content

Commit fa4d98b

Browse files
author
MarcoFalke
committed
Avoid divide-by-zero in header sync logs when NodeClock is behind
1 parent fa58550 commit fa4d98b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/validation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,6 +4189,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
41894189
if (IsInitialBlockDownload() && ppindex && *ppindex) {
41904190
const CBlockIndex& last_accepted{**ppindex};
41914191
int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()};
4192+
blocks_left = std::max<int64_t>(0, blocks_left);
41924193
const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)};
41934194
LogInfo("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
41944195
}
@@ -4215,6 +4216,7 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t
42154216
GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
42164217
if (initial_download) {
42174218
int64_t blocks_left{(NodeClock::now() - NodeSeconds{std::chrono::seconds{timestamp}}) / GetConsensus().PowTargetSpacing()};
4219+
blocks_left = std::max<int64_t>(0, blocks_left);
42184220
const double progress{100.0 * height / (height + blocks_left)};
42194221
LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
42204222
}

0 commit comments

Comments
 (0)