Skip to content

Commit

Permalink
[backport] Add log output during initial header sync
Browse files Browse the repository at this point in the history
Co-Authored-By: Calin Culianu <calin.culianu@gmail.com>

Summary
---

This is a backport of core #15615. It adds logging on initial header
synch so that users monitoring the log know what is happening.

It actually was always a pet peeve of mine that when synching a brand
new chain, you end up having bitcoind sit there doing nothing for a
while in the beginning. It is actually downloading headers during this
time but the log file has no new progress until it finishes, at which
point it proceeds to download blocks.

This backport fixes this.  It adds progress information as it initially
downloads headers.

Note that the original core backport was modified:

- Made the code easier to read
- The core version was holding `cs_main` needlessly -- this version does not hold
  `cs_main` while it composes and prints the log message.  This is because it is
  not necessary to hold `cs_main` here (working with CBlockIndex references is
  always lock-free in this codebase).

Test Plan
---

- `ninja check check-functional`
- Start a new testnet synch and monitor the log. You should see messages
  like so on initial header synch:

    2020-11-04T03:13:59Z Synchronizing headers, height: 78000, progress: 16.6%
    2020-11-04T03:13:59Z Synchronizing headers, height: 80000, progress: 16.9%
    2020-11-04T03:14:00Z Synchronizing headers, height: 82000, progress: 17.3%

These new header-download-progress messages only appear during IBD, and never
during normal operation.
  • Loading branch information
jonasschnelli authored and cculianu committed Nov 6, 2020
1 parent 98dbf72 commit e422356
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/validation.cpp
Expand Up @@ -3995,6 +3995,21 @@ bool ProcessNewBlockHeaders(const Config &config,
}

NotifyHeaderTip();

// During initial header synch, log the header download progress
if (IsInitialBlockDownload()) {
if (ppindex && *ppindex) {
const CBlockIndex *const pindex = *ppindex;
const auto nTimeDiff = GetAdjustedTime() - pindex->GetBlockTime();
if (nTimeDiff > 0) {
const double chainHeightGuess = pindex->nHeight + nTimeDiff / double(config.GetChainParams()
.GetConsensus().nPowTargetSpacing);
const double percentProg = pindex->nHeight / chainHeightGuess * 100.0;
LogPrintf("Synchronizing headers, height: %d, progress: %.1f%%\n", pindex->nHeight, percentProg);
}
}
}

return true;
}

Expand Down

0 comments on commit e422356

Please sign in to comment.