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 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
15 class CSyncCheckpoint;
17 /** Block-chain checkpoints are compiled-in sanity checks.
18 * They are updated every release or three.
22 // Returns true if block passes checkpoint checks
23 bool CheckHardened(int nHeight, const uint256& hash);
25 // Return conservative estimate of total number of blocks, 0 if unknown
26 int GetTotalBlocksEstimate();
28 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
29 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
31 extern uint256 hashSyncCheckpoint;
32 extern CSyncCheckpoint checkpointMessage;
33 extern uint256 hashInvalidCheckpoint;
34 extern CCriticalSection cs_hashSyncCheckpoint;
36 CBlockIndex* GetLastSyncCheckpoint();
37 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
38 bool AcceptPendingSyncCheckpoint();
39 uint256 AutoSelectSyncCheckpoint();
40 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
41 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
42 bool ResetSyncCheckpoint();
43 void AskForPendingSyncCheckpoint(CNode* pfrom);
44 bool SetCheckpointPrivKey(std::string strPrivKey);
45 bool SendSyncCheckpoint(uint256 hashCheckpoint);
46 bool IsMatureSyncCheckpoint();
47 bool IsSyncCheckpointTooOld(unsigned int nSeconds);
50 // ppcoin: synchronized checkpoint
51 class CUnsignedSyncCheckpoint
55 uint256 hashCheckpoint; // checkpoint block
59 READWRITE(this->nVersion);
60 nVersion = this->nVersion;
61 READWRITE(hashCheckpoint);
70 std::string ToString() const
75 " hashCheckpoint = %s\n"
78 hashCheckpoint.ToString().c_str());
83 printf("%s", ToString().c_str());
87 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
90 static const std::string strMasterPubKey;
91 static std::string strMasterPrivKey;
93 std::vector<unsigned char> vchMsg;
94 std::vector<unsigned char> vchSig;
109 CUnsignedSyncCheckpoint::SetNull();
116 return (hashCheckpoint == 0);
119 uint256 GetHash() const
121 return SerializeHash(*this);
124 bool RelayTo(CNode* pnode) const
126 // returns true if wasn't already sent
127 if (pnode->hashCheckpointKnown != hashCheckpoint)
129 pnode->hashCheckpointKnown = hashCheckpoint;
130 pnode->PushMessage("checkpoint", *this);
136 bool CheckSignature();
137 bool ProcessSyncCheckpoint(CNode* pfrom);