More difficulty adjustment progress?
This commit is contained in:
parent
4af0b18e91
commit
f43fe1e283
@ -110,7 +110,7 @@ public:
|
|||||||
consensus.nPowTargetSpacing = 40; // 40s block time
|
consensus.nPowTargetSpacing = 40; // 40s block time
|
||||||
// V1
|
// V1
|
||||||
consensus.nTargetTimespan_Version1 = 60 * 60;
|
consensus.nTargetTimespan_Version1 = 60 * 60;
|
||||||
consensus.nInterval_Version1 = 60 * 60 / 40;
|
consensus.nInterval_Version1 = consensus.nTargetTimespan_Version1 / consensus.nPowTargetSpacing;
|
||||||
consensus.nMaxAdjustUp_Version1 = 75;
|
consensus.nMaxAdjustUp_Version1 = 75;
|
||||||
consensus.nMaxAdjustDown_Version1 = 300;
|
consensus.nMaxAdjustDown_Version1 = 300;
|
||||||
consensus.nAveragingInterval_Version1 = consensus.nInterval_Version1;
|
consensus.nAveragingInterval_Version1 = consensus.nInterval_Version1;
|
||||||
|
|||||||
@ -94,18 +94,19 @@ struct Params {
|
|||||||
if (height < nHeight_Difficulty_Version3)
|
if (height < nHeight_Difficulty_Version3)
|
||||||
return averagingTargetTimespan * (100 + nMaxAdjustDown_Version2) / 100;
|
return averagingTargetTimespan * (100 + nMaxAdjustDown_Version2) / 100;
|
||||||
// V3
|
// V3
|
||||||
return TargetTimespan(height) * (100 + nMaxAdjustDown_Version3) / 100;
|
return averagingTargetTimespan * (100 + nMaxAdjustDown_Version3) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t MinActualTimespan(int height) const {
|
int64_t MinActualTimespan(int height) const {
|
||||||
|
const int64_t averagingTargetTimespan = AveragingInterval(height) * nPowTargetSpacing;
|
||||||
// V1
|
// V1
|
||||||
if (height < nHeight_Difficulty_Version2)
|
if (height < nHeight_Difficulty_Version2)
|
||||||
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version1) / 100;
|
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version1) / 100;
|
||||||
// V2
|
// V2
|
||||||
if (height < nHeight_Difficulty_Version3)
|
if (height < nHeight_Difficulty_Version3)
|
||||||
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version2) / 100;
|
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version2) / 100;
|
||||||
// V3
|
// V3
|
||||||
return TargetTimespan(height) * (100 - nMaxAdjustUp_Version3) / 100;
|
return averagingTargetTimespan * (100 - nMaxAdjustUp_Version3) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t AveragingInterval(int height) const {
|
int64_t AveragingInterval(int height) const {
|
||||||
|
|||||||
10
src/pow.cpp
10
src/pow.cpp
@ -24,13 +24,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
// Special difficulty rule for testnet:
|
// Special difficulty rule for testnet:
|
||||||
// If the new block's timestamp is more than 2* 10 minutes
|
// If the new block's timestamp is more than 2* 10 minutes
|
||||||
// then allow mining of a min-difficulty block.
|
// 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;
|
return nProofOfWorkLimit;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Return the last non-special-min-difficulty-rules-block
|
// Return the last non-special-min-difficulty-rules-block
|
||||||
const CBlockIndex* pindex = pindexLast;
|
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;
|
pindex = pindex->pprev;
|
||||||
return pindex->nBits;
|
return pindex->nBits;
|
||||||
}
|
}
|
||||||
@ -89,6 +89,12 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
|
|||||||
if (bnNew > bnPowLimit)
|
if (bnNew > bnPowLimit)
|
||||||
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();
|
return bnNew.GetCompact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user