Skip to content

Commit 1cc0e96

Browse files
committed
Trivial optimization: use GetAncestor to compute new target
1 parent 8e4fd0c commit 1cc0e96

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)