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 /** Checkpointing mode */
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 // Return conservative estimate of total number of blocks, 0 if unknown
37 int GetTotalBlocksEstimate();
39 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
40 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
42 // Returns last checkpoint timestamp
43 int GetLastCheckpointTime();
45 extern uint256 hashSyncCheckpoint;
46 extern CSyncCheckpoint checkpointMessage;
47 extern uint256 hashInvalidCheckpoint;
48 extern CCriticalSection cs_hashSyncCheckpoint;
50 CBlockIndex* GetLastSyncCheckpoint();
51 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
52 bool AcceptPendingSyncCheckpoint();
53 uint256 AutoSelectSyncCheckpoint();
54 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
55 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
56 bool ResetSyncCheckpoint();
57 void AskForPendingSyncCheckpoint(CNode* pfrom);
58 bool SetCheckpointPrivKey(std::string strPrivKey);
59 bool SendSyncCheckpoint(uint256 hashCheckpoint);
60 bool IsMatureSyncCheckpoint();
61 bool IsSyncCheckpointTooOld(unsigned int nSeconds);
64 // ppcoin: synchronized checkpoint
65 class CUnsignedSyncCheckpoint
69 uint256 hashCheckpoint; // checkpoint block
73 READWRITE(this->nVersion);
74 nVersion = this->nVersion;
75 READWRITE(hashCheckpoint);
84 std::string ToString() const
89 " hashCheckpoint = %s\n"
92 hashCheckpoint.ToString().c_str());
97 printf("%s", ToString().c_str());
101 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
104 static const std::string strMasterPubKey;
105 static std::string strMasterPrivKey;
107 std::vector<unsigned char> vchMsg;
108 std::vector<unsigned char> vchSig;
123 CUnsignedSyncCheckpoint::SetNull();
130 return (hashCheckpoint == 0);
133 uint256 GetHash() const
135 return SerializeHash(*this);
138 bool RelayTo(CNode* pnode) const
140 // returns true if wasn't already sent
141 if (pnode->hashCheckpointKnown != hashCheckpoint)
143 pnode->hashCheckpointKnown = hashCheckpoint;
144 pnode->PushMessage("checkpoint", *this);
150 bool CheckSignature();
151 bool ProcessSyncCheckpoint(CNode* pfrom);