mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-13 19:50:43 +02:00
Avoid divide-by-zero in header sync logs when NodeClock is behind
This commit is contained in:
parent
fa58550317
commit
fa4d98b3c8
@ -4189,6 +4189,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
|
|||||||
if (IsInitialBlockDownload() && ppindex && *ppindex) {
|
if (IsInitialBlockDownload() && ppindex && *ppindex) {
|
||||||
const CBlockIndex& last_accepted{**ppindex};
|
const CBlockIndex& last_accepted{**ppindex};
|
||||||
int64_t blocks_left{(NodeClock::now() - last_accepted.Time()) / GetConsensus().PowTargetSpacing()};
|
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)};
|
const double progress{100.0 * last_accepted.nHeight / (last_accepted.nHeight + blocks_left)};
|
||||||
LogInfo("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
|
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);
|
GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
|
||||||
if (initial_download) {
|
if (initial_download) {
|
||||||
int64_t blocks_left{(NodeClock::now() - NodeSeconds{std::chrono::seconds{timestamp}}) / GetConsensus().PowTargetSpacing()};
|
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)};
|
const double progress{100.0 * height / (height + blocks_left)};
|
||||||
LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
|
LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user