1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Copyright (c) 2011-2013 The PPCoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_CHECKPOINT_H
6 #define BITCOIN_CHECKPOINT_H
12 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
16 class CSyncCheckpoint;
18 /** Block-chain checkpoints are compiled-in sanity checks.
19 * They are updated every release or three.
23 // Returns true if block passes checkpoint checks
24 bool CheckHardened(int nHeight, const uint256& hash);
26 // Return conservative estimate of total number of blocks, 0 if unknown
27 int GetTotalBlocksEstimate();
29 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
30 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
32 extern uint256 hashSyncCheckpoint;
33 extern CSyncCheckpoint checkpointMessage;
34 extern uint256 hashInvalidCheckpoint;
35 extern CCriticalSection cs_hashSyncCheckpoint;
37 CBlockIndex* GetLastSyncCheckpoint();
38 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
39 bool AcceptPendingSyncCheckpoint();
40 uint256 AutoSelectSyncCheckpoint();
41 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
42 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
43 bool ResetSyncCheckpoint();
44 void AskForPendingSyncCheckpoint(CNode* pfrom);
45 bool SetCheckpointPrivKey(std::string strPrivKey);
46 bool SendSyncCheckpoint(uint256 hashCheckpoint);
47 bool IsMatureSyncCheckpoint();
48 bool IsSyncCheckpointTooOld(unsigned int nSeconds);
51 // ppcoin: synchronized checkpoint
52 class CUnsignedSyncCheckpoint
56 uint256 hashCheckpoint; // checkpoint block
60 READWRITE(this->nVersion);
61 nVersion = this->nVersion;
62 READWRITE(hashCheckpoint);
71 std::string ToString() const
76 " hashCheckpoint = %s\n"
79 hashCheckpoint.ToString().c_str());
84 printf("%s", ToString().c_str());
88 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
91 static const std::string strMasterPubKey;
92 static std::string strMasterPrivKey;
94 std::vector<unsigned char> vchMsg;
95 std::vector<unsigned char> vchSig;
110 CUnsignedSyncCheckpoint::SetNull();
117 return (hashCheckpoint == 0);
120 uint256 GetHash() const
122 return SerializeHash(*this);
125 bool RelayTo(CNode* pnode) const
127 // returns true if wasn't already sent
128 if (pnode->hashCheckpointKnown != hashCheckpoint)
130 pnode->hashCheckpointKnown = hashCheckpoint;
131 pnode->PushMessage("checkpoint", *this);
137 bool CheckSignature();
138 bool ProcessSyncCheckpoint(CNode* pfrom);