diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2024-05-03 10:05:22 +0900 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2024-08-06 01:38:12 +0200 |
commit | 0100907ca168c53e8fe044bdda396f308825162c (patch) | |
tree | 92be4706795f1d2c581621388f3e6ee24ee263bd | |
parent | 74a04f9e7ad6a16988149cc3438b9ce13c91cdb9 (diff) |
testnet: Add Testnet4 difficulty adjustment rules fix
-rw-r--r-- | src/pow.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/pow.cpp b/src/pow.cpp index 1e8d53de8b..50de8946be 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -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.enforce_BIP94) { + // Here we use the first block of the difficulty period. This way + // the real difficulty is always preserved in the first block as + // it is not allowed to use the min-difficulty exception. + int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); + const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); + bnNew.SetCompact(pindexFirst->nBits); + } else { + bnNew.SetCompact(pindexLast->nBits); + } + bnNew *= nActualTimespan; bnNew /= params.nPowTargetTimespan; |