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 // Returns last checkpoint timestamp
32 int GetLastCheckpointTime();
34 extern uint256 hashSyncCheckpoint;
35 extern CSyncCheckpoint checkpointMessage;
36 extern uint256 hashInvalidCheckpoint;
37 extern CCriticalSection cs_hashSyncCheckpoint;
39 CBlockIndex* GetLastSyncCheckpoint();
40 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
41 bool AcceptPendingSyncCheckpoint();
42 uint256 AutoSelectSyncCheckpoint();
43 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
44 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
45 bool ResetSyncCheckpoint();
46 void AskForPendingSyncCheckpoint(CNode* pfrom);
47 bool SetCheckpointPrivKey(std::string strPrivKey);
48 bool SendSyncCheckpoint(uint256 hashCheckpoint);
49 bool IsMatureSyncCheckpoint();
50 bool IsSyncCheckpointTooOld(unsigned int nSeconds);
53 // ppcoin: synchronized checkpoint
54 class CUnsignedSyncCheckpoint
58 uint256 hashCheckpoint; // checkpoint block
62 READWRITE(this->nVersion);
63 nVersion = this->nVersion;
64 READWRITE(hashCheckpoint);
73 std::string ToString() const
78 " hashCheckpoint = %s\n"
81 hashCheckpoint.ToString().c_str());
86 printf("%s", ToString().c_str());
90 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
93 static const std::string strMasterPubKey;
94 static std::string strMasterPrivKey;
96 std::vector<unsigned char> vchMsg;
97 std::vector<unsigned char> vchSig;
112 CUnsignedSyncCheckpoint::SetNull();
119 return (hashCheckpoint == 0);
122 uint256 GetHash() const
124 return SerializeHash(*this);
127 bool RelayTo(CNode* pnode) const
129 // returns true if wasn't already sent
130 if (pnode->hashCheckpointKnown != hashCheckpoint)
132 pnode->hashCheckpointKnown = hashCheckpoint;
133 pnode->PushMessage("checkpoint", *this);
139 bool CheckSignature();
140 bool ProcessSyncCheckpoint(CNode* pfrom);