@@ -3042,7 +3042,8 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
30423042 chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (), chainActive.Tip ()->nVersion ,
30433043 log (chainActive.Tip ()->nChainWork .getdouble ())/log (2.0 ), (unsigned long )chainActive.Tip ()->nChainTx ,
30443044 DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , chainActive.Tip ()->GetBlockTime ()),
3045- GuessVerificationProgress (chainParams.TxData (), chainActive.Tip ()), pcoinsTip->DynamicMemoryUsage () * (1.0 / (1 <<20 )), pcoinsTip->GetCacheSize ());
3045+ GuessVerificationProgress (chainActive.Tip (), chainParams.GetConsensus ().nPowTargetSpacing ),
3046+ pcoinsTip->DynamicMemoryUsage () * (1.0 / (1 <<20 )), pcoinsTip->GetCacheSize ());
30463047 if (!warningMessages.empty ())
30473048 LogPrintf (" warning='%s'" , boost::algorithm::join (warningMessages, " , " ));
30483049 LogPrintf (" \n " );
@@ -4609,10 +4610,10 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
46094610
46104611 PruneBlockIndexCandidates ();
46114612
4612- LogPrintf (" %s: hashBestChain=%s height=%d date=%s progress=%f \n " , __func__,
4613+ LogPrintf (" %s: hashBestChain=%s height=%d date=%s progress=%.3f \n " , __func__,
46134614 chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (),
46144615 DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , chainActive.Tip ()->GetBlockTime ()),
4615- GuessVerificationProgress (chainparams. TxData (), chainActive. Tip () ));
4616+ GuessVerificationProgress (chainActive. Tip (), chainparams. GetConsensus (). nPowTargetSpacing ));
46164617
46174618 return true ;
46184619}
@@ -5317,22 +5318,20 @@ void DumpMempool(void)
53175318 }
53185319}
53195320
5320- // ! Guess how far we are in the verification process at the given block index
5321- double GuessVerificationProgress (const ChainTxData& data, CBlockIndex *pindex) {
5322- if (pindex == NULL )
5321+ // Guess how far we are in the verification process at the given block index.
5322+ // Since we have signed fixed-interval blocks, estimating progress is a very easy.
5323+ // We can extrapolate the last block time to the current time to estimate how many more blocks
5324+ // we expect.
5325+ double GuessVerificationProgress (CBlockIndex *pindex, int64_t blockInterval) {
5326+ if (pindex == NULL || pindex->nHeight < 2 )
53235327 return 0.0 ;
53245328
53255329 int64_t nNow = time (NULL );
5326-
5327- double fTxTotal ;
5328-
5329- if (pindex->nChainTx <= data.nTxCount ) {
5330- fTxTotal = data.nTxCount + (nNow - data.nTime ) * data.dTxRate ;
5331- } else {
5332- fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime ()) * data.dTxRate ;
5333- }
5334-
5335- return pindex->nChainTx / fTxTotal ;
5330+ int64_t moreBlocksExpected = (nNow - pindex->GetBlockTime ()) / blockInterval;
5331+ double progress = (pindex->nHeight + 0.0 ) / (pindex->nHeight + moreBlocksExpected);
5332+ // Round to 3 digits to avoid 0.999999 when finished.
5333+ progress = ceil (progress * 1000.0 ) / 1000.0 ;
5334+ return progress;
53365335}
53375336
53385337class CMainCleanup
0 commit comments