13 pindexPrev, pblock, params,
14 pindexPrev->GetAncestor(params.axionHeight));
33 assert(pindexPrev !=
nullptr);
37 assert(pindexAnchorBlock !=
nullptr);
41 assert(pindexPrev->nHeight >= pindexAnchorBlock->nHeight);
48 if (params.fPowAllowMinDifficultyBlocks &&
49 (pblock->GetBlockTime() >
50 pindexPrev->GetBlockTime() + 2 * params.nPowTargetSpacing)) {
59 assert(pindexPrev->pprev !=
nullptr);
63 const auto anchorTime = pindexAnchorBlock->pprev
64 ? pindexAnchorBlock->pprev->GetBlockTime()
65 : pindexAnchorBlock->GetBlockTime();
66 const int64_t nTimeDiff = pindexPrev->GetBlockTime() - anchorTime;
68 const int64_t nHeightDiff =
69 pindexPrev->nHeight - pindexAnchorBlock->nHeight;
75 CalculateASERT(refBlockTarget, params.nPowTargetSpacing, nTimeDiff,
76 nHeightDiff, powLimit, params.nDAAHalfLife);
85 const int64_t nPowTargetSpacing,
86 const int64_t nTimeDiff,
const int64_t nHeightDiff,
88 const int64_t nHalfLife)
noexcept {
90 assert(refTarget > 0 && refTarget <= powLimit);
94 assert((powLimit >> 224) == 0);
108 assert(llabs(nTimeDiff - nPowTargetSpacing * nHeightDiff) <
110 const int64_t exponent =
111 ((nTimeDiff - nPowTargetSpacing * (nHeightDiff + 1)) * 65536) /
124 static_assert(int64_t(-1) >> 1 == int64_t(-1),
125 "ASERT algorithm needs arithmetic shift support");
130 int64_t shifts = exponent >> 16;
131 const auto frac = uint16_t(exponent);
132 assert(exponent == (shifts * 65536) + frac);
137 const uint32_t factor =
138 65536 + ((+195766423245049ull * frac + 971821376ull * frac * frac +
139 5127ull * frac * frac * frac + (1ull << 47)) >>
147 nextTarget >>= -shifts;
150 const auto nextTargetShifted = nextTarget << shifts;
151 if ((nextTargetShifted >> shifts) != nextTarget) {
154 nextTarget = powLimit;
157 nextTarget = nextTargetShifted;
161 if (nextTarget == 0) {
164 }
else if (nextTarget > powLimit) {
165 nextTarget = powLimit;
arith_uint256 UintToArith256(const uint256 &a)
arith_uint256 CalculateASERT(const arith_uint256 &refTarget, const int64_t nPowTargetSpacing, const int64_t nTimeDiff, const int64_t nHeightDiff, const arith_uint256 &powLimit, const int64_t nHalfLife) noexcept
uint32_t GetNextASERTWorkRequired(const CBlockIndex *pindexPrev, const CBlockHeader *pblock, const Consensus::Params ¶ms) noexcept
The block chain is a tree shaped structure starting with the genesis block at the root,...
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
Parameters that influence chain consensus.