Skip to content

Commit

Permalink
Add modifier cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Dec 5, 2018
1 parent 30735a8 commit a8d52e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7326,9 +7326,20 @@ bool CheckStakeKernelHash(unsigned int nBits, CBlock& blockFrom, unsigned int nT
uint64_t nStakeModifier;
int64_t nStakeModifierTime = 0;
int nStakeModifierHeight = 0;
unsigned int nSize = (unsigned int)mapModifiers.size();

if (!GetKernelStakeModifier(hashBlock, nStakeModifier, nStakeModifierTime, nStakeModifierHeight))
return error("%s: Returned false at height %d", __func__, mapBlockIndex[hashBlock]->nHeight);
if (nSize >= MODIFIER_CACHE_LIMIT)
mapModifiers.clear();

/* Stake modifiers for PoS mining are calculated repeatedly
* and can be cached to speed up the whole process */
if (mapModifiers.count(nTimeBlockFrom)) {
nStakeModifier = mapModifiers[nTimeBlockFrom];
} else {
if (!GetKernelStakeModifier(hashBlock, nStakeModifier, nStakeModifierTime, nStakeModifierHeight))
return error("%s: Returned false at height %d", __func__, mapBlockIndex[hashBlock]->nHeight);
mapModifiers.insert(make_pair(nTimeBlockFrom, nStakeModifier));
}

ss << nStakeModifier << nTimeBlockFrom << nTxPrevOffset << txPrev.nTime << prevout.n << nTimeTx;
hashProofOfStake = UintToArith256(Hash(ss.begin(), ss.end()));
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ static const unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60;
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
/** Additional block download timeout per parallel downloading peer (i.e. 5 min) */
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
/** Stake modifier cache size limit */
static const unsigned int MODIFIER_CACHE_LIMIT = 16384;

static const unsigned int DEFAULT_LIMITFREERELAY = 15;
static const bool DEFAULT_RELAYPRIORITY = true;
Expand Down

0 comments on commit a8d52e1

Please sign in to comment.