mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
DGW2
This commit is contained in:
parent
9a10446317
commit
9ea042a12a
87
src/main.cpp
87
src/main.cpp
@ -1488,6 +1488,83 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockH
|
||||
}
|
||||
|
||||
|
||||
unsigned int static DarkGravityWave2(const CBlockIndex* pindexLast, const CBlockHeader *pblock) {
|
||||
/* current difficulty formula, darkcoin - DarkGravity v2, written by Evan Duffield - evan@darkcoin.io */
|
||||
const CBlockIndex *BlockLastSolved = pindexLast;
|
||||
const CBlockIndex *BlockReading = pindexLast;
|
||||
const CBlockHeader *BlockCreating = pblock;
|
||||
BlockCreating = BlockCreating;
|
||||
int64 nBlockTimeAverage = 0;
|
||||
int64 nBlockTimeAveragePrev = 0;
|
||||
int64 nBlockTimeCount = 0;
|
||||
int64 nBlockTimeSum2 = 0;
|
||||
int64 nBlockTimeCount2 = 0;
|
||||
int64 LastBlockTime = 0;
|
||||
int64 PastBlocksMin = 14;
|
||||
int64 PastBlocksMax = 140;
|
||||
int64 CountBlocks = 0;
|
||||
CBigNum PastDifficultyAverage;
|
||||
CBigNum PastDifficultyAveragePrev;
|
||||
|
||||
if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) { return bnProofOfWorkLimit.GetCompact(); }
|
||||
|
||||
for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
|
||||
if (PastBlocksMax > 0 && i > PastBlocksMax) { break; }
|
||||
CountBlocks++;
|
||||
|
||||
if(CountBlocks <= PastBlocksMin) {
|
||||
if (CountBlocks == 1) { PastDifficultyAverage.SetCompact(BlockReading->nBits); }
|
||||
else { PastDifficultyAverage = ((CBigNum().SetCompact(BlockReading->nBits) - PastDifficultyAveragePrev) / CountBlocks) + PastDifficultyAveragePrev; }
|
||||
PastDifficultyAveragePrev = PastDifficultyAverage;
|
||||
}
|
||||
|
||||
if(LastBlockTime > 0){
|
||||
int64 Diff = (LastBlockTime - BlockReading->GetBlockTime());
|
||||
if(nBlockTimeCount <= PastBlocksMin) {
|
||||
nBlockTimeCount++;
|
||||
|
||||
if (nBlockTimeCount == 1) { nBlockTimeAverage = Diff; }
|
||||
else { nBlockTimeAverage = ((Diff - nBlockTimeAveragePrev) / nBlockTimeCount) + nBlockTimeAveragePrev; }
|
||||
nBlockTimeAveragePrev = nBlockTimeAverage;
|
||||
}
|
||||
nBlockTimeCount2++;
|
||||
nBlockTimeSum2 += Diff;
|
||||
}
|
||||
LastBlockTime = BlockReading->GetBlockTime();
|
||||
|
||||
if (BlockReading->pprev == NULL) { assert(BlockReading); break; }
|
||||
BlockReading = BlockReading->pprev;
|
||||
}
|
||||
|
||||
CBigNum bnNew(PastDifficultyAverage);
|
||||
if (nBlockTimeCount != 0 && nBlockTimeCount2 != 0) {
|
||||
double SmartAverage = ((((long double)nBlockTimeAverage)*0.7)+(((long double)nBlockTimeSum2 / (long double)nBlockTimeCount2)*0.3));
|
||||
if(SmartAverage < 1) SmartAverage = 1;
|
||||
double Shift = nTargetSpacing/SmartAverage;
|
||||
|
||||
double fActualTimespan = ((long double)CountBlocks*(double)nTargetSpacing)/Shift;
|
||||
double fTargetTimespan = ((long double)CountBlocks*(double)nTargetSpacing);
|
||||
|
||||
if (fActualTimespan < fTargetTimespan/3)
|
||||
fActualTimespan = fTargetTimespan/3;
|
||||
if (fActualTimespan > fTargetTimespan*3)
|
||||
fActualTimespan = fTargetTimespan*3;
|
||||
|
||||
int64 nActualTimespan = fActualTimespan;
|
||||
int64 nTargetTimespan = fTargetTimespan;
|
||||
|
||||
// Retarget
|
||||
bnNew *= nActualTimespan;
|
||||
bnNew /= nTargetTimespan;
|
||||
}
|
||||
|
||||
if (bnNew > bnProofOfWorkLimit){
|
||||
bnNew = bnProofOfWorkLimit;
|
||||
}
|
||||
|
||||
return bnNew.GetCompact();
|
||||
}
|
||||
|
||||
unsigned int static GetNextWorkRequired_V2(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
|
||||
{
|
||||
static const int64 BlocksTargetSpacing = 2.5 * 60; // 2.5 minutes
|
||||
@ -1504,20 +1581,24 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl
|
||||
{
|
||||
int DiffMode = 1;
|
||||
if (fTestNet) {
|
||||
if (pindexLast->nHeight+1 >= 5) { DiffMode = 3; }
|
||||
if (pindexLast->nHeight+1 >= 15) { DiffMode = 4; }
|
||||
else if (pindexLast->nHeight+1 >= 5) { DiffMode = 3; }
|
||||
}
|
||||
else {
|
||||
if (pindexLast->nHeight+1 >= 34140) { DiffMode = 3; }
|
||||
if (pindexLast->nHeight+1 >= 45000) { DiffMode = 4; }
|
||||
else if (pindexLast->nHeight+1 >= 34140) { DiffMode = 3; }
|
||||
else if (pindexLast->nHeight+1 >= 15200) { DiffMode = 2; }
|
||||
}
|
||||
|
||||
if (DiffMode == 1) { return GetNextWorkRequired_V1(pindexLast, pblock); }
|
||||
else if (DiffMode == 2) { return GetNextWorkRequired_V2(pindexLast, pblock); }
|
||||
else if (DiffMode == 3) { return DarkGravityWave(pindexLast, pblock); }
|
||||
return DarkGravityWave(pindexLast, pblock);
|
||||
else if (DiffMode == 4) { return DarkGravityWave2(pindexLast, pblock); }
|
||||
return DarkGravityWave2(pindexLast, pblock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
|
||||
{
|
||||
CBigNum bnTarget;
|
||||
|
Loading…
Reference in New Issue
Block a user