PPCoin: RPC command 'sendcheckpoint'
[novacoin.git] / src / checkpoints.cpp
index aeb0be7..4afdab9 100644 (file)
@@ -83,31 +83,6 @@ namespace Checkpoints
         return true;
     }
 
-    bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom)
-    {
-        if (!CheckSignature())
-            return false;
-
-        CRITICAL_BLOCK(cs_hashSyncCheckpoint)
-        {
-            if (!mapBlockIndex.count(hashCheckpoint))
-            {
-                // We haven't accepted this block, keep the checkpoint as pending
-                checkpointMessagePending = *this;
-                // Ask this guy to fill in what we're missing
-                if (pfrom)
-                    pfrom->PushGetBlocks(pindexBest, hashCheckpoint);
-                return false;
-            }
-            if (!ValidateSyncCheckpoint(hashCheckpoint))
-                return false;
-            hashSyncCheckpoint = this->hashCheckpoint;
-            checkpointMessage = *this;
-            checkpointMessagePending.SetNull();
-        }
-        return true;
-    }
-
     bool AcceptPendingSyncCheckpoint(uint256 hashAcceptedBlock)
     {
         if (!mapBlockIndex.count(hashAcceptedBlock))
@@ -124,6 +99,10 @@ namespace Checkpoints
                 hashSyncCheckpoint = checkpointMessagePending.hashCheckpoint;
                 checkpointMessage = checkpointMessagePending;
                 checkpointMessagePending.SetNull();
+                printf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString().c_str());
+                // relay the checkpoint
+                BOOST_FOREACH(CNode* pnode, vNodes)
+                    checkpointMessage.RelayTo(pnode);
                 return true;
             }
 
@@ -247,3 +226,31 @@ namespace Checkpoints
         return true;
     }
 }
+
+// ppcoin: process synchronized checkpoint
+bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom)
+{
+    if (!CheckSignature())
+        return false;
+
+    CRITICAL_BLOCK(Checkpoints::cs_hashSyncCheckpoint)
+    {
+        if (!mapBlockIndex.count(hashCheckpoint))
+        {
+            // We haven't accepted this block, keep the checkpoint as pending
+            Checkpoints::checkpointMessagePending = *this;
+            printf("ProcessSyncCheckpoint : pending for sync-checkpoint %s\n", hashCheckpoint.ToString().c_str());
+            // Ask this guy to fill in what we're missing
+            if (pfrom)
+                pfrom->PushGetBlocks(pindexBest, hashCheckpoint);
+            return false;
+        }
+        if (!Checkpoints::ValidateSyncCheckpoint(hashCheckpoint))
+            return false;
+        Checkpoints::hashSyncCheckpoint = this->hashCheckpoint;
+        Checkpoints::checkpointMessage = *this;
+        Checkpoints::checkpointMessagePending.SetNull();
+        printf("ProcessSyncCheckpoint : sync-checkpoint at %s\n", Checkpoints::hashSyncCheckpoint.ToString().c_str());
+    }
+    return true;
+}