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 STAKE_MAX_AGE (60 * 60 * 24 * 90) // stake age for full weight
14 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
18 class CSyncCheckpoint;
20 /** Block-chain checkpoints are compiled-in sanity checks.
21 * They are updated every release or three.
25 // Returns true if block passes checkpoint checks
26 bool CheckHardened(int nHeight, const uint256& hash);
28 // Return conservative estimate of total number of blocks, 0 if unknown
29 int GetTotalBlocksEstimate();
31 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
32 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
34 extern uint256 hashSyncCheckpoint;
35 extern CSyncCheckpoint checkpointMessage;
36 extern uint256 hashInvalidCheckpoint;
37 extern CCriticalSection cs_hashSyncCheckpoint;
39 CBlockIndex* GetLastSyncCheckpoint();
40 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
41 bool AcceptPendingSyncCheckpoint();
42 uint256 AutoSelectSyncCheckpoint();
43 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
44 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
45 bool ResetSyncCheckpoint();
46 void AskForPendingSyncCheckpoint(CNode* pfrom);
47 bool SetCheckpointPrivKey(std::string strPrivKey);
48 bool SendSyncCheckpoint(uint256 hashCheckpoint);
49 bool IsMatureSyncCheckpoint();
52 // ppcoin: synchronized checkpoint
53 class CUnsignedSyncCheckpoint
57 uint256 hashCheckpoint; // checkpoint block
61 READWRITE(this->nVersion);
62 nVersion = this->nVersion;
63 READWRITE(hashCheckpoint);
72 std::string ToString() const
77 " hashCheckpoint = %s\n"
80 hashCheckpoint.ToString().c_str());
85 printf("%s", ToString().c_str());
89 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
92 static const std::string strMasterPubKey;
93 static std::string strMasterPrivKey;
95 std::vector<unsigned char> vchMsg;
96 std::vector<unsigned char> vchSig;
111 CUnsignedSyncCheckpoint::SetNull();
118 return (hashCheckpoint == 0);
121 uint256 GetHash() const
123 return SerializeHash(*this);
126 bool RelayTo(CNode* pnode) const
128 // returns true if wasn't already sent
129 if (pnode->hashCheckpointKnown != hashCheckpoint)
131 pnode->hashCheckpointKnown = hashCheckpoint;
132 pnode->PushMessage("checkpoint", *this);
138 bool CheckSignature();
139 bool ProcessSyncCheckpoint(CNode* pfrom);