PPCoin: Define synchronized checkpoint
authorSunny King <sunnyking9999@gmail.com>
Wed, 30 May 2012 20:36:36 +0000 (21:36 +0100)
committerSunny King <sunnyking9999@gmail.com>
Wed, 30 May 2012 20:36:36 +0000 (21:36 +0100)
src/checkpoints.cpp
src/checkpoints.h
src/db.cpp
src/db.h

index f3bfe5d..89e53ca 100644 (file)
@@ -25,10 +25,6 @@ namespace Checkpoints
         ( 0, hashGenesisBlock )
         ; // ppcoin: no checkpoint yet; to be created in future releases
 
-    // ppcoin: automatic checkpoint (represented by height of checkpoint)
-    int nAutoCheckpoint = 0;
-    int nBranchPoint = 0;    // branch point to alternative branch
-
     bool CheckHardened(int nHeight, const uint256& hash)
     {
         if (fTestNet) return true; // Testnet has no checkpoints
@@ -38,6 +34,39 @@ namespace Checkpoints
         return hash == i->second;
     }
 
+    int GetTotalBlocksEstimate()
+    {
+        if (fTestNet) return 0;
+
+        return mapCheckpoints.rbegin()->first;
+    }
+
+    CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
+    {
+        if (fTestNet) return NULL;
+
+        int64 nResult;
+        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
+        {
+            const uint256& hash = i.second;
+            std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
+            if (t != mapBlockIndex.end())
+                return t->second;
+        }
+        return NULL;
+    }
+
+    // ppcoin: synchronized checkpoint (centrally broadcasted)
+    uint256 hashSyncCheckpoint;
+
+    bool AcceptNewSyncCheckpoint(uint256 hashCheckpoint)
+    {
+    }
+
+    // ppcoin: automatic checkpoint (represented by height of checkpoint)
+    int nAutoCheckpoint = 0;
+    int nBranchPoint = 0;    // branch point to alternative branch
+
     // ppcoin: check automatic checkpoint
     // To pass the check:
     //   - All ancestors (including the block itself) have block index already
@@ -125,13 +154,6 @@ namespace Checkpoints
         printf("Checkpoints: auto checkpoint now at height=%d\n", nAutoCheckpoint);
     }
 
-    int GetTotalBlocksEstimate()
-    {
-        if (fTestNet) return 0;
-
-        return mapCheckpoints.rbegin()->first;
-    }
-
     // ppcoin: reset auto checkpoint
     bool ResetAutoCheckpoint(int nCheckpoint)
     {
@@ -157,19 +179,4 @@ namespace Checkpoints
 
         return true;
     }
-
-    CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex)
-    {
-        if (fTestNet) return NULL;
-
-        int64 nResult;
-        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
-        {
-            const uint256& hash = i.second;
-            std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash);
-            if (t != mapBlockIndex.end())
-                return t->second;
-        }
-        return NULL;
-    }
 }
index c984798..033b228 100644 (file)
@@ -22,23 +22,27 @@ class CBlockIndex;
 //
 namespace Checkpoints
 {
-    extern int nAutoCheckpoint;
-    extern int nBranchPoint;
-
     // Returns true if block passes checkpoint checks
     bool CheckHardened(int nHeight, const uint256& hash);
-    bool CheckAuto(const CBlockIndex *pindex);
-
-    int  GetNextChainCheckpoint(const CBlockIndex *pindex);
-    int  GetNextAutoCheckpoint(int nCheckpoint);
-    void AdvanceAutoCheckpoint(int nCheckpoint);
-    bool ResetAutoCheckpoint(int nCheckpoint);
 
     // Return conservative estimate of total number of blocks, 0 if unknown
     int GetTotalBlocksEstimate();
 
     // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
     CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
+
+    // ppcoin: synchronized checkpoint
+    extern uint256 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);
 }
 
 #endif
index d85e4a9..a51c217 100644 (file)
@@ -481,6 +481,16 @@ bool CTxDB::WriteAutoCheckpoint(int nCheckpoint, bool fReset)
     return Write(string("nAutoCheckpoint"), nCheckpoint);
 }
 
+bool CTxDB::ReadSyncCheckpoint(uint256& hashCheckpoint)
+{
+    return Read(string("hashSyncCheckpoint"), hashCheckpoint);
+}
+
+bool CTxDB::WriteSyncCheckpoint(uint256 hashCheckpoint)
+{
+    return Write(string("hashSyncCheckpoint"), hashCheckpoint);
+}
+
 CBlockIndex static * InsertBlockIndex(uint256 hash)
 {
     if (hash == 0)
@@ -581,11 +591,16 @@ bool CTxDB::LoadBlockIndex()
     nBestChainTrust = pindexBest->nChainTrust;
     printf("LoadBlockIndex(): hashBestChain=%s  height=%d  trust=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, nBestChainTrust);
 
-    // Load nAutoCheckpoint
+    // ppcoin: load nAutoCheckpoint
     if (!ReadAutoCheckpoint(Checkpoints::nAutoCheckpoint))
         return error("CTxDB::LoadBlockIndex() : nAutoCheckpoint not loaded");
     printf("LoadBlockIndex(): automatic checkpoint at height=%d\n", Checkpoints::nAutoCheckpoint);
 
+    // ppcoin: load hashSyncCheckpoint
+    if (!ReadSyncCheckpoint(Checkpoints::hashSyncCheckpoint))
+        return error("CTxDB::LoadBlockIndex() : hashSyncCheckpoint not loaded");
+    printf("LoadBlockIndex(): synchronized checkpoint %s\n", Checkpoints::hashSyncCheckpoint.ToString().c_str());
+
     // Load nBestInvalidTrust, OK if it doesn't exist
     ReadBestInvalidTrust(nBestInvalidTrust);
 
index b11ccac..f3b7cac 100644 (file)
--- a/src/db.h
+++ b/src/db.h
@@ -293,6 +293,8 @@ public:
     bool WriteBestInvalidTrust(uint64 nBestInvalidTrust);
     bool ReadAutoCheckpoint(int& nAutoCheckpoint);
     bool WriteAutoCheckpoint(int nCheckpoint, bool fReset=false);
+    bool ReadSyncCheckpoint(uint256& hashCheckpoint);
+    bool WriteSyncCheckpoint(uint256 hashCheckpoint);
     bool LoadBlockIndex();
 };