forked from DNotesCoin/DNotes2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckpoints.cpp
More file actions
93 lines (76 loc) · 3.21 KB
/
checkpoints.cpp
File metadata and controls
93 lines (76 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/foreach.hpp>
#include "checkpoints.h"
#include "txdb.h"
#include "main.h"
#include "uint256.h"
static const int nCheckpointSpan = 500;
namespace Checkpoints
{
typedef std::map<int, uint256> MapCheckpoints;
//
// What makes a good checkpoint block?
// + Is surrounded by blocks with reasonable timestamps
// (no blocks before with a timestamp after, none after with
// timestamp before)
// + Contains no strange transactions
//
static MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
( 0, uint256("0x00001123368370feb0997f471423e4445be205b9947e7053c762886317274d2a") )
( 2, uint256("0x2a95c98075c4ca1ae23f4bdc207be423efb64f347bd7ad7f0568bab5a2ea7f4f") ) // Premine
( 100, uint256("0x58c23d68b43a670f11bc5993c4194347779bde93b1e856ce2d2ec99ca3a0952c") )
( 1000, uint256("0x4d41cbcf542ef60c8e9acd8229684bf1bbbbfab062c56122dd1a30a2331f45c4") )
( 142050, uint256("0xf8825a74a619639003719cf0874f6efd200e978ff6645cd1ea61ba006d982750") )
;
// TestNet has no checkpoints
static MapCheckpoints mapCheckpointsTestnet;
// RegTest has no checkpoints
static MapCheckpoints mapCheckpointsRegTest;
bool CheckHardened(int nHeight, const uint256& hash)
{
MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet :IsRegTest() ? mapCheckpointsRegTest : mapCheckpoints);
MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
if (i == checkpoints.end()) return true;
return hash == i->second;
}
int GetTotalBlocksEstimate()
{
MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints);
if (checkpoints.empty())
return 0;
return checkpoints.rbegin()->first;
}
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
{
MapCheckpoints& checkpoints = (TestNet() ? mapCheckpointsTestnet : mapCheckpoints);
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
{
const uint256& hash = i.second;
std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
if (t != mapBlockIndex.end())
return t->second;
}
return NULL;
}
// Automatically select a suitable sync-checkpoint
const CBlockIndex* AutoSelectSyncCheckpoint()
{
const CBlockIndex *pindex = pindexBest;
// Search backward for a block within max span and maturity window
while (pindex->pprev && pindex->nHeight + nCheckpointSpan > pindexBest->nHeight)
pindex = pindex->pprev;
return pindex;
}
// Check against synchronized checkpoint
bool CheckSync(int nHeight)
{
const CBlockIndex* pindexSync = AutoSelectSyncCheckpoint();
if (nHeight <= pindexSync->nHeight)
return false;
return true;
}
}