aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPatrick Lodder <[email protected]>2014-08-05 00:18:52 +0200
committerPatrick Lodder <[email protected]>2014-08-05 02:27:28 +0200
commit7d18abff714c1b5e051506fad244d3561b8ffb62 (patch)
treebaafed0d80742a4b11e7201bb29edcb3d55ceaf4 /src/main.cpp
parentMerge pull request #591 from patricklodder/1.8-version-check-fix (diff)
downloaddiscoin-7d18abff714c1b5e051506fad244d3561b8ffb62.tar.xz
discoin-7d18abff714c1b5e051506fad244d3561b8ffb62.zip
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.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp21
1 files 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;
}