1 // Copyright (c) 2009-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "checkpoints.h"
8 #include "chainparams.h"
14 #include <boost/foreach.hpp>
16 namespace Checkpoints
{
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.
26 static const double SIGCHECK_VERIFICATION_FACTOR
= 5.0;
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
) {
33 int64_t nNow
= time(NULL
);
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.
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
;
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
;
55 return fWorkBefore
/ (fWorkBefore
+ fWorkAfter
);
58 int GetTotalBlocksEstimate(const CCheckpointData
& data
)
60 const MapCheckpoints
& checkpoints
= data
.mapCheckpoints
;
62 if (checkpoints
.empty())
65 return checkpoints
.rbegin()->first
;
68 CBlockIndex
* GetLastCheckpoint(const CCheckpointData
& data
)
70 const MapCheckpoints
& checkpoints
= data
.mapCheckpoints
;
72 BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type
& i
, checkpoints
)
74 const uint256
& hash
= i
.second
;
75 BlockMap::const_iterator t
= mapBlockIndex
.find(hash
);
76 if (t
!= mapBlockIndex
.end())
82 } // namespace Checkpoints