1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Copyright (c) 2011-2012 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 STAKE_MIN_AGE (60 * 60 * 24 * 30) // minimum age 30 days for coin age
13 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
17 class CSyncCheckpoint;
19 /** Block-chain checkpoints are compiled-in sanity checks.
20 * They are updated every release or three.
24 // Returns true if block passes checkpoint checks
25 bool CheckHardened(int nHeight, const uint256& hash);
27 // Return conservative estimate of total number of blocks, 0 if unknown
28 int GetTotalBlocksEstimate();
30 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
31 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
33 extern uint256 hashSyncCheckpoint;
34 extern CSyncCheckpoint checkpointMessage;
35 extern uint256 hashInvalidCheckpoint;
36 extern CCriticalSection cs_hashSyncCheckpoint;
38 CBlockIndex* GetLastSyncCheckpoint();
39 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
40 bool AcceptPendingSyncCheckpoint();
41 uint256 AutoSelectSyncCheckpoint();
42 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
43 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
44 bool ResetSyncCheckpoint();
45 void AskForPendingSyncCheckpoint(CNode* pfrom);
46 bool SetCheckpointPrivKey(std::string strPrivKey);
47 bool SendSyncCheckpoint(uint256 hashCheckpoint);
48 bool IsMatureSyncCheckpoint();
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);