MCPcopy Create free account
hub / github.com/ElementsProject/elements / GuessVerificationProgress

Function GuessVerificationProgress

src/validation.cpp:5131–5143  ·  view source on GitHub ↗

Guess how far we are in the verification process at the given block index. Since we have signed fixed-interval blocks, estimating progress is a very easy. We can extrapolate the last block time to the current time to estimate how many more blocks we expect.

Source from the content-addressed store, hash-verified

5129//! We can extrapolate the last block time to the current time to estimate how many more blocks
5130//! we expect.
5131double GuessVerificationProgress(const CBlockIndex* pindex, int64_t blockInterval) {
5132 if (pindex == NULL || pindex->nHeight < 1) {
5133 return 0.0;
5134 }
5135
5136 int64_t nNow = GetTime();
5137 int64_t moreBlocksExpected = (nNow - pindex->GetBlockTime()) / blockInterval;
5138 double progress = (pindex->nHeight + 0.0) / (pindex->nHeight + moreBlocksExpected);
5139 // Round to 3 digits to avoid 0.999999 when finished.
5140 progress = ceil(progress * 1000.0) / 1000.0;
5141 // Avoid higher than one if last block is newer than current time.
5142 return std::min(1.0, progress);
5143}
5144
5145std::optional<uint256> ChainstateManager::SnapshotBlockhash() const
5146{

Callers 7

AppInitMainFunction · 0.85
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.85
LoadChainTipMethod · 0.85
getblockchaininfoFunction · 0.85
handleNotifyBlockTipMethod · 0.85

Calls 2

GetTimeFunction · 0.85
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected