Merge pull request #131 from donshin/network-difficulty-comparability

Calculate network difficulty based on legacy powLimit value
This commit is contained in:
Jon Layton 2018-03-05 16:39:23 -06:00 committed by GitHub
commit 1d8429d6db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -41,13 +41,14 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul
bits = blockindex->nBits; bits = blockindex->nBits;
} }
uint32_t powLimit = // instead of using powLimit, network difficulty is calculated using a legacy powLimit value to maintain comparability with the network difficulty of other Equihash-based coins for mining profitability calculations.
UintToArith256(Params().GetConsensus().powLimit).GetCompact(); uint32_t powLimitLegacy =
UintToArith256(uint256S("0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).GetCompact();
int nShift = (bits >> 24) & 0xff; int nShift = (bits >> 24) & 0xff;
int nShiftAmount = (powLimit >> 24) & 0xff; int nShiftAmount = (powLimitLegacy >> 24) & 0xff;
double dDiff = double dDiff =
(double)(powLimit & 0x00ffffff) / (double)(powLimitLegacy & 0x00ffffff) /
(double)(bits & 0x00ffffff); (double)(bits & 0x00ffffff);
while (nShift < nShiftAmount) while (nShift < nShiftAmount)
@ -61,6 +62,9 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul
nShift--; nShift--;
} }
// for compatibility purposes, the floor of 1.0 is maintained.
if (dDiff < 1) dDiff = 1.0;
return dDiff; return dDiff;
} }