[MOVEONLY] Move progress estimation out of checkpoints
This commit is contained in:
parent
7dac1e5e9e
commit
a4bac66cca
7 changed files with 52 additions and 50 deletions
|
@ -15,46 +15,6 @@
|
|||
|
||||
namespace Checkpoints {
|
||||
|
||||
/**
|
||||
* How many times slower we expect checking transactions after the last
|
||||
* checkpoint to be (from checking signatures, which is skipped up to the
|
||||
* last checkpoint). This number is a compromise, as it can't be accurate
|
||||
* for every system. When reindexing from a fast disk with a slow CPU, it
|
||||
* can be up to 20, while when downloading from a slow network with a
|
||||
* fast multicore CPU, it won't be much higher than 1.
|
||||
*/
|
||||
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
|
||||
|
||||
//! Guess how far we are in the verification process at the given block index
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
||||
if (pindex==NULL)
|
||||
return 0.0;
|
||||
|
||||
int64_t nNow = time(NULL);
|
||||
|
||||
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
|
||||
double fWorkBefore = 0.0; // Amount of work done before pindex
|
||||
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
|
||||
// Work is defined as: 1.0 per transaction before the last checkpoint, and
|
||||
// fSigcheckVerificationFactor per transaction after.
|
||||
|
||||
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
|
||||
double nCheapBefore = pindex->nChainTx;
|
||||
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
|
||||
double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
|
||||
fWorkBefore = nCheapBefore;
|
||||
fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
|
||||
} else {
|
||||
double nCheapBefore = data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
|
||||
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
|
||||
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
|
||||
}
|
||||
|
||||
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
||||
}
|
||||
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
|
||||
{
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
|
|
@ -22,8 +22,6 @@ namespace Checkpoints
|
|||
//! Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data);
|
||||
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
|
||||
|
||||
} //namespace Checkpoints
|
||||
|
||||
#endif // BITCOIN_CHECKPOINTS_H
|
||||
|
|
|
@ -130,7 +130,7 @@ double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const
|
|||
LOCK(cs_main);
|
||||
tip = chainActive.Tip();
|
||||
}
|
||||
return Checkpoints::GuessVerificationProgress(Params().Checkpoints(), tip);
|
||||
return GuessVerificationProgress(Params().Checkpoints(), tip);
|
||||
}
|
||||
|
||||
void ClientModel::updateTimer()
|
||||
|
|
|
@ -1073,7 +1073,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
|||
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
|
||||
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
||||
obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast()));
|
||||
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
|
||||
obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
|
||||
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("pruned", fPruneMode));
|
||||
|
||||
|
|
|
@ -2080,7 +2080,7 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
|
|||
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), chainActive.Tip()->nVersion,
|
||||
log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx,
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
|
||||
Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
|
||||
GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
|
||||
if (!warningMessages.empty())
|
||||
LogPrintf(" warning='%s'", boost::algorithm::join(warningMessages, ", "));
|
||||
LogPrintf("\n");
|
||||
|
@ -3445,7 +3445,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
|
|||
LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__,
|
||||
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(),
|
||||
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
|
||||
Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()));
|
||||
GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -4141,6 +4141,46 @@ void DumpMempool(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times slower we expect checking transactions after the last
|
||||
* checkpoint to be (from checking signatures, which is skipped up to the
|
||||
* last checkpoint). This number is a compromise, as it can't be accurate
|
||||
* for every system. When reindexing from a fast disk with a slow CPU, it
|
||||
* can be up to 20, while when downloading from a slow network with a
|
||||
* fast multicore CPU, it won't be much higher than 1.
|
||||
*/
|
||||
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
|
||||
|
||||
//! Guess how far we are in the verification process at the given block index
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
|
||||
if (pindex==NULL)
|
||||
return 0.0;
|
||||
|
||||
int64_t nNow = time(NULL);
|
||||
|
||||
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
|
||||
double fWorkBefore = 0.0; // Amount of work done before pindex
|
||||
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
|
||||
// Work is defined as: 1.0 per transaction before the last checkpoint, and
|
||||
// fSigcheckVerificationFactor per transaction after.
|
||||
|
||||
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
|
||||
double nCheapBefore = pindex->nChainTx;
|
||||
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
|
||||
double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
|
||||
fWorkBefore = nCheapBefore;
|
||||
fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
|
||||
} else {
|
||||
double nCheapBefore = data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
|
||||
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
|
||||
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
|
||||
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
|
||||
}
|
||||
|
||||
return fWorkBefore / (fWorkBefore + fWorkAfter);
|
||||
}
|
||||
|
||||
class CMainCleanup
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -42,6 +42,7 @@ class CScriptCheck;
|
|||
class CTxMemPool;
|
||||
class CValidationInterface;
|
||||
class CValidationState;
|
||||
class CCheckpointData;
|
||||
|
||||
struct PrecomputedTransactionData;
|
||||
struct LockPoints;
|
||||
|
@ -279,6 +280,9 @@ bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::P
|
|||
bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
|
||||
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
|
||||
|
||||
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
|
||||
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
|
||||
|
||||
/**
|
||||
* Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.
|
||||
* The user sets the target (in MB) on the command line or in config file. This will be run on startup and whenever new
|
||||
|
|
|
@ -1479,12 +1479,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||
pindex = chainActive.Next(pindex);
|
||||
|
||||
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
|
||||
double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
|
||||
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false);
|
||||
double dProgressStart = GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
|
||||
double dProgressTip = GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false);
|
||||
while (pindex)
|
||||
{
|
||||
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
|
||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
||||
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
|
||||
|
||||
CBlock block;
|
||||
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
|
||||
|
@ -1497,7 +1497,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||
pindex = chainActive.Next(pindex);
|
||||
if (GetTime() >= nNow + 60) {
|
||||
nNow = GetTime();
|
||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.Checkpoints(), pindex));
|
||||
}
|
||||
}
|
||||
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI
|
||||
|
|
Loading…
Reference in a new issue