Skip to content

Commit

Permalink
testnet: Add Testnet4 difficulty adjustment rules fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr committed May 8, 2024
1 parent 37e202a commit e172a96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
// Retarget
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
arith_uint256 bnNew;
bnNew.SetCompact(pindexLast->nBits);

// Special difficulty rule for Testnet4
if (params.fPowAllowMinDifficultyBlocks && params.hashGenesisBlock == uint256S("0x00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043")) {
// Use the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
const unsigned int pow_min{bnPowLimit.GetCompact()};
while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == pow_min)
pindex = pindex->pprev;
bnNew.SetCompact(pindex->nBits);
} else {
bnNew.SetCompact(pindexLast->nBits);
}

bnNew *= nActualTimespan;
bnNew /= params.nPowTargetTimespan;

Expand Down

0 comments on commit e172a96

Please sign in to comment.