mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Merge bitcoin/bitcoin#29647: Avoid divide-by-zero in header sync logs when NodeClock is behind
fa4d98b3c8
Avoid divide-by-zero in header sync logs when NodeClock is behind (MarcoFalke)fa58550317
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: utACKfa4d98b3c8
sr-gi: tACK [fa4d98b
](fa4d98b3c8
) achow101: ACKfa4d98b3c8
tdb3: ACKfa4d98b3c8
Tree-SHA512: 3c5aee4030af387695918c5238012c972ebf850b52e956b5f74590cd7fd4eff0b3e593d411e3eb2a0bb12294af8dc6fbe320f90e4c261399b65a404ff3c3cbd9
This commit is contained in:
commit
85c8a5ec48
1 changed files with 6 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue