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
14 // max 1 hour before latest block
15 static const int64_t CHECKPOINT_MAX_SPAN = nOneHour;
24 class CSyncCheckpoint;
27 /** Block-chain checkpoints are compiled-in sanity checks.
28 * They are updated every release or three.
32 /** Checkpointing mode */
35 // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
37 // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
39 // Permissive checkpoints policy, don't perform any checking
43 // Returns true if block passes checkpoint checks
44 bool CheckHardened(int nHeight, const uint256& hash);
46 // Returns true if block passes banlist checks
47 bool CheckBanned(const uint256 &nHash);
49 // Return conservative estimate of total number of blocks, 0 if unknown
50 int GetTotalBlocksEstimate();
52 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
53 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
55 // Returns last checkpoint timestamp
56 unsigned int GetLastCheckpointTime();
58 extern uint256 hashSyncCheckpoint;
59 extern CSyncCheckpoint checkpointMessage;
60 extern uint256 hashInvalidCheckpoint;
61 extern CCriticalSection cs_hashSyncCheckpoint;
63 CBlockIndex* GetLastSyncCheckpoint();
64 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
65 bool AcceptPendingSyncCheckpoint();
66 uint256 AutoSelectSyncCheckpoint();
67 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
68 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
69 bool ResetSyncCheckpoint();
70 void AskForPendingSyncCheckpoint(CNode* pfrom);
71 bool SetCheckpointPrivKey(std::string strPrivKey);
72 bool SendSyncCheckpoint(uint256 hashCheckpoint);
73 bool IsMatureSyncCheckpoint();
76 // ppcoin: synchronized checkpoint
77 class CUnsignedSyncCheckpoint
81 uint256 hashCheckpoint; // checkpoint block
85 READWRITE(this->nVersion);
86 nVersion = this->nVersion;
87 READWRITE(hashCheckpoint);
96 std::string ToString() const
101 " hashCheckpoint = %s\n"
104 hashCheckpoint.ToString().c_str());
108 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
111 static const std::string strMasterPubKey;
112 static std::string strMasterPrivKey;
114 std::vector<unsigned char> vchMsg;
115 std::vector<unsigned char> vchSig;
127 uint256 GetHash() const;
128 bool RelayTo(CNode* pnode) const;
129 bool CheckSignature();
130 bool ProcessSyncCheckpoint(CNode* pfrom);