1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Copyright (c) 2011-2012 The PPCoin developers
3 // Copyright (c) 2012-2013 The NovaCoin developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_CHECKPOINT_H
7 #define BITCOIN_CHECKPOINT_H
13 #define STAKE_MIN_AGE (60 * 60 * 24 * 30) // minimum age 30 days for coin age
14 #define STAKE_MAX_AGE (60 * 60 * 24 * 90) // stake age for full weight
15 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
19 class CSyncCheckpoint;
21 /** Block-chain checkpoints are compiled-in sanity checks.
22 * They are updated every release or three.
26 // Returns true if block passes checkpoint checks
27 bool CheckHardened(int nHeight, const uint256& hash);
29 // Return conservative estimate of total number of blocks, 0 if unknown
30 int GetTotalBlocksEstimate();
32 // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
33 CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
35 extern uint256 hashSyncCheckpoint;
36 extern CSyncCheckpoint checkpointMessage;
37 extern uint256 hashInvalidCheckpoint;
38 extern CCriticalSection cs_hashSyncCheckpoint;
40 CBlockIndex* GetLastSyncCheckpoint();
41 bool WriteSyncCheckpoint(const uint256& hashCheckpoint);
42 bool AcceptPendingSyncCheckpoint();
43 uint256 AutoSelectSyncCheckpoint();
44 bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev);
45 bool WantedByPendingSyncCheckpoint(uint256 hashBlock);
46 bool ResetSyncCheckpoint();
47 void AskForPendingSyncCheckpoint(CNode* pfrom);
48 bool SetCheckpointPrivKey(std::string strPrivKey);
49 bool SendSyncCheckpoint(uint256 hashCheckpoint);
50 bool IsMatureSyncCheckpoint();
53 // ppcoin: synchronized checkpoint
54 class CUnsignedSyncCheckpoint
58 uint256 hashCheckpoint; // checkpoint block
62 READWRITE(this->nVersion);
63 nVersion = this->nVersion;
64 READWRITE(hashCheckpoint);
73 std::string ToString() const
78 " hashCheckpoint = %s\n"
81 hashCheckpoint.ToString().c_str());
86 printf("%s", ToString().c_str());
90 class CSyncCheckpoint : public CUnsignedSyncCheckpoint
93 static const std::string strMasterPubKey;
94 static std::string strMasterPrivKey;
96 std::vector<unsigned char> vchMsg;
97 std::vector<unsigned char> vchSig;
112 CUnsignedSyncCheckpoint::SetNull();
119 return (hashCheckpoint == 0);
122 uint256 GetHash() const
124 return SerializeHash(*this);
127 bool RelayTo(CNode* pnode) const
129 // returns true if wasn't already sent
130 if (pnode->hashCheckpointKnown != hashCheckpoint)
132 pnode->hashCheckpointKnown = hashCheckpoint;
133 pnode->PushMessage("checkpoint", *this);
139 bool CheckSignature();
140 bool ProcessSyncCheckpoint(CNode* pfrom);