Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.

Commit d776b39

Browse files
committed
Fix progress reporting issue
1 parent 931196c commit d776b39

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
130130
LOCK(cs_main);
131131
tip = chainActive.Tip();
132132
}
133-
return GuessVerificationProgress(Params().TxData(), tip);
133+
return GuessVerificationProgress(tip, Params().GetConsensus().nPowTargetSpacing);
134134
}
135135

136136
void ClientModel::updateTimer()

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
10741074
obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
10751075
obj.push_back(Pair("bestblockhash", tip->GetBlockHash().GetHex()));
10761076
obj.push_back(Pair("mediantime", (int64_t)tip->GetMedianTimePast()));
1077-
obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), tip)));
1077+
obj.push_back(Pair("verificationprogress", GuessVerificationProgress(tip, Params().GetConsensus().nPowTargetSpacing)));
10781078
obj.push_back(Pair("pruned", fPruneMode));
10791079
obj.push_back(Pair("signblock_asm", ScriptToAsmStr(tip->proof.challenge)));
10801080
obj.push_back(Pair("signblock_hex", HexStr(tip->proof.challenge.begin(), tip->proof.challenge.end())));

src/validation.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

53385337
class CMainCleanup

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams,
287287
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
288288

289289
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
290-
double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
290+
double GuessVerificationProgress(CBlockIndex* pindex, int64_t blockInterval);
291291

292292
/**
293293
* Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.

src/wallet/wallet.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,12 +1692,14 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
16921692
pindex = chainActive.Next(pindex);
16931693

16941694
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
1695-
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
1696-
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
1695+
double dProgressStart = GuessVerificationProgress(pindex, chainParams.GetConsensus().nPowTargetSpacing);
1696+
double dProgressTip = GuessVerificationProgress(chainActive.Tip(), chainParams.GetConsensus().nPowTargetSpacing);
16971697
while (pindex)
16981698
{
1699-
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
1700-
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
1699+
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) {
1700+
double progress = GuessVerificationProgress(pindex, chainParams.GetConsensus().nPowTargetSpacing);
1701+
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((progress - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
1702+
}
17011703

17021704
CBlock block;
17031705
if (ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
@@ -1713,7 +1715,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
17131715
pindex = chainActive.Next(pindex);
17141716
if (GetTime() >= nNow + 60) {
17151717
nNow = GetTime();
1716-
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
1718+
double progress = GuessVerificationProgress(pindex, chainParams.GetConsensus().nPowTargetSpacing);
1719+
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, progress);
17171720
}
17181721
}
17191722
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI

0 commit comments

Comments
 (0)