Fix pow_tests to work with Equihash
Changing the order of difficulty calculation operations to divide first doesn't affect the result significantly, but ensures we never overflow the arith_uint256 during multiplication and get an artificial jump in difficulty.
This commit is contained in:
@@ -71,8 +71,8 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
|
|||||||
arith_uint256 bnOld;
|
arith_uint256 bnOld;
|
||||||
bnNew.SetCompact(pindexLast->nBits);
|
bnNew.SetCompact(pindexLast->nBits);
|
||||||
bnOld = bnNew;
|
bnOld = bnNew;
|
||||||
bnNew *= nActualTimespan;
|
|
||||||
bnNew /= params.nPowTargetTimespan;
|
bnNew /= params.nPowTargetTimespan;
|
||||||
|
bnNew *= nActualTimespan;
|
||||||
|
|
||||||
if (bnNew > bnPowLimit)
|
if (bnNew > bnPowLimit)
|
||||||
bnNew = bnPowLimit;
|
bnNew = bnPowLimit;
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
|||||||
CBlockIndex pindexLast;
|
CBlockIndex pindexLast;
|
||||||
pindexLast.nHeight = 2015;
|
pindexLast.nHeight = 2015;
|
||||||
pindexLast.nTime = 1233061996; // Block #2015
|
pindexLast.nTime = 1233061996; // Block #2015
|
||||||
pindexLast.nBits = 0x1d00ffff;
|
// TODO change once the harder genesis block is generated
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00ffff);
|
pindexLast.nBits = 0x207fffff;
|
||||||
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x207fffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the lower bound for actual time taken */
|
/* Test the constraint on the lower bound for actual time taken */
|
||||||
@@ -52,7 +53,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
|||||||
pindexLast.nHeight = 68543;
|
pindexLast.nHeight = 68543;
|
||||||
pindexLast.nTime = 1279297671; // Block #68543
|
pindexLast.nTime = 1279297671; // Block #68543
|
||||||
pindexLast.nBits = 0x1c05a3f4;
|
pindexLast.nBits = 0x1c05a3f4;
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fd);
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the upper bound for actual time taken */
|
/* Test the constraint on the upper bound for actual time taken */
|
||||||
|
|||||||
Reference in New Issue
Block a user