@@ -2394,7 +2394,8 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
23942394 pindexNew->GetBlockHash ().ToString (), pindexNew->nHeight , pindexNew->nVersion ,
23952395 (unsigned long )pindexNew->nChainTx ,
23962396 FormatISO8601DateTime (pindexNew->GetBlockTime ()),
2397- GuessVerificationProgress (chainParams.TxData (), pindexNew), pcoinsTip->DynamicMemoryUsage () * (1.0 / (1 <<20 )), pcoinsTip->GetCacheSize ());
2397+ GuessVerificationProgress (pindexNew, chainParams.GetConsensus ().nPowTargetSpacing ),
2398+ pcoinsTip->DynamicMemoryUsage () * (1.0 / (1 <<20 )), pcoinsTip->GetCacheSize ());
23982399 if (!warningMessages.empty ())
23992400 LogPrintf (" warning='%s'" , warningMessages); /* Continued */
24002401 LogPrintf (" \n " );
@@ -4203,10 +4204,10 @@ bool LoadChainTip(const CChainParams& chainparams)
42034204
42044205 g_chainstate.PruneBlockIndexCandidates ();
42054206
4206- LogPrintf (" Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f \n " ,
4207+ LogPrintf (" Loaded best chain: hashBestChain=%s height=%d date=%s progress=%.3f \n " ,
42074208 chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (),
42084209 FormatISO8601DateTime (chainActive.Tip ()->GetBlockTime ()),
4209- GuessVerificationProgress (chainparams. TxData (), chainActive. Tip () ));
4210+ GuessVerificationProgress (chainActive. Tip (), chainparams. GetConsensus (). nPowTargetSpacing ));
42104211 return true ;
42114212}
42124213
@@ -5067,23 +5068,22 @@ bool DumpMempool(void)
50675068 return true ;
50685069}
50695070
5070- // ! Guess how far we are in the verification process at the given block index
5071- // ! require cs_main if pindex has not been validated yet (because nChainTx might be unset)
5072- double GuessVerificationProgress (const ChainTxData& data, const CBlockIndex *pindex) {
5073- if (pindex == nullptr )
5071+ // ! Guess how far we are in the verification process at the given block index.
5072+ // ! Since we have signed fixed-interval blocks, estimating progress is a very easy.
5073+ // ! We can extrapolate the last block time to the current time to estimate how many more blocks
5074+ // ! we expect.
5075+ double GuessVerificationProgress (const CBlockIndex* pindex, int64_t blockInterval) {
5076+ if (pindex == NULL || pindex->nHeight < 1 ) {
50745077 return 0.0 ;
5075-
5076- int64_t nNow = time (nullptr );
5077-
5078- double fTxTotal ;
5079-
5080- if (pindex->nChainTx <= data.nTxCount ) {
5081- fTxTotal = data.nTxCount + (nNow - data.nTime ) * data.dTxRate ;
5082- } else {
5083- fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime ()) * data.dTxRate ;
50845078 }
50855079
5086- return pindex->nChainTx / fTxTotal ;
5080+ int64_t nNow = GetTime ();
5081+ int64_t moreBlocksExpected = (nNow - pindex->GetBlockTime ()) / blockInterval;
5082+ double progress = (pindex->nHeight + 0.0 ) / (pindex->nHeight + moreBlocksExpected);
5083+ // Round to 3 digits to avoid 0.999999 when finished.
5084+ progress = ceil (progress * 1000.0 ) / 1000.0 ;
5085+ // Avoid higher than one if last block is newer than current time.
5086+ return std::min (1.0 , progress);
50875087}
50885088
50895089class CMainCleanup
0 commit comments