From a4bac66cca62a5514579a15d198f3baa80683172 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 4 Jan 2017 07:09:02 -0800 Subject: [MOVEONLY] Move progress estimation out of checkpoints --- src/checkpoints.cpp | 40 ---------------------------------------- src/checkpoints.h | 2 -- src/qt/clientmodel.cpp | 2 +- src/rpc/blockchain.cpp | 2 +- src/validation.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/validation.h | 4 ++++ src/wallet/wallet.cpp | 8 ++++---- 7 files changed, 52 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 9a20747049..13b5876530 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -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; diff --git a/src/checkpoints.h b/src/checkpoints.h index f826de2319..7449d1063b 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -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 diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 20a04dc8a8..aefcc47255 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -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() diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a127f10b8b..a3954d81fc 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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)); diff --git a/src/validation.cpp b/src/validation.cpp index ca1e5a713c..ea43d4f171 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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: diff --git a/src/validation.h b/src/validation.h index 981f659633..0288e9163e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -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 pblock = std::shared_ptr()); 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 diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9676832560..50eab61739 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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 -- cgit v1.2.3 From 3641141c8f9bdc68fcc0792ce8842a8e33ea7320 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 4 Jan 2017 07:31:56 -0800 Subject: Move tx estimation data out of CCheckPointData --- src/chainparams.cpp | 14 ++++++++++++-- src/chainparams.h | 5 +++++ src/qt/clientmodel.cpp | 2 +- src/rpc/blockchain.cpp | 2 +- src/validation.cpp | 6 +++--- src/validation.h | 4 ++-- src/wallet/wallet.cpp | 8 ++++---- 7 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1e294da9f4..06196de362 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -151,7 +151,10 @@ public: (225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")) (250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")) (279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")) - (295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")), + (295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")) + }; + + chainTxData = ChainTxData{ 1397080064, // * UNIX timestamp of last checkpoint block 36544669, // * total number of transactions between genesis and last checkpoint // (the tx=... number in the SetBestChain debug.log lines) @@ -234,6 +237,9 @@ public: checkpointData = (CCheckpointData) { boost::assign::map_list_of ( 546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")), + }; + + chainTxData = ChainTxData{ 1337966069, 1488, 300 @@ -297,11 +303,15 @@ public: checkpointData = (CCheckpointData){ boost::assign::map_list_of - ( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")), + ( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")) + }; + + chainTxData = ChainTxData{ 0, 0, 0 }; + base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,111); base58Prefixes[SCRIPT_ADDRESS] = std::vector(1,196); base58Prefixes[SECRET_KEY] = std::vector(1,239); diff --git a/src/chainparams.h b/src/chainparams.h index 381bac12f9..8dbde9fc24 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -28,6 +28,9 @@ typedef std::map MapCheckpoints; struct CCheckpointData { MapCheckpoints mapCheckpoints; +}; + +struct ChainTxData { int64_t nTimeLastCheckpoint; int64_t nTransactionsLastCheckpoint; double fTransactionsPerDay; @@ -73,6 +76,7 @@ public: const std::vector& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } const std::vector& FixedSeeds() const { return vFixedSeeds; } const CCheckpointData& Checkpoints() const { return checkpointData; } + const ChainTxData& TxData() const { return chainTxData; } protected: CChainParams() {} @@ -90,6 +94,7 @@ protected: bool fRequireStandard; bool fMineBlocksOnDemand; CCheckpointData checkpointData; + ChainTxData chainTxData; }; /** diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index aefcc47255..bb10e49422 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -130,7 +130,7 @@ double ClientModel::getVerificationProgress(const CBlockIndex *tipIn) const LOCK(cs_main); tip = chainActive.Tip(); } - return GuessVerificationProgress(Params().Checkpoints(), tip); + return GuessVerificationProgress(Params().TxData(), tip); } void ClientModel::updateTimer() diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index a3954d81fc..09671ea20e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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", GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()))); + obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); diff --git a/src/validation.cpp b/src/validation.cpp index ea43d4f171..14d5dbe452 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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()), - GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); + GuessVerificationProgress(chainParams.TxData(), 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()), - GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip())); + GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); return true; } @@ -4152,7 +4152,7 @@ void DumpMempool(void) 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) { +double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex, bool fSigchecks) { if (pindex==NULL) return 0.0; diff --git a/src/validation.h b/src/validation.h index 0288e9163e..7bde123bfe 100644 --- a/src/validation.h +++ b/src/validation.h @@ -42,7 +42,7 @@ class CScriptCheck; class CTxMemPool; class CValidationInterface; class CValidationState; -class CCheckpointData; +struct ChainTxData; struct PrecomputedTransactionData; struct LockPoints; @@ -281,7 +281,7 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, 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); +double GuessVerificationProgress(const ChainTxData& 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. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 50eab61739..7101a1a3be 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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 = GuessVerificationProgress(chainParams.Checkpoints(), pindex, false); - double dProgressTip = GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false); + double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex, false); + double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip(), false); while (pindex) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) - ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); + ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), 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, GuessVerificationProgress(chainParams.Checkpoints(), pindex)); + LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex)); } } ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI -- cgit v1.2.3 From 6dd81169fc33f0c9720afe0b9b52ed4539e59580 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 4 Jan 2017 13:09:20 -0800 Subject: Remove SIGCHECK_VERIFICATION_FACTOR --- src/validation.cpp | 34 ++++++---------------------------- src/validation.h | 2 +- src/wallet/wallet.cpp | 6 +++--- 3 files changed, 10 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/validation.cpp b/src/validation.cpp index 14d5dbe452..0ff9a00254 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4141,44 +4141,22 @@ 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 ChainTxData& data, CBlockIndex *pindex, bool fSigchecks) { - if (pindex==NULL) +double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) { + 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. + double fTxTotal; 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; + fTxTotal = data.nTransactionsLastCheckpoint + (nNow - data.nTimeLastCheckpoint) / 86400.0 * data.fTransactionsPerDay; } 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; + fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime()) / 86400.0 * data.fTransactionsPerDay; } - return fWorkBefore / (fWorkBefore + fWorkAfter); + return pindex->nChainTx / fTxTotal; } class CMainCleanup diff --git a/src/validation.h b/src/validation.h index 7bde123bfe..ebfff66ea1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -281,7 +281,7 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, 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 ChainTxData& data, CBlockIndex* pindex, bool fSigchecks = true); +double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex); /** * Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7101a1a3be..686efe7c43 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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 = GuessVerificationProgress(chainParams.TxData(), pindex, false); - double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip(), false); + double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex); + double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip()); while (pindex) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) - ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); + ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); CBlock block; ReadBlockFromDisk(block, pindex, Params().GetConsensus()); -- cgit v1.2.3 From e356d9a758fff44841c0a630ef6b048de05e53f0 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 4 Jan 2017 07:35:39 -0800 Subject: Shorten variable names and switch to tx/s --- src/chainparams.cpp | 4 ++-- src/chainparams.h | 6 +++--- src/validation.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 06196de362..626dc9f8cb 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -158,7 +158,7 @@ public: 1397080064, // * UNIX timestamp of last checkpoint block 36544669, // * total number of transactions between genesis and last checkpoint // (the tx=... number in the SetBestChain debug.log lines) - 60000.0 // * estimated number of transactions per day after checkpoint + 0.7 // * estimated number of transactions per second after checkpoint }; } }; @@ -242,7 +242,7 @@ public: chainTxData = ChainTxData{ 1337966069, 1488, - 300 + 0.0035 }; } diff --git a/src/chainparams.h b/src/chainparams.h index 8dbde9fc24..db524e8f8e 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -31,9 +31,9 @@ struct CCheckpointData { }; struct ChainTxData { - int64_t nTimeLastCheckpoint; - int64_t nTransactionsLastCheckpoint; - double fTransactionsPerDay; + int64_t nTime; + int64_t nTxCount; + double dTxRate; }; /** diff --git a/src/validation.cpp b/src/validation.cpp index 0ff9a00254..f9b1cd52ec 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4150,10 +4150,10 @@ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) { double fTxTotal; - if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) { - fTxTotal = data.nTransactionsLastCheckpoint + (nNow - data.nTimeLastCheckpoint) / 86400.0 * data.fTransactionsPerDay; + if (pindex->nChainTx <= data.nTxCount) { + fTxTotal = data.nTxCount + (nNow - data.nTime) * data.dTxRate; } else { - fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime()) / 86400.0 * data.fTransactionsPerDay; + fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime()) * data.dTxRate; } return pindex->nChainTx / fTxTotal; -- cgit v1.2.3 From df3637177a5988261e6ce704018e14140401e1e1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 4 Jan 2017 08:20:37 -0800 Subject: Update estimated transaction count data --- src/chainparams.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 626dc9f8cb..66b5d48fd9 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -155,10 +155,11 @@ public: }; chainTxData = ChainTxData{ - 1397080064, // * UNIX timestamp of last checkpoint block - 36544669, // * total number of transactions between genesis and last checkpoint + // Data as of block 00000000000000000166d612d5595e2b1cd88d71d695fc580af64d8da8658c23 (height 446482). + 1483472411, // * UNIX timestamp of last known number of transactions + 184495391, // * total number of transactions between genesis and that timestamp // (the tx=... number in the SetBestChain debug.log lines) - 0.7 // * estimated number of transactions per second after checkpoint + 3.2 // * estimated number of transactions per second after that timestamp }; } }; @@ -240,9 +241,10 @@ public: }; chainTxData = ChainTxData{ - 1337966069, - 1488, - 0.0035 + // Data as of block 00000000c2872f8f8a8935c8e3c5862be9038c97d4de2cf37ed496991166928a (height 1063660) + 1483546230, + 12834668, + 0.15 }; } -- cgit v1.2.3