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.
This commit is contained in:
parent
7b70a67db0
commit
7d18abff71
21
src/main.cpp
21
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 nInterval = nTargetTimespan / nTargetSpacing;
|
||||||
|
|
||||||
static const int64_t nDiffChangeTarget = 145000; // Patch effective @ block 145000
|
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
|
// 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)
|
if (pindexLast == NULL)
|
||||||
return nProofOfWorkLimit;
|
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:
|
// Special difficulty rule for testnet:
|
||||||
// If the new block's timestamp is more than 2* nTargetSpacing minutes
|
// 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())
|
if (TestNet())
|
||||||
{
|
{
|
||||||
// Return the last non-special-min-difficulty-rules-block
|
if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2)
|
||||||
const CBlockIndex* pindex = pindexLast;
|
{
|
||||||
while (pindex->pprev && pindex->nHeight % retargetInterval != 0 && pindex->nBits == nProofOfWorkLimit)
|
// Special difficulty rule for testnet:
|
||||||
pindex = pindex->pprev;
|
// If the new block's timestamp is more than 2* nTargetSpacing minutes
|
||||||
return pindex->nBits;
|
// 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;
|
return pindexLast->nBits;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue