diff options
author | Ava Chow <github@achow101.com> | 2024-03-22 13:08:23 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-03-22 13:18:30 -0400 |
commit | 85c8a5ec48b5e2a0ba26bec0acb572dce37271ff (patch) | |
tree | 5360b593f5f5fa2536a3ab0c03c001f57cad2c6a /src/validation.cpp | |
parent | 2ffaa927023f5dc2a7b8d6cfeb4f4810e573b18c (diff) | |
parent | fa4d98b3c8e63f20c6f366fc9382039ba52614a4 (diff) | |
download | bitcoin-85c8a5ec48b5e2a0ba26bec0acb572dce37271ff.tar.xz |
Merge bitcoin/bitcoin#29647: Avoid divide-by-zero in header sync logs when NodeClock is behind
fa4d98b3c8e63f20c6f366fc9382039ba52614a4 Avoid divide-by-zero in header sync logs when NodeClock is behind (MarcoFalke)
fa58550317c633c411009c1cc8fb692e3baf97e8 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 fa4d98b3c8e63f20c6f366fc9382039ba52614a4
sr-gi:
tACK [fa4d98b](https://github.com/bitcoin/bitcoin/pull/29647/commits/fa4d98b3c8e63f20c6f366fc9382039ba52614a4)
achow101:
ACK fa4d98b3c8e63f20c6f366fc9382039ba52614a4
tdb3:
ACK fa4d98b3c8e63f20c6f366fc9382039ba52614a4
Tree-SHA512: 3c5aee4030af387695918c5238012c972ebf850b52e956b5f74590cd7fd4eff0b3e593d411e3eb2a0bb12294af8dc6fbe320f90e4c261399b65a404ff3c3cbd9
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index b6d0c38f39..a8c98ae9ba 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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; @@ -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); } } |