]> Git Repo - VerusCoin.git/blame - src/checkpoints.cpp
Merge pull request #2336 from petertodd/invalid-opcode-coverage
[VerusCoin.git] / src / checkpoints.cpp
CommitLineData
88216419 1// Copyright (c) 2009-2012 The Bitcoin developers
eb5fff9e 2// Distributed under the MIT/X11 software license, see the accompanying
3a25a2b9 3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
eb5fff9e 4
eb5fff9e 5#include <boost/assign/list_of.hpp> // for 'map_list_of()'
10fd7f66
GA
6#include <boost/foreach.hpp>
7
10fd7f66 8#include "checkpoints.h"
eb5fff9e 9
ed6d0b5f
PW
10#include "main.h"
11#include "uint256.h"
12
eb5fff9e
GA
13namespace Checkpoints
14{
15 typedef std::map<int, uint256> MapCheckpoints;
16
9f2467ad
PW
17 // How many times we expect transactions after the last checkpoint to
18 // be slower. This number is conservative. On multi-core CPUs with
19 // parallel signature checking enabled, this number is way too high.
20 // We prefer a progressbar that's faster at the end than the other
21 // way around, though.
22 static const double fSigcheckVerificationFactor = 15.0;
23
24 struct CCheckpointData {
25 const MapCheckpoints *mapCheckpoints;
26 int64 nTimeLastCheckpoint;
27 int64 nTransactionsLastCheckpoint;
28 double fTransactionsPerDay;
29 };
30
10fd7f66
GA
31 // What makes a good checkpoint block?
32 // + Is surrounded by blocks with reasonable timestamps
33 // (no blocks before with a timestamp after, none after with
34 // timestamp before)
35 // + Contains no strange transactions
eb5fff9e
GA
36 static MapCheckpoints mapCheckpoints =
37 boost::assign::map_list_of
38 ( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
39 ( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
eb5fff9e
GA
40 ( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"))
41 (105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"))
eb5fff9e 42 (134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
8c12851e 43 (168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
80cfc3a4 44 (193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317"))
5d32d3f8 45 (210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e"))
a53465a6 46 (216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e"))
eb5fff9e 47 ;
9f2467ad
PW
48 static const CCheckpointData data = {
49 &mapCheckpoints,
50 1357902690, // * UNIX timestamp of last checkpoint block
51 11011160, // * total number of transactions between genesis and last checkpoint
52 // (the tx=... number in the SetBestChain debug.log lines)
53 50000.0 // * estimated number of transactions per day after checkpoint
54 };
eb5fff9e 55
9f2467ad 56 static MapCheckpoints mapCheckpointsTestnet =
c87c8cd1
GA
57 boost::assign::map_list_of
58 ( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
59 ;
9f2467ad
PW
60 static const CCheckpointData dataTestnet = {
61 &mapCheckpointsTestnet,
62 1338180505,
63 16341,
64 300
65 };
66
67 const CCheckpointData &Checkpoints() {
68 if (fTestNet)
69 return dataTestnet;
70 else
71 return data;
72 }
c87c8cd1 73
eb5fff9e
GA
74 bool CheckBlock(int nHeight, const uint256& hash)
75 {
e6955d04 76 if (!GetBoolArg("-checkpoints", true))
857b3ad9
JG
77 return true;
78
9f2467ad 79 const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
eb5fff9e 80
c87c8cd1
GA
81 MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
82 if (i == checkpoints.end()) return true;
eb5fff9e
GA
83 return hash == i->second;
84 }
85
9f2467ad
PW
86 // Guess how far we are in the verification process at the given block index
87 double GuessVerificationProgress(CBlockIndex *pindex) {
88 if (pindex==NULL)
89 return 0.0;
90
91 int64 nNow = time(NULL);
92
93 double fWorkBefore = 0.0; // Amount of work done before pindex
94 double fWorkAfter = 0.0; // Amount of work left after pindex (estimated)
95 // Work is defined as: 1.0 per transaction before the last checkoint, and
96 // fSigcheckVerificationFactor per transaction after.
97
98 const CCheckpointData &data = Checkpoints();
99
100 if (pindex->nChainTx <= data.nTransactionsLastCheckpoint) {
101 double nCheapBefore = pindex->nChainTx;
102 double nCheapAfter = data.nTransactionsLastCheckpoint - pindex->nChainTx;
103 double nExpensiveAfter = (nNow - data.nTimeLastCheckpoint)/86400.0*data.fTransactionsPerDay;
104 fWorkBefore = nCheapBefore;
105 fWorkAfter = nCheapAfter + nExpensiveAfter*fSigcheckVerificationFactor;
106 } else {
107 double nCheapBefore = data.nTransactionsLastCheckpoint;
108 double nExpensiveBefore = pindex->nChainTx - data.nTransactionsLastCheckpoint;
109 double nExpensiveAfter = (nNow - pindex->nTime)/86400.0*data.fTransactionsPerDay;
110 fWorkBefore = nCheapBefore + nExpensiveBefore*fSigcheckVerificationFactor;
111 fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor;
112 }
113
114 return fWorkBefore / (fWorkBefore + fWorkAfter);
115 }
116
eb5fff9e
GA
117 int GetTotalBlocksEstimate()
118 {
e6955d04 119 if (!GetBoolArg("-checkpoints", true))
857b3ad9
JG
120 return 0;
121
9f2467ad 122 const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
eb5fff9e 123
c87c8cd1 124 return checkpoints.rbegin()->first;
eb5fff9e 125 }
10fd7f66
GA
126
127 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
128 {
e6955d04 129 if (!GetBoolArg("-checkpoints", true))
857b3ad9
JG
130 return NULL;
131
9f2467ad 132 const MapCheckpoints& checkpoints = *Checkpoints().mapCheckpoints;
10fd7f66 133
c87c8cd1 134 BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
10fd7f66
GA
135 {
136 const uint256& hash = i.second;
137 std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
138 if (t != mapBlockIndex.end())
139 return t->second;
140 }
141 return NULL;
142 }
eb5fff9e 143}
This page took 0.076974 seconds and 4 git commands to generate.