Dash Core  0.12.2.1
P2P Digital Currency
checkpoints.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2014 The Bitcoin developers
2 // Copyright (c) 2014-2017 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "checkpoints.h"
7 
8 #include "chain.h"
9 #include "chainparams.h"
10 #include "validation.h"
11 #include "uint256.h"
12 
13 #include <stdint.h>
14 
15 #include <boost/foreach.hpp>
16 
17 namespace Checkpoints {
18 
27  static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
28 
30  double GuessVerificationProgress(const CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
31  if (pindex==NULL)
32  return 0.0;
33 
34  int64_t nNow = time(NULL);
35 
36  double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
37  double fWorkBefore = 0.0; // Amount of work done before pindex
38  double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
39  // Work is defined as: 1.0 per transaction before the last checkpoint, and
40  // fSigcheckVerificationFactor per transaction after.
41 
42  if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
43  double nCheapBefore = pindex->nChainTx;
44  double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
45  double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
46  fWorkBefore = nCheapBefore;
47  fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
48  } else {
49  double nCheapBefore = data.nTransactionsLastCheckpoint;
50  double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
51  double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
52  fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
53  fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
54  }
55 
56  return fWorkBefore / (fWorkBefore + fWorkAfter);
57  }
58 
60  {
61  const MapCheckpoints& checkpoints = data.mapCheckpoints;
62 
63  BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
64  {
65  const uint256& hash = i.second;
66  BlockMap::const_iterator t = mapBlockIndex.find(hash);
67  if (t != mapBlockIndex.end())
68  return t->second;
69  }
70  return NULL;
71  }
72 
73 } // namespace Checkpoints
std::map< int, uint256 > MapCheckpoints
Definition: chainparams.h:26
CBlockIndex * GetLastCheckpoint(const CCheckpointData &data)
Returns last CBlockIndex* in mapBlockIndex that is a checkpoint.
Definition: checkpoints.cpp:59
static const double SIGCHECK_VERIFICATION_FACTOR
Definition: checkpoints.cpp:27
double GuessVerificationProgress(const CCheckpointData &data, CBlockIndex *pindex, bool fSigchecks)
Guess how far we are in the verification process at the given block index.
Definition: checkpoints.cpp:30
unsigned int nChainTx
Definition: chain.h:134
int64_t GetBlockTime() const
Definition: chain.h:223
BlockMap mapBlockIndex
Definition: validation.cpp:64