From aa86873afd932eddc053cd45a90580cff6bb279c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 8 Apr 2016 23:19:03 +1200 Subject: [PATCH] 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. --- src/pow.cpp | 2 +- src/test/pow_tests.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 1b5a87890..ebcba1dae 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -71,8 +71,8 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF arith_uint256 bnOld; bnNew.SetCompact(pindexLast->nBits); bnOld = bnNew; - bnNew *= nActualTimespan; bnNew /= params.nPowTargetTimespan; + bnNew *= nActualTimespan; if (bnNew > bnPowLimit) bnNew = bnPowLimit; diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index a43674928..8e244f1ee 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -37,8 +37,9 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) CBlockIndex pindexLast; pindexLast.nHeight = 2015; pindexLast.nTime = 1233061996; // Block #2015 - pindexLast.nBits = 0x1d00ffff; - BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00ffff); + // TODO change once the harder genesis block is generated + pindexLast.nBits = 0x207fffff; + BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x207fffff); } /* 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.nTime = 1279297671; // Block #68543 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 */