MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GuessVerificationProgress

Method GuessVerificationProgress

src/validation.cpp:5509–5544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5507}
5508
5509double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) const
5510{
5511 AssertLockHeld(GetMutex());
5512 const ChainTxData& data{GetParams().TxData()};
5513 if (pindex == nullptr) {
5514 return 0.0;
5515 }
5516
5517 if (pindex->m_chain_tx_count == 0) {
5518 LogDebug(BCLog::VALIDATION, "Block %d has unset m_chain_tx_count. Unable to estimate verification progress.\n", pindex->nHeight);
5519 return 0.0;
5520 }
5521
5522 const int64_t nNow{TicksSinceEpoch<std::chrono::seconds>(NodeClock::now())};
5523 const auto block_time{
5524 (Assume(m_best_header) && std::abs(nNow - pindex->GetBlockTime()) <= Ticks<std::chrono::seconds>(2h) &&
5525 Assume(m_best_header->nHeight >= pindex->nHeight)) ?
5526 // When the header is known to be recent, switch to a height-based
5527 // approach. This ensures the returned value is quantized when
5528 // close to "1.0", because some users expect it to be. This also
5529 // avoids relying too much on the exact miner-set timestamp, which
5530 // may be off.
5531 nNow - (m_best_header->nHeight - pindex->nHeight) * GetConsensus().nPowTargetSpacing :
5532 pindex->GetBlockTime(),
5533 };
5534
5535 double fTxTotal;
5536
5537 if (pindex->m_chain_tx_count <= data.tx_count) {
5538 fTxTotal = data.tx_count + (nNow - data.nTime) * data.dTxRate;
5539 } else {
5540 fTxTotal = pindex->m_chain_tx_count + (nNow - block_time) * data.dTxRate;
5541 }
5542
5543 return std::min<double>(pindex->m_chain_tx_count / fTxTotal, 1.0);
5544}
5545
5546double ChainstateManager::GetBackgroundVerificationProgress(const CBlockIndex& pindex) const
5547{

Callers 9

AppInitMainFunction · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.80
ActivateBestChainMethod · 0.80
InvalidateBlockMethod · 0.80
LoadChainTipMethod · 0.80
getblockchaininfoFunction · 0.80
getchainstatesFunction · 0.80

Calls 1

GetBlockTimeMethod · 0.45

Tested by

no test coverage detected