20 assert(pindexLast !=
nullptr);
24 int64_t nPastBlocks = 180;
27 if (!pindexLast || pindexLast->
nHeight < nPastBlocks) {
36 return nProofOfWorkLimit;
41 pindex->
nBits == nProofOfWorkLimit)
42 pindex = pindex->
pprev;
50 for (
unsigned int nCountBlocks = 1; nCountBlocks <= nPastBlocks; nCountBlocks++) {
52 if (nCountBlocks == 1) {
53 bnPastTargetAvg = bnTarget;
56 bnPastTargetAvg = (bnPastTargetAvg * nCountBlocks + bnTarget) / (nCountBlocks + 1);
59 if(nCountBlocks != nPastBlocks) {
60 assert(pindex->
pprev);
61 pindex = pindex->
pprev;
71 if (nActualTimespan < nTargetTimespan/3)
72 nActualTimespan = nTargetTimespan/3;
73 if (nActualTimespan > nTargetTimespan*3)
74 nActualTimespan = nTargetTimespan*3;
77 bnNew *= nActualTimespan;
78 bnNew /= nTargetTimespan;
80 if (bnNew > bnPowLimit) {
89 assert(pindexLast !=
nullptr);
101 return nProofOfWorkLimit;
107 pindex = pindex->
pprev;
108 return pindex->
nBits;
111 return pindexLast->
nBits;
116 assert(nHeightFirst >= 0);
125 int dgw = DarkGravityWave(pindexLast, pblock, params);
145 return pindexLast->
nBits;
148 int64_t nActualTimespan = pindexLast->
GetBlockTime() - nFirstBlockTime;
158 bnNew *= nActualTimespan;
161 if (bnNew > bnPowLimit)
173 bnTarget.
SetCompact(nBits, &fNegative, &fOverflow);
int64_t GetBlockTime() const
int64_t nPowTargetTimespan
CBlockIndex * pprev
pointer to the index of the predecessor of this block
unsigned int GetNextWorkRequiredBTC(const CBlockIndex *pindexLast, const CBlockHeader *pblock, const Consensus::Params ¶ms)
bool fPowAllowMinDifficultyBlocks
unsigned int CalculateNextWorkRequired(const CBlockIndex *pindexLast, int64_t nFirstBlockTime, const Consensus::Params ¶ms)
uint32_t GetCompact(bool fNegative=false) const
arith_uint256 UintToArith256(const uint256 &a)
uint256 powLimit
Proof of work parameters.
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock, const Consensus::Params ¶ms)
bool IsDGWActive(unsigned int nBlockNumber)
int64_t nPowTargetSpacing
Parameters that influence chain consensus.
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
256-bit unsigned big integer.
int64_t DifficultyAdjustmentInterval() const
The block chain is a tree shaped structure starting with the genesis block at the root...
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.