16 assert(pindexLast !=
nullptr);
28 return nProofOfWorkLimit;
34 pindex = pindex->
pprev;
38 return pindexLast->
nBits;
53 return pindexLast->
nBits;
56 int64_t nActualTimespan = pindexLast->
GetBlockTime() - nFirstBlockTime;
78 bnNew *= nActualTimespan;
81 if (bnNew > bnPowLimit)
103 largest_difficulty_target.
SetCompact(old_nbits);
104 largest_difficulty_target *= largest_timespan;
107 if (largest_difficulty_target > pow_limit) {
108 largest_difficulty_target = pow_limit;
115 if (maximum_new_target < observed_new_target)
return false;
119 smallest_difficulty_target.
SetCompact(old_nbits);
120 smallest_difficulty_target *= smallest_timespan;
123 if (smallest_difficulty_target > pow_limit) {
124 smallest_difficulty_target = pow_limit;
131 if (minimum_new_target > observed_new_target)
return false;
132 }
else if (old_nbits != new_nbits) {
142 if constexpr (
G_FUZZING)
return (hash.
data()[31] & 0x80) == 0;
152 bnTarget.
SetCompact(nBits, &fNegative, &fOverflow);
arith_uint256 UintToArith256(const uint256 &a)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t GetBlockTime() const
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
256-bit unsigned big integer.
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...
uint32_t GetCompact(bool fNegative=false) const
constexpr const unsigned char * data() const
bool PermittedDifficultyTransition(const Consensus::Params ¶ms, int64_t height, uint32_t old_nbits, uint32_t new_nbits)
Return false if the proof-of-work requirement specified by new_nbits at a given height is not possibl...
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock, const Consensus::Params ¶ms)
bool CheckProofOfWorkImpl(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
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.
unsigned int CalculateNextWorkRequired(const CBlockIndex *pindexLast, int64_t nFirstBlockTime, const Consensus::Params ¶ms)
Parameters that influence chain consensus.
bool enforce_BIP94
Enforce BIP94 timewarp attack mitigation.
int64_t DifficultyAdjustmentInterval() const
int64_t nPowTargetTimespan
uint256 powLimit
Proof of work parameters.
int64_t nPowTargetSpacing
bool fPowAllowMinDifficultyBlocks