diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a43d800aa..c2b005dd0 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -102,6 +102,7 @@ public: consensus.nMajorityRejectBlockOutdated = 950; consensus.nMajorityWindow = 4000; consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); consensus.nPowAveragingWindow = 17; consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins @@ -240,7 +241,7 @@ void *chainparams_commandline(void *ptr) // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing mainParams.consensus.nLwmaAjustedWeight = 1350; mainParams.consensus.nPowAveragingWindow = 45; - mainParams.consensus.powLimit = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + mainParams.consensus.powAlternate = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); } checkpointData = //(Checkpoints::CCheckpointData) @@ -431,6 +432,7 @@ public: consensus.nMajorityRejectBlockOutdated = 75; consensus.nMajorityWindow = 400; consensus.powLimit = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + consensus.powAlternate = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.nPowAveragingWindow = 17; assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow); consensus.nMaxFutureBlockTime = 7 * 60; @@ -521,6 +523,7 @@ public: consensus.nMajorityRejectBlockOutdated = 950; consensus.nMajorityWindow = 1000; consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); consensus.nPowAveragingWindow = 17; consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow); diff --git a/src/consensus/params.h b/src/consensus/params.h index a072f50cb..c901547ae 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -92,6 +92,7 @@ struct Params { /** Proof of work parameters */ uint256 powLimit; + uint256 powAlternate; int64_t nPowAveragingWindow; int64_t nPowMaxAdjustDown; int64_t nPowMaxAdjustUp; diff --git a/src/pow.cpp b/src/pow.cpp index 11c4b17ab..c2fa9c37d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -95,12 +95,17 @@ unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params) { - unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); + arith_uint256 nextTarget {0}, sumTarget {0}, bnTmp, bnLimit; + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + bnLimit = UintToArith256(params.powLimit); + else + bnLimit = UintToArith256(params.powAlternate); + + unsigned int nProofOfWorkLimit = bnLimit.GetCompact(); // Find the first block in the averaging interval as we total the linearly weighted average const CBlockIndex* pindexFirst = pindexLast; const CBlockIndex* pindexNext; - arith_uint256 nextTarget {0}, sumTarget {0}, bnTmp; int64_t t = 0, solvetime, k = params.nLwmaAjustedWeight, N = params.nPowAveragingWindow; for (int i = 0, j = N - 1; pindexFirst && i < N; i++, j--) { @@ -129,7 +134,7 @@ unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const if (t < N * k / 3) t = N * k / 3; - bnTmp = UintToArith256(params.powLimit); + bnTmp = bnLimit; nextTarget = t * sumTarget; if (nextTarget > bnTmp) nextTarget = bnTmp; @@ -246,7 +251,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } } } - if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) + arith_uint256 bnLimit = (height <= 1 || ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) ? UintToArith256(params.powLimit) : UintToArith256(params.powAlternate); + if (fNegative || bnTarget == 0 || fOverflow || bnTarget > bnLimit) return error("CheckProofOfWork(): nBits below minimum work"); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget )