PPCoin: Include coinstake timestamp in duplicate-stake check
[novacoin.git] / src / db.cpp
index 6eece05..89f8b16 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)
@@ -540,6 +550,9 @@ bool CTxDB::LoadBlockIndex()
             pindexNew->nBlockPos      = diskindex.nBlockPos;
             pindexNew->nChainTrust    = diskindex.nChainTrust;
             pindexNew->nHeight        = diskindex.nHeight;
+            pindexNew->nCheckpoint    = diskindex.nCheckpoint;
+            pindexNew->fProofOfStake  = diskindex.fProofOfStake;
+            pindexNew->prevoutStake   = diskindex.prevoutStake;
             pindexNew->nVersion       = diskindex.nVersion;
             pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
             pindexNew->nTime          = diskindex.nTime;
@@ -552,6 +565,10 @@ bool CTxDB::LoadBlockIndex()
 
             if (!pindexNew->CheckIndex())
                 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
+
+            // ppcoin: build setStakeSeen
+            if (pindexNew->fProofOfStake)
+                setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));
         }
         else
         {
@@ -574,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);