From 7d18abff714c1b5e051506fad244d3561b8ffb62 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Tue, 5 Aug 2014 00:18:52 +0200 Subject: [PATCH] Apply predetermined block for testnet fork PR #589 caused a condition for testnet difficulty to not match at a couple of cases pre block 145k leading to issues with -reindex. This makes the testnet fork hard at block 157500, while retaining every case before that block. --- src/main.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b686545bf..da1f12cdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1246,6 +1246,7 @@ static const int64_t nTargetSpacing = 60; // Dogecoin: 1 minute static const int64_t nInterval = nTargetTimespan / nTargetSpacing; static const int64_t nDiffChangeTarget = 145000; // Patch effective @ block 145000 +static const int64_t nTestnetResetTargetFix = 157500; // Testnet enables target reset at block 157500 // // minimum amount of work that could possibly be required nTime after @@ -1299,7 +1300,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast == NULL) return nProofOfWorkLimit; - if (TestNet() && pblock->nTime > pindexLast->nTime + nTargetSpacing*2) + if (TestNet() && pindexLast->nHeight >= nTestnetResetTargetFix && pblock->nTime > pindexLast->nTime + nTargetSpacing*2) { // Special difficulty rule for testnet: // If the new block's timestamp is more than 2* nTargetSpacing minutes @@ -1312,11 +1313,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { if (TestNet()) { - // Return the last non-special-min-difficulty-rules-block - const CBlockIndex* pindex = pindexLast; - while (pindex->pprev && pindex->nHeight % retargetInterval != 0 && pindex->nBits == nProofOfWorkLimit) - pindex = pindex->pprev; - return pindex->nBits; + if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2) + { + // Special difficulty rule for testnet: + // If the new block's timestamp is more than 2* nTargetSpacing minutes + // then allow mining of a min-difficulty block. + return nProofOfWorkLimit; + } else { + // Return the last non-special-min-difficulty-rules-block + const CBlockIndex* pindex = pindexLast; + while (pindex->pprev && pindex->nHeight % retargetInterval != 0 && pindex->nBits == nProofOfWorkLimit) + pindex = pindex->pprev; + return pindex->nBits; + } } return pindexLast->nBits; }