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 6, 2024
1 parent 2dc6410 commit f1ec42f
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("0x000000008d6faa98083fa55742aa82d4ed249bd1bfc3239c706e0a61ef9e3931")) {
// 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 f1ec42f

Please sign in to comment.