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
13 // max 1 hour before latest block
14 static const int64_t CHECKPOINT_MAX_SPAN = nOneHour;
23 class CSyncCheckpoint;
26 /** Block-chain checkpoints are compiled-in sanity checks.
27 * They are updated every release or three.
31 /** Checkpointing mode */
34 // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
36 // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
38 // Permissive checkpoints policy, don't perform any checking
42 // Returns true if block passes checkpoint checks
43 bool CheckHardened(int nHeight, const uint256& hash);
45 // Returns true if block passes banlist checks
46 bool CheckBanned(const uint256 &nHash);
48 // Return conservative estimate of total number of blocks, 0 if unknown
49 int GetTotalBlocksEstimate();
51 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
52 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
54 // Returns last checkpoint timestamp
55 unsigned int GetLastCheckpointTime();
57 extern uint256 hashSyncCheckpoint;
58 extern CSyncCheckpoint checkpointMessage;
59 extern uint256 hashInvalidCheckpoint;
60 extern CCriticalSection cs_hashSyncCheckpoint;
62 CBlockIndex* GetLastSyncCheckpoint();
63 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
64 bool AcceptPendingSyncCheckpoint();
65 uint256 AutoSelectSyncCheckpoint();
66 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
67 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
68 bool ResetSyncCheckpoint();
69 void AskForPendingSyncCheckpoint(CNode* pfrom);
70 bool SetCheckpointPrivKey(std::string strPrivKey);
71 bool SendSyncCheckpoint(uint256 hashCheckpoint);
72 bool IsMatureSyncCheckpoint();
75 // ppcoin: synchronized checkpoint
76 class CUnsignedSyncCheckpoint
80 uint256 hashCheckpoint; // checkpoint block
84 READWRITE(this->nVersion);
85 nVersion = this->nVersion;
86 READWRITE(hashCheckpoint);
95 std::string ToString() const
100 " hashCheckpoint = %s\n"
103 hashCheckpoint.ToString().c_str());
107 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
110 static const std::string strMasterPubKey;
111 static std::string strMasterPrivKey;
113 std::vector<unsigned char> vchMsg;
114 std::vector<unsigned char> vchSig;
126 uint256 GetHash() const;
127 bool RelayTo(CNode* pnode) const;
128 bool CheckSignature();
129 bool ProcessSyncCheckpoint(CNode* pfrom);