+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++);
// 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))
+ 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))
+ pair<const uint256, uint64> value(hashBlockFrom, nStakeModifier);
+ it = mapStakeModifier.insert(value).first;
+ nStakeModifier = it->second;
+ mapStakeModifierLastUse[hashBlockFrom] = GetTime();