Trivial optimization: use GetAncestor to compute new target

This commit is contained in:
Pieter Wuille 2015-03-26 11:06:27 -07:00
parent 8e4fd0cc31
commit 1cc0e96e9c

View File

@ -42,9 +42,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
} }
// Go back by what we want to be 14 days worth of blocks // Go back by what we want to be 14 days worth of blocks
const CBlockIndex* pindexFirst = pindexLast; int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
for (int i = 0; pindexFirst && i < params.DifficultyAdjustmentInterval()-1; i++) assert(nHeightFirst >= 0);
pindexFirst = pindexFirst->pprev; const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
assert(pindexFirst); assert(pindexFirst);
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);