Update GetDifficulty() to use consensus.powLimit from consensus parameters. Fixes #1032.

This commit is contained in:
aniemerg
2016-06-20 22:21:42 -04:00
parent dd74e9dd32
commit 24809b16b6

View File

@@ -34,16 +34,20 @@ double GetDifficulty(const CBlockIndex* blockindex)
} }
int nShift = (blockindex->nBits >> 24) & 0xff; int nShift = (blockindex->nBits >> 24) & 0xff;
uint32_t powLimit =
UintToArith256(Params().GetConsensus().powLimit).GetCompact();;
int nShiftAmount = (powLimit >> 24) & 0xff;
double dDiff = double dDiff =
(double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff); (double)(powLimit & 0x00ffffff) /
(double)(blockindex->nBits & 0x00ffffff);
while (nShift < 29) while (nShift < nShiftAmount)
{ {
dDiff *= 256.0; dDiff *= 256.0;
nShift++; nShift++;
} }
while (nShift > 29) while (nShift > nShiftAmount)
{ {
dDiff /= 256.0; dDiff /= 256.0;
nShift--; nShift--;