1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef BITCOIN_CHECKPOINT_H
5 #define BITCOIN_CHECKPOINT_H
11 // max 1 hour before latest block
12 static const int64_t CHECKPOINT_MAX_SPAN = nOneHour;
22 class CSyncCheckpoint;
24 /** Block-chain checkpoints are compiled-in sanity checks.
25 * They are updated every release or three.
29 /** Checkpointing mode */
32 // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
34 // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
36 // Permissive checkpoints policy, don't perform any checking
40 // Returns true if block passes checkpoint checks
41 bool CheckHardened(int nHeight, const uint256& hash);
43 // Returns true if block passes banlist checks
44 bool CheckBanned(const uint256 &nHash);
46 // Return conservative estimate of total number of blocks, 0 if unknown
47 int GetTotalBlocksEstimate();
49 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
50 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
52 // Returns last checkpoint timestamp
53 unsigned int GetLastCheckpointTime();
55 extern uint256 hashSyncCheckpoint;
56 extern CSyncCheckpoint checkpointMessage;
57 extern uint256 hashInvalidCheckpoint;
58 extern CCriticalSection cs_hashSyncCheckpoint;
60 CBlockIndex* GetLastSyncCheckpoint();
61 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
62 bool AcceptPendingSyncCheckpoint();
63 uint256 AutoSelectSyncCheckpoint();
64 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
65 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
66 bool ResetSyncCheckpoint();
67 void AskForPendingSyncCheckpoint(CNode* pfrom);
68 bool SetCheckpointPrivKey(std::string strPrivKey);
69 bool SendSyncCheckpoint(uint256 hashCheckpoint);
70 bool IsMatureSyncCheckpoint();
73 // ppcoin: synchronized checkpoint
74 class CUnsignedSyncCheckpoint
78 uint256 hashCheckpoint; // checkpoint block
82 READWRITE(this->nVersion);
83 nVersion = this->nVersion;
84 READWRITE(hashCheckpoint);
93 std::string ToString() const
98 " hashCheckpoint = %s\n"
101 hashCheckpoint.ToString().c_str());
105 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
108 static const std::string strMasterPubKey;
109 static std::string strMasterPrivKey;
111 std::vector<unsigned char> vchMsg;
112 std::vector<unsigned char> vchSig;
127 CUnsignedSyncCheckpoint::SetNull();
134 return (hashCheckpoint == 0);
137 uint256 GetHash() const
139 return SerializeHash(*this);
142 bool RelayTo(CNode* pnode) const
144 // returns true if wasn't already sent
145 if (pnode->hashCheckpointKnown != hashCheckpoint)
147 pnode->hashCheckpointKnown = hashCheckpoint;
148 pnode->PushMessage("checkpoint", *this);
154 bool CheckSignature();
155 bool ProcessSyncCheckpoint(CNode* pfrom);