]> Git Repo - VerusCoin.git/blame - src/checkpoints.cpp
Build fix
[VerusCoin.git] / src / checkpoints.cpp
CommitLineData
f914f1a7 1// Copyright (c) 2009-2014 The Bitcoin Core developers
fa94b9d5 2// Distributed under the MIT software license, see the accompanying
bc909a7a 3// file COPYING or https://www.opensource.org/licenses/mit-license.php .
eb5fff9e 4
10fd7f66 5#include "checkpoints.h"
eb5fff9e 6
e11712df 7#include "chainparams.h"
ed6d0b5f
PW
8#include "main.h"
9#include "uint256.h"
10
51ed9ec9
BD
11#include <stdint.h>
12
51ed9ec9
BD
13#include <boost/foreach.hpp>
14
e10dcf27
PK
15namespace Checkpoints {
16
fa94b9d5 17 /**
b05a89b2
LD
18 * How many times slower we expect checking transactions after the last
19 * checkpoint to be (from checking signatures, which is skipped up to the
20 * last checkpoint). This number is a compromise, as it can't be accurate
21 * for every system. When reindexing from a fast disk with a slow CPU, it
fa94b9d5
MF
22 * can be up to 20, while when downloading from a slow network with a
23 * fast multicore CPU, it won't be much higher than 1.
24 */
39278369 25 static const double SIGCHECK_VERIFICATION_FACTOR = 5.0;
04824d85 26 bool CheckBlock(const CChainParams::CCheckpointData& data, int nHeight, const uint256& hash)
b599dcc6 27 {
28 const MapCheckpoints& checkpoints = data.mapCheckpoints;
29
30 MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
31 if (i == checkpoints.end()) return true;
32 return hash == i->second;
33 }
9f2467ad 34
fa94b9d5 35 //! Guess how far we are in the verification process at the given block index
04824d85 36 double GuessVerificationProgress(const CChainParams::CCheckpointData& data, CBlockIndex *pindex, bool fSigchecks) {
9f2467ad
PW
37 if (pindex==NULL)
38 return 0.0;
39
51ed9ec9 40 int64_t nNow = time(NULL);
9f2467ad 41
39278369 42 double fSigcheckVerificationFactor = fSigchecks ? SIGCHECK_VERIFICATION_FACTOR : 1.0;
9f2467ad
PW
43 double fWorkBefore = 0.0; // Amount of work done before pindex
44 double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
e7906d18 45 // Work is defined as: 1.0 per transaction before the last checkpoint, and
9f2467ad
PW
46 // fSigcheckVerificationFactor per transaction after.
47
9f2467ad
PW
48 if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
49 double nCheapBefore = pindex->nChainTx;
50 double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
51 double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
52 fWorkBefore = nCheapBefore;
53 fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
54 } else {
55 double nCheapBefore = data.nTransactionsLastCheckpoint;
56 double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
209377a7 57 double nExpensiveAfter = (nNow - pindex->GetBlockTime())/86400.0*data.fTransactionsPerDay;
9f2467ad
PW
58 fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
59 fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
60 }
61
62 return fWorkBefore / (fWorkBefore + fWorkAfter);
63 }
64
04824d85 65 int GetTotalBlocksEstimate(const CChainParams::CCheckpointData& data)
eb5fff9e 66 {
11982d36 67 const MapCheckpoints& checkpoints = data.mapCheckpoints;
857b3ad9 68
a8cdaf5c
CF
69 if (checkpoints.empty())
70 return 0;
eb5fff9e 71
c87c8cd1 72 return checkpoints.rbegin()->first;
eb5fff9e 73 }
10fd7f66 74
04824d85 75 CBlockIndex* GetLastCheckpoint(const CChainParams::CCheckpointData& data)
10fd7f66 76 {
11982d36 77 const MapCheckpoints& checkpoints = data.mapCheckpoints;
10fd7f66 78
c87c8cd1 79 BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
10fd7f66
GA
80 {
81 const uint256& hash = i.second;
145d5be8 82 BlockMap::const_iterator t = mapBlockIndex.find(hash);
10fd7f66
GA
83 if (t != mapBlockIndex.end())
84 return t->second;
85 }
86 return NULL;
87 }
e10dcf27
PK
88
89} // namespace Checkpoints
This page took 0.249668 seconds and 4 git commands to generate.