X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fcheckpoints.h;h=9d5a16652ee196a64e7b9c891cf9de5b8d562bd8;hb=9795536e660254a25984d0fc81a548eaf0e91c92;hp=033b2286dd55ba50e7ddb1b3e4917ad5570c671d;hpb=5fd6c2c30e1a0dd25e6efe20a55ca1b212e80c98;p=novacoin.git diff --git a/src/checkpoints.h b/src/checkpoints.h index 033b228..9d5a166 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -15,6 +15,7 @@ class uint256; class CBlockIndex; +class CSyncCheckpoint; // // Block-chain checkpoints are compiled-in sanity checks. @@ -31,18 +32,105 @@ namespace Checkpoints // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint CBlockIndex* GetLastCheckpoint(const std::map& mapBlockIndex); - // ppcoin: synchronized checkpoint extern uint256 hashSyncCheckpoint; + extern CSyncCheckpoint checkpointMessage; + extern uint256 hashInvalidCheckpoint; + extern CCriticalSection cs_hashSyncCheckpoint; - // ppcoin: automatic checkpoint - extern int nAutoCheckpoint; - extern int nBranchPoint; - - bool CheckAuto(const CBlockIndex *pindex); - int GetNextChainCheckpoint(const CBlockIndex *pindex); - int GetNextAutoCheckpoint(int nCheckpoint); - void AdvanceAutoCheckpoint(int nCheckpoint); - bool ResetAutoCheckpoint(int nCheckpoint); + CBlockIndex* GetLastSyncCheckpoint(); + bool AcceptPendingSyncCheckpoint(); + uint256 AutoSelectSyncCheckpoint(); + bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev); + bool WantedByPendingSyncCheckpoint(uint256 hashBlock); } +// ppcoin: synchronized checkpoint +class CUnsignedSyncCheckpoint +{ +public: + int nVersion; + uint256 hashCheckpoint; // checkpoint block + + IMPLEMENT_SERIALIZE + ( + READWRITE(this->nVersion); + nVersion = this->nVersion; + READWRITE(hashCheckpoint); + ) + + void SetNull() + { + nVersion = 1; + hashCheckpoint = 0; + } + + std::string ToString() const + { + return strprintf( + "CSyncCheckpoint(\n" + " nVersion = %d\n" + " hashCheckpoint = %s\n" + ")\n", + nVersion, + hashCheckpoint.ToString().c_str()); + } + + void print() const + { + printf("%s", ToString().c_str()); + } +}; + +class CSyncCheckpoint : public CUnsignedSyncCheckpoint +{ +public: + static const std::string strMasterPubKey; + + std::vector vchMsg; + std::vector vchSig; + + CSyncCheckpoint() + { + SetNull(); + } + + IMPLEMENT_SERIALIZE + ( + READWRITE(vchMsg); + READWRITE(vchSig); + ) + + void SetNull() + { + CUnsignedSyncCheckpoint::SetNull(); + vchMsg.clear(); + vchSig.clear(); + } + + bool IsNull() const + { + return (hashCheckpoint == 0); + } + + uint256 GetHash() const + { + return SerializeHash(*this); + } + + bool RelayTo(CNode* pnode) const + { + // returns true if wasn't already sent + if (pnode->hashCheckpointKnown != hashCheckpoint) + { + pnode->hashCheckpointKnown = hashCheckpoint; + pnode->PushMessage("checkpoint", *this); + return true; + } + return false; + } + + bool CheckSignature(); + bool ProcessSyncCheckpoint(CNode* pfrom); +}; + #endif