X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fcheckpoints.cpp;h=d986b07ae10322d4b92415b67f892870044096b7;hb=dffda08fddf00889dd710ab704e9e99929be325a;hp=097dd87c97ec74f0015f240a0469012150d568d0;hpb=f3a172bdf16a3a316e34ad6335514f95b0ebf1e4;p=novacoin.git diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 097dd87..d986b07 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -83,19 +83,22 @@ namespace Checkpoints return true; } - bool AcceptPendingSyncCheckpoint(uint256 hashAcceptedBlock) + bool AcceptPendingSyncCheckpoint() { - if (!mapBlockIndex.count(hashAcceptedBlock)) - return false; - CRITICAL_BLOCK(cs_hashSyncCheckpoint) - if ((!checkpointMessagePending.IsNull()) && checkpointMessagePending.hashCheckpoint == hashAcceptedBlock) + if ((!checkpointMessagePending.IsNull()) && mapBlockIndex.count(checkpointMessagePending.hashCheckpoint)) { if (!ValidateSyncCheckpoint(checkpointMessagePending.hashCheckpoint)) { checkpointMessagePending.SetNull(); return false; } + + CTxDB txdb; + if (!txdb.WriteSyncCheckpoint(checkpointMessagePending.hashCheckpoint)) + return error("AcceptPendingSyncCheckpoint() : failed to write to db sync checkpoint %s\n", checkpointMessagePending.hashCheckpoint.ToString().c_str()); + txdb.Close(); + hashSyncCheckpoint = checkpointMessagePending.hashCheckpoint; checkpointMessage = checkpointMessagePending; checkpointMessagePending.SetNull(); @@ -118,6 +121,22 @@ namespace Checkpoints return pindex->GetBlockHash(); } + // Check against synchronized checkpoint + bool CheckSync(int nHeight, const uint256& hashBlock) + { + if (fTestNet) return true; // Testnet has no checkpoints + + CRITICAL_BLOCK(cs_hashSyncCheckpoint) + { + CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint]; + if (nHeight == pindexSync->nHeight && hashBlock != hashSyncCheckpoint) + return false; // same height with sync-checkpoint + if (nHeight < pindexSync->nHeight && !mapBlockIndex.count(hashBlock)) + return false; // lower height than sync-checkpoint + } + return true; + } + // ppcoin: automatic checkpoint (represented by height of checkpoint) int nAutoCheckpoint = 0; int nBranchPoint = 0; // branch point to alternative branch @@ -256,6 +275,12 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) } if (!Checkpoints::ValidateSyncCheckpoint(hashCheckpoint)) return false; + + CTxDB txdb; + if (!txdb.WriteSyncCheckpoint(this->hashCheckpoint)) + return error("ProcessSyncCheckpoint() : failed to write to db sync checkpoint %s\n", this->hashCheckpoint.ToString().c_str()); + txdb.Close(); + Checkpoints::hashSyncCheckpoint = this->hashCheckpoint; Checkpoints::checkpointMessage = *this; Checkpoints::checkpointMessagePending.SetNull();