Skip to content

Commit 880cbf4

Browse files
authored
Backport fPowAllowMinDifficultyBlocks rule to DarkGravityWave (#2027)
1 parent 8b4c419 commit 880cbf4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/pow.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const Conse
7979
return bnNew.GetCompact();
8080
}
8181

82-
unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const Consensus::Params& params) {
82+
unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) {
8383
/* current difficulty formula, dash - DarkGravity v3, written by Evan Duffield - evan@dash.org */
8484
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
8585
int64_t nPastBlocks = 24;
@@ -89,6 +89,19 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const Consens
8989
return bnPowLimit.GetCompact();
9090
}
9191

92+
if (params.fPowAllowMinDifficultyBlocks && (
93+
// testnet ...
94+
(params.hashDevnetGenesisBlock.IsNull() && pindexLast->nChainWork >= UintToArith256(uint256S("0x000000000000000000000000000000000000000000000000003e9ccfe0e03e01"))) ||
95+
// or devnet
96+
!params.hashDevnetGenesisBlock.IsNull())) {
97+
// Special difficulty rule for testnet/devnet:
98+
// If the new block's timestamp is more than 2* 2.5 minutes
99+
// then allow mining of a min-difficulty block.
100+
// TODO: "testnet OR devenet" part on next testnet hard-fork
101+
if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
102+
return bnPowLimit.GetCompact();
103+
}
104+
92105
const CBlockIndex *pindex = pindexLast;
93106
arith_uint256 bnPastTargetAvg;
94107

@@ -172,7 +185,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
172185
{
173186
// Most recent algo first
174187
if (pindexLast->nHeight + 1 >= params.nPowDGWHeight) {
175-
return DarkGravityWave(pindexLast, params);
188+
return DarkGravityWave(pindexLast, pblock, params);
176189
}
177190
else if (pindexLast->nHeight + 1 >= params.nPowKGWHeight) {
178191
return KimotoGravityWell(pindexLast, params);

0 commit comments

Comments
 (0)