Simplify difficulty averaging code
This commit is contained in:
parent
5fbb839f53
commit
7b173bd80f
12
src/pow.cpp
12
src/pow.cpp
|
@ -26,15 +26,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||||
|
|
||||||
// Find the first block in the averaging interval
|
// Find the first block in the averaging interval
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
const CBlockIndex* pindexFirst = pindexLast;
|
||||||
arith_uint256 bnAvg;
|
arith_uint256 bnTot {0};
|
||||||
arith_uint256 bnTmp;
|
|
||||||
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
|
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
|
||||||
if (i == 0) {
|
arith_uint256 bnTmp;
|
||||||
bnAvg.SetCompact(pindexFirst->nBits);
|
|
||||||
} else {
|
|
||||||
bnTmp.SetCompact(pindexFirst->nBits);
|
bnTmp.SetCompact(pindexFirst->nBits);
|
||||||
bnAvg = ((bnAvg * i) + bnTmp) / (i + 1);
|
bnTot += bnTmp;
|
||||||
}
|
|
||||||
pindexFirst = pindexFirst->pprev;
|
pindexFirst = pindexFirst->pprev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +38,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||||
if (pindexFirst == NULL)
|
if (pindexFirst == NULL)
|
||||||
return nProofOfWorkLimit;
|
return nProofOfWorkLimit;
|
||||||
|
|
||||||
|
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
|
||||||
|
|
||||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue