Skip to content

Commit 0100907

Browse files
committed
testnet: Add Testnet4 difficulty adjustment rules fix
1 parent 74a04f9 commit 0100907

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/pow.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,19 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
6161
// Retarget
6262
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
6363
arith_uint256 bnNew;
64-
bnNew.SetCompact(pindexLast->nBits);
64+
65+
// Special difficulty rule for Testnet4
66+
if (params.enforce_BIP94) {
67+
// Here we use the first block of the difficulty period. This way
68+
// the real difficulty is always preserved in the first block as
69+
// it is not allowed to use the min-difficulty exception.
70+
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
71+
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
72+
bnNew.SetCompact(pindexFirst->nBits);
73+
} else {
74+
bnNew.SetCompact(pindexLast->nBits);
75+
}
76+
6577
bnNew *= nActualTimespan;
6678
bnNew /= params.nPowTargetTimespan;
6779

0 commit comments

Comments
 (0)