Comments (0)

Files changed (3)

File src/kernel.cpp Modified

View file
  • Ignore whitespace
  • Hide word diff
     return true;
 }
 
+// Stake modifier cache
+static map<const uint256, uint64> mapStakeModifier;
+static map<const uint256, uint64> mapStakeModifierLastUse;
+
+void CleanStakeModifierCache()
+{
+    uint64 nNow = GetTime();
+    map<const uint256, uint64>::iterator it = mapStakeModifierLastUse.begin();
+    while (it != mapStakeModifierLastUse.end())
+    {
+        const uint256& hash = it->first;
+        uint64& nLastUse = it->second;
+
+        if (nNow > nLastUse + 24 * 60 * 60)
+        {
+            mapStakeModifier.erase(hash);
+            mapStakeModifierLastUse.erase(it++);
+        }
+        else
+            it++;
+    }
+}
+
 // ppcoin kernel protocol
 // coinstake must meet hash target according to the protocol:
 // kernel (input 0) must meet the formula
     int64 nStakeModifierTime = 0;
     if (IsProtocolV03(nTimeTx))  // v0.3 protocol
     {
-        if (!GetKernelStakeModifier(blockFrom.GetHash(), nStakeModifier, nStakeModifierHeight, nStakeModifierTime, fPrintProofOfStake))
-            return false;
+        const uint256 hashBlockFrom = blockFrom.GetHash();
+        map<const uint256, uint64>::const_iterator it = mapStakeModifier.find(hashBlockFrom);
+        if (it == mapStakeModifier.end())
+        {
+            if (!GetKernelStakeModifier(blockFrom.GetHash(), nStakeModifier, nStakeModifierHeight, nStakeModifierTime, fPrintProofOfStake))
+                return false;
+            pair<const uint256, uint64> value(hashBlockFrom, nStakeModifier);
+            it = mapStakeModifier.insert(value).first;
+        }
+        nStakeModifier = it->second;
         ss << nStakeModifier;
+
+        mapStakeModifierLastUse[hashBlockFrom] = GetTime();
     }
     else // v0.2 protocol
     {

File src/kernel.h Modified

View file
  • Ignore whitespace
  • Hide word diff
 // Check stake modifier hard checkpoints
 bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);
 
+// Expire old stake modifier cache
+void CleanStakeModifierCache();
+
 #endif // PPCOIN_KERNEL_H

File src/wallet.cpp Modified

View file
  • Ignore whitespace
  • Hide word diff
         else
             it++;
     }
+    CleanStakeModifierCache();
 
     txNew.vin.clear();
     txNew.vout.clear();