PPCoin: Remove automatic checkpoint code
[novacoin.git] / src / checkpoints.h
1 // Copyright (c) 2011 The Bitcoin developers
2 // Copyright (c) 2011-2012 The PPCoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_CHECKPOINT_H
6 #define  BITCOIN_CHECKPOINT_H
7
8 #include <map>
9 #include "util.h"
10
11 // ppcoin: auto checkpoint min at 8 hours; max at 16 hours
12 #define AUTO_CHECKPOINT_MIN_SPAN   (60 * 60 * 8)
13 #define AUTO_CHECKPOINT_MAX_SPAN   (60 * 60 * 16)
14 #define AUTO_CHECKPOINT_TRUST_SPAN (60 * 60 * 24)
15
16 class uint256;
17 class CBlockIndex;
18 class CSyncCheckpoint;
19
20 //
21 // Block-chain checkpoints are compiled-in sanity checks.
22 // They are updated every release or three.
23 //
24 namespace Checkpoints
25 {
26     // Returns true if block passes checkpoint checks
27     bool CheckHardened(int nHeight, const uint256& hash);
28
29     // Return conservative estimate of total number of blocks, 0 if unknown
30     int GetTotalBlocksEstimate();
31
32     // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
33     CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
34
35     extern uint256 hashSyncCheckpoint;
36     extern CSyncCheckpoint checkpointMessage;
37     extern uint256 hashInvalidCheckpoint;
38     extern CCriticalSection cs_hashSyncCheckpoint;
39
40     CBlockIndex* GetLastSyncCheckpoint();
41     bool AcceptPendingSyncCheckpoint();
42     uint256 AutoSelectSyncCheckpoint();
43     bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
44     bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
45 }
46
47 // ppcoin: synchronized checkpoint
48 class CUnsignedSyncCheckpoint
49 {
50 public:
51     int nVersion;
52     uint256 hashCheckpoint;      // checkpoint block
53
54     IMPLEMENT_SERIALIZE
55     (
56         READWRITE(this->nVersion);
57         nVersion = this->nVersion;
58         READWRITE(hashCheckpoint);
59     )
60
61     void SetNull()
62     {
63         nVersion = 1;
64         hashCheckpoint = 0;
65     }
66
67     std::string ToString() const
68     {
69         return strprintf(
70                 "CSyncCheckpoint(\n"
71                 "    nVersion       = %d\n"
72                 "    hashCheckpoint = %s\n"
73                 ")\n",
74             nVersion,
75             hashCheckpoint.ToString().c_str());
76     }
77
78     void print() const
79     {
80         printf("%s", ToString().c_str());
81     }
82 };
83
84 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
85 {
86 public:
87     static const std::string strMasterPubKey;
88
89     std::vector<unsigned char> vchMsg;
90     std::vector<unsigned char> vchSig;
91
92     CSyncCheckpoint()
93     {
94         SetNull();
95     }
96
97     IMPLEMENT_SERIALIZE
98     (
99         READWRITE(vchMsg);
100         READWRITE(vchSig);
101     )
102
103     void SetNull()
104     {
105         CUnsignedSyncCheckpoint::SetNull();
106         vchMsg.clear();
107         vchSig.clear();
108     }
109
110     bool IsNull() const
111     {
112         return (hashCheckpoint == 0);
113     }
114
115     uint256 GetHash() const
116     {
117         return SerializeHash(*this);
118     }
119
120     bool RelayTo(CNode* pnode) const
121     {
122         // returns true if wasn't already sent
123         if (pnode->hashCheckpointKnown != hashCheckpoint)
124         {
125             pnode->hashCheckpointKnown = hashCheckpoint;
126             pnode->PushMessage("checkpoint", *this);
127             return true;
128         }
129         return false;
130     }
131
132     bool CheckSignature();
133     bool ProcessSyncCheckpoint(CNode* pfrom);
134 };
135
136 #endif