|
|
@ -13,7 +13,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) |
|
|
|
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int nProofOfWorkLimit = params.powLimit.GetCompact(); |
|
|
|
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); |
|
|
|
|
|
|
|
|
|
|
|
// Genesis block
|
|
|
|
// Genesis block
|
|
|
|
if (pindexLast == NULL) |
|
|
|
if (pindexLast == NULL) |
|
|
@ -61,6 +61,7 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF |
|
|
|
nActualTimespan = params.nPowTargetTimespan*4; |
|
|
|
nActualTimespan = params.nPowTargetTimespan*4; |
|
|
|
|
|
|
|
|
|
|
|
// Retarget
|
|
|
|
// Retarget
|
|
|
|
|
|
|
|
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); |
|
|
|
arith_uint256 bnNew; |
|
|
|
arith_uint256 bnNew; |
|
|
|
arith_uint256 bnOld; |
|
|
|
arith_uint256 bnOld; |
|
|
|
bnNew.SetCompact(pindexLast->nBits); |
|
|
|
bnNew.SetCompact(pindexLast->nBits); |
|
|
@ -68,8 +69,8 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF |
|
|
|
bnNew *= nActualTimespan; |
|
|
|
bnNew *= nActualTimespan; |
|
|
|
bnNew /= params.nPowTargetTimespan; |
|
|
|
bnNew /= params.nPowTargetTimespan; |
|
|
|
|
|
|
|
|
|
|
|
if (bnNew > params.powLimit) |
|
|
|
if (bnNew > bnPowLimit) |
|
|
|
bnNew = params.powLimit; |
|
|
|
bnNew = bnPowLimit; |
|
|
|
|
|
|
|
|
|
|
|
/// debug print
|
|
|
|
/// debug print
|
|
|
|
LogPrintf("GetNextWorkRequired RETARGET\n"); |
|
|
|
LogPrintf("GetNextWorkRequired RETARGET\n"); |
|
|
@ -89,7 +90,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& |
|
|
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow); |
|
|
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow); |
|
|
|
|
|
|
|
|
|
|
|
// Check range
|
|
|
|
// Check range
|
|
|
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > params.powLimit) |
|
|
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) |
|
|
|
return error("CheckProofOfWork(): nBits below minimum work"); |
|
|
|
return error("CheckProofOfWork(): nBits below minimum work"); |
|
|
|
|
|
|
|
|
|
|
|
// Check proof of work matches claimed amount
|
|
|
|
// Check proof of work matches claimed amount
|
|
|
|