diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-03-13 15:15:42 +0100 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-03-13 16:17:08 +0100 |
commit | fa4d98b3c8e63f20c6f366fc9382039ba52614a4 (patch) | |
tree | 93e8e36da19a4cb8d3a07e377d35adb07aa17ec9 /src/validation.cpp | |
parent | fa58550317c633c411009c1cc8fb692e3baf97e8 (diff) | |
download | bitcoin-fa4d98b3c8e63f20c6f366fc9382039ba52614a4.tar.xz |
Avoid divide-by-zero in header sync logs when NodeClock is behind
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index a230010497..a9d9f9d207 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4189,6 +4189,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& if (IsInitialBlockDownload() && ppindex && *ppindex) { const CBlockIndex& last_accepted{**ppindex}; int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()}; + blocks_left = std::max<int64_t>(0, blocks_left); const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)}; LogInfo("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress); } @@ -4215,6 +4216,7 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true); if (initial_download) { int64_t blocks_left{(NodeClock::now() - NodeSeconds{std::chrono::seconds{timestamp}}) / GetConsensus().PowTargetSpacing()}; + blocks_left = std::max<int64_t>(0, blocks_left); const double progress{100.0 * height / (height + blocks_left)}; LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress); } |