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;
16 class CSyncCheckpoint;
18 // Block-chain checkpoints are compiled-in sanity checks.
19 // They are updated every release or three.
25 // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
27 // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
29 // Permissive checkpoints policy, don't perform any checking
33 // Returns true if block passes checkpoint checks
34 bool CheckHardened(int nHeight, const uint256& hash);
36 // Returns true if block passes banlist checks
37 bool CheckBanned(const uint256 &nHash);
39 // Return conservative estimate of total number of blocks, 0 if unknown
40 int GetTotalBlocksEstimate();
42 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
43 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
45 // Returns last checkpoint timestamp
46 unsigned int GetLastCheckpointTime();
48 extern uint256 hashSyncCheckpoint;
49 extern CSyncCheckpoint checkpointMessage;
50 extern uint256 hashInvalidCheckpoint;
51 extern CCriticalSection cs_hashSyncCheckpoint;
53 CBlockIndex* GetLastSyncCheckpoint();
54 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
55 bool AcceptPendingSyncCheckpoint();
56 uint256 AutoSelectSyncCheckpoint();
57 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
58 bool WantedByPendingSyncCheckpoint(const uint256 &hashBlock);
59 bool ResetSyncCheckpoint();
60 void AskForPendingSyncCheckpoint(CNode* pfrom);
61 bool SetCheckpointPrivKey(const std::string &strPrivKey);
62 bool SendSyncCheckpoint(const uint256 &hashCheckpoint);
63 bool IsMatureSyncCheckpoint();
66 // ppcoin: synchronized checkpoint
67 class CUnsignedSyncCheckpoint
71 uint256 hashCheckpoint; // checkpoint block
75 READWRITE(this->nVersion);
76 nVersion = this->nVersion;
77 READWRITE(hashCheckpoint);
81 std::string ToString() const;
84 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
87 static const std::string strMasterPubKey;
88 static std::string strMasterPrivKey;
90 std::vector<unsigned char> vchMsg;
91 std::vector<unsigned char> vchSig;
103 uint256 GetHash() const;
104 bool RelayTo(CNode* pnode) const;
105 bool CheckSignature();
106 bool ProcessSyncCheckpoint(CNode* pfrom);