|
|
@ -9,7 +9,6 @@
|
|
|
|
#include "chain.h"
|
|
|
|
#include "chain.h"
|
|
|
|
#include "primitives/block.h"
|
|
|
|
#include "primitives/block.h"
|
|
|
|
#include "uint256.h"
|
|
|
|
#include "uint256.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -57,7 +56,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
|
|
|
|
|
|
|
|
|
|
|
|
// Limit adjustment step
|
|
|
|
// Limit adjustment step
|
|
|
|
int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
|
|
|
|
int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
|
|
|
|
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
|
|
|
|
|
|
|
|
if (nActualTimespan < params.nPowTargetTimespan/4)
|
|
|
|
if (nActualTimespan < params.nPowTargetTimespan/4)
|
|
|
|
nActualTimespan = params.nPowTargetTimespan/4;
|
|
|
|
nActualTimespan = params.nPowTargetTimespan/4;
|
|
|
|
if (nActualTimespan > params.nPowTargetTimespan*4)
|
|
|
|
if (nActualTimespan > params.nPowTargetTimespan*4)
|
|
|
@ -75,12 +73,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
|
|
|
|
if (bnNew > bnPowLimit)
|
|
|
|
if (bnNew > bnPowLimit)
|
|
|
|
bnNew = bnPowLimit;
|
|
|
|
bnNew = bnPowLimit;
|
|
|
|
|
|
|
|
|
|
|
|
/// debug print
|
|
|
|
|
|
|
|
LogPrintf("GetNextWorkRequired RETARGET\n");
|
|
|
|
|
|
|
|
LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan);
|
|
|
|
|
|
|
|
LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
|
|
|
|
|
|
|
|
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bnNew.GetCompact();
|
|
|
|
return bnNew.GetCompact();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -94,11 +86,11 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&
|
|
|
|
|
|
|
|
|
|
|
|
// Check range
|
|
|
|
// Check range
|
|
|
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
|
|
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
|
|
|
return error("CheckProofOfWork(): nBits below minimum work");
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Check proof of work matches claimed amount
|
|
|
|
// Check proof of work matches claimed amount
|
|
|
|
if (UintToArith256(hash) > bnTarget)
|
|
|
|
if (UintToArith256(hash) > bnTarget)
|
|
|
|
return error("CheckProofOfWork(): hash doesn't match nBits");
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|