Skip to content

Commit fac0f30

Browse files
committed
Merge #9472: Disentangle progress estimation from checkpoints and update it
df36371 Update estimated transaction count data (Pieter Wuille) e356d9a Shorten variable names and switch to tx/s (Pieter Wuille) 6dd8116 Remove SIGCHECK_VERIFICATION_FACTOR (Pieter Wuille) 3641141 Move tx estimation data out of CCheckPointData (Pieter Wuille) a4bac66 [MOVEONLY] Move progress estimation out of checkpoints (Pieter Wuille)
2 parents a65ced1 + df36371 commit fac0f30

File tree

9 files changed

+58
-61
lines changed

9 files changed

+58
-61
lines changed

src/chainparams.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ class CMainParams : public CChainParams {
151151
(225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932"))
152152
(250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214"))
153153
(279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40"))
154-
(295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")),
155-
1397080064, // * UNIX timestamp of last checkpoint block
156-
36544669, // * total number of transactions between genesis and last checkpoint
154+
(295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983"))
155+
};
156+
157+
chainTxData = ChainTxData{
158+
// Data as of block 00000000000000000166d612d5595e2b1cd88d71d695fc580af64d8da8658c23 (height 446482).
159+
1483472411, // * UNIX timestamp of last known number of transactions
160+
184495391, // * total number of transactions between genesis and that timestamp
157161
// (the tx=... number in the SetBestChain debug.log lines)
158-
60000.0 // * estimated number of transactions per day after checkpoint
162+
3.2 // * estimated number of transactions per second after that timestamp
159163
};
160164
}
161165
};
@@ -234,9 +238,13 @@ class CTestNetParams : public CChainParams {
234238
checkpointData = (CCheckpointData) {
235239
boost::assign::map_list_of
236240
( 546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")),
237-
1337966069,
238-
1488,
239-
300
241+
};
242+
243+
chainTxData = ChainTxData{
244+
// Data as of block 00000000c2872f8f8a8935c8e3c5862be9038c97d4de2cf37ed496991166928a (height 1063660)
245+
1483546230,
246+
12834668,
247+
0.15
240248
};
241249

242250
}
@@ -297,11 +305,15 @@ class CRegTestParams : public CChainParams {
297305

298306
checkpointData = (CCheckpointData){
299307
boost::assign::map_list_of
300-
( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")),
308+
( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"))
309+
};
310+
311+
chainTxData = ChainTxData{
301312
0,
302313
0,
303314
0
304315
};
316+
305317
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
306318
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
307319
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);

src/chainparams.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ typedef std::map<int, uint256> MapCheckpoints;
2828

2929
struct CCheckpointData {
3030
MapCheckpoints mapCheckpoints;
31-
int64_t nTimeLastCheckpoint;
32-
int64_t nTransactionsLastCheckpoint;
33-
double fTransactionsPerDay;
31+
};
32+
33+
struct ChainTxData {
34+
int64_t nTime;
35+
int64_t nTxCount;
36+
double dTxRate;
3437
};
3538

3639
/**
@@ -73,6 +76,7 @@ class CChainParams
7376
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
7477
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
7578
const CCheckpointData& Checkpoints() const { return checkpointData; }
79+
const ChainTxData& TxData() const { return chainTxData; }
7680
protected:
7781
CChainParams() {}
7882

@@ -90,6 +94,7 @@ class CChainParams
9094
bool fRequireStandard;
9195
bool fMineBlocksOnDemand;
9296
CCheckpointData checkpointData;
97+
ChainTxData chainTxData;
9398
};
9499

95100
/**

src/checkpoints.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,6 @@
1515

1616
namespace Checkpoints {
1717

18-
/**
19-
* How many times slower we expect checking transactions after the last
20-
* checkpoint to be (from checking signatures, which is skipped up to the
21-
* last checkpoint). This number is a compromise, as it can't be accurate
22-
* for every system. When reindexing from a fast disk with a slow CPU, it
23-
* can be up to 20, while when downloading from a slow network with a
24-
* fast multicore CPU, it won't be much higher than 1.
25-
*/
26-
static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
27-
28-
//! Guess how far we are in the verification process at the given block index
29-
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
30-
if (pindex==NULL)
31-
return 0.0;
32-
33-
int64_t nNow = time(NULL);
34-
35-
double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
36-
double fWorkBefore = 0.0; // Amount of work done before pindex
37-
double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
38-
// Work is defined as: 1.0 per transaction before the last checkpoint, and
39-
// fSigcheckVerificationFactor per transaction after.
40-
41-
if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
42-
double nCheapBefore = pindex->nChainTx;
43-
double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
44-
double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
45-
fWorkBefore = nCheapBefore;
46-
fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
47-
} else {
48-
double nCheapBefore = data.nTransactionsLastCheckpoint;
49-
double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
50-
double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
51-
fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
52-
fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
53-
}
54-
55-
return fWorkBefore / (fWorkBefore + fWorkAfter);
56-
}
57-
5818
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
5919
{
6020
const MapCheckpoints& checkpoints = data.mapCheckpoints;

src/checkpoints.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace Checkpoints
2222
//! Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
2323
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data);
2424

25-
double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex* pindex, bool fSigchecks = true);
26-
2725
} //namespace Checkpoints
2826

2927
#endif // BITCOIN_CHECKPOINTS_H

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 Checkpoints::GuessVerificationProgress(Params().Checkpoints(), tip);
133+
return GuessVerificationProgress(Params().TxData(), tip);
134134
}
135135

136136
void ClientModel::updateTimer()

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
11201120
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
11211121
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
11221122
obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast()));
1123-
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
1123+
obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip())));
11241124
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
11251125
obj.push_back(Pair("pruned", fPruneMode));
11261126

src/validation.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
21062106
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), chainActive.Tip()->nVersion,
21072107
log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx,
21082108
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
2109-
Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
2109+
GuessVerificationProgress(chainParams.TxData(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
21102110
if (!warningMessages.empty())
21112111
LogPrintf(" warning='%s'", boost::algorithm::join(warningMessages, ", "));
21122112
LogPrintf("\n");
@@ -3500,7 +3500,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
35003500
LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__,
35013501
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(),
35023502
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
3503-
Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()));
3503+
GuessVerificationProgress(chainparams.TxData(), chainActive.Tip()));
35043504

35053505
return true;
35063506
}
@@ -4198,6 +4198,24 @@ void DumpMempool(void)
41984198
}
41994199
}
42004200

4201+
//! Guess how far we are in the verification process at the given block index
4202+
double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) {
4203+
if (pindex == NULL)
4204+
return 0.0;
4205+
4206+
int64_t nNow = time(NULL);
4207+
4208+
double fTxTotal;
4209+
4210+
if (pindex->nChainTx <= data.nTxCount) {
4211+
fTxTotal = data.nTxCount + (nNow - data.nTime) * data.dTxRate;
4212+
} else {
4213+
fTxTotal = pindex->nChainTx + (nNow - pindex->GetBlockTime()) * data.dTxRate;
4214+
}
4215+
4216+
return pindex->nChainTx / fTxTotal;
4217+
}
4218+
42014219
class CMainCleanup
42024220
{
42034221
public:

src/validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CScriptCheck;
4242
class CTxMemPool;
4343
class CValidationInterface;
4444
class CValidationState;
45+
struct ChainTxData;
4546

4647
struct PrecomputedTransactionData;
4748
struct LockPoints;
@@ -281,6 +282,9 @@ bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::P
281282
bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
282283
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
283284

285+
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
286+
double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
287+
284288
/**
285289
* Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.
286290
* The user sets the target (in MB) on the command line or in config file. This will be run on startup and whenever new

src/wallet/wallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,12 +1479,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
14791479
pindex = chainActive.Next(pindex);
14801480

14811481
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
1482-
double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false);
1483-
double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false);
1482+
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
1483+
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
14841484
while (pindex)
14851485
{
14861486
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
1487-
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
1487+
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((GuessVerificationProgress(chainParams.TxData(), pindex) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
14881488

14891489
CBlock block;
14901490
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
@@ -1497,7 +1497,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
14971497
pindex = chainActive.Next(pindex);
14981498
if (GetTime() >= nNow + 60) {
14991499
nNow = GetTime();
1500-
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex));
1500+
LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
15011501
}
15021502
}
15031503
ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI

0 commit comments

Comments
 (0)