Skip to content

Commit b36f1ce

Browse files
committed
Merge pull request #5948
1cc0e96 Trivial optimization: use GetAncestor to compute new target (Pieter Wuille)
2 parents 27e8d22 + 1cc0e96 commit b36f1ce

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/pow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
4242
}
4343

4444
// Go back by what we want to be 14 days worth of blocks
45-
const CBlockIndex* pindexFirst = pindexLast;
46-
for (int i = 0; pindexFirst && i < params.DifficultyAdjustmentInterval()-1; i++)
47-
pindexFirst = pindexFirst->pprev;
45+
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
46+
assert(nHeightFirst >= 0);
47+
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
4848
assert(pindexFirst);
4949

5050
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);

0 commit comments

Comments
 (0)