More difficulty adjustment progress?

This commit is contained in:
Jeremiah Buddenhagen 2017-12-19 15:28:12 -08:00
parent 4af0b18e91
commit f43fe1e283
3 changed files with 14 additions and 7 deletions

View File

@ -110,7 +110,7 @@ public:
consensus.nPowTargetSpacing = 40; // 40s block time
// V1
consensus.nTargetTimespan_Version1 = 60 * 60;
consensus.nInterval_Version1 = 60 * 60 / 40;
consensus.nInterval_Version1 = consensus.nTargetTimespan_Version1 / consensus.nPowTargetSpacing;
consensus.nMaxAdjustUp_Version1 = 75;
consensus.nMaxAdjustDown_Version1 = 300;
consensus.nAveragingInterval_Version1 = consensus.nInterval_Version1;

View File

@ -94,18 +94,19 @@ struct Params {
if (height < nHeight_Difficulty_Version3)
return averagingTargetTimespan * (100 + nMaxAdjustDown_Version2) / 100;
// V3
return TargetTimespan(height) * (100 + nMaxAdjustDown_Version3) / 100;
return averagingTargetTimespan * (100 + nMaxAdjustDown_Version3) / 100;
}
int64_t MinActualTimespan(int height) const {
const int64_t averagingTargetTimespan = AveragingInterval(height) * nPowTargetSpacing;
// V1
if (height < nHeight_Difficulty_Version2)
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version1) / 100;
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version1) / 100;
// V2
if (height < nHeight_Difficulty_Version3)
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version2) / 100;
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version2) / 100;
// V3
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version3) / 100;
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version3) / 100;
}
int64_t AveragingInterval(int height) const {

View File

@ -24,13 +24,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Special difficulty rule for testnet:
// If the new block's timestamp is more than 2* 10 minutes
// then allow mining of a min-difficulty block.
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.TargetTimespan(pindexLast->nHeight+1)*2)
return nProofOfWorkLimit;
else
{
// Return the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval(pindex->nHeight) != 0 && pindex->nBits == nProofOfWorkLimit)
while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval(pindex->nHeight+1) != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;
}
@ -89,6 +89,12 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
if (bnNew > bnPowLimit)
bnNew = bnPowLimit;
/// debug print
LogPrintf("GetNextWorkRequired RETARGET\n");
LogPrintf("Params().TargetTimespan() = %d nActualTimespan = %d\n", params.TargetTimespan(pindexLast->nHeight+1), nActualTimespan);
LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
return bnNew.GetCompact();
}