Skip to content

Commit

Permalink
Merge bitcoin#29647: Avoid divide-by-zero in header sync logs when No…
Browse files Browse the repository at this point in the history
…deClock is behind

fa4d98b Avoid divide-by-zero in header sync logs when NodeClock is behind (MarcoFalke)
fa58550 refactor: Modernize header sync logs (MarcoFalke)

Pull request description:

  The log may be confusing, when the NodeClock is behind the current header tip.

  Fix it, by assuming the NodeClock is never behind the current header tip.

ACKs for top commit:
  sipa:
    utACK fa4d98b
  sr-gi:
    tACK [fa4d98b](bitcoin@fa4d98b)
  achow101:
    ACK fa4d98b
  tdb3:
    ACK fa4d98b

Tree-SHA512: 3c5aee4030af387695918c5238012c972ebf850b52e956b5f74590cd7fd4eff0b3e593d411e3eb2a0bb12294af8dc6fbe320f90e4c261399b65a404ff3c3cbd9
  • Loading branch information
achow101 committed Mar 22, 2024
2 parents 2ffaa92 + fa4d98b commit 85c8a5e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4234,9 +4234,10 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
if (NotifyHeaderTip(*this)) {
if (IsInitialBlockDownload() && ppindex && *ppindex) {
const CBlockIndex& last_accepted{**ppindex};
const int64_t blocks_left{(GetTime() - last_accepted.GetBlockTime()) / GetConsensus().nPowTargetSpacing};
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)};
LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
LogInfo("Synchronizing blockheaders, height: %d (~%.2f%%)\n", last_accepted.nHeight, progress);
}
}
return true;
Expand All @@ -4260,9 +4261,10 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t
bool initial_download = IsInitialBlockDownload();
GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
if (initial_download) {
const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing};
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)};
LogPrintf("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
LogInfo("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
}
}

Expand Down

0 comments on commit 85c8a5e

Please sign in to comment.