Fix to separate minimum difficulties for primary and alternate algorithms
This commit is contained in:
@@ -102,6 +102,7 @@ public:
|
|||||||
consensus.nMajorityRejectBlockOutdated = 950;
|
consensus.nMajorityRejectBlockOutdated = 950;
|
||||||
consensus.nMajorityWindow = 4000;
|
consensus.nMajorityWindow = 4000;
|
||||||
consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||||
|
consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||||
consensus.nPowAveragingWindow = 17;
|
consensus.nPowAveragingWindow = 17;
|
||||||
consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins
|
consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins
|
||||||
|
|
||||||
@@ -240,7 +241,7 @@ void *chainparams_commandline(void *ptr)
|
|||||||
// nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing
|
// nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing
|
||||||
mainParams.consensus.nLwmaAjustedWeight = 1350;
|
mainParams.consensus.nLwmaAjustedWeight = 1350;
|
||||||
mainParams.consensus.nPowAveragingWindow = 45;
|
mainParams.consensus.nPowAveragingWindow = 45;
|
||||||
mainParams.consensus.powLimit = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
mainParams.consensus.powAlternate = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpointData = //(Checkpoints::CCheckpointData)
|
checkpointData = //(Checkpoints::CCheckpointData)
|
||||||
@@ -431,6 +432,7 @@ public:
|
|||||||
consensus.nMajorityRejectBlockOutdated = 75;
|
consensus.nMajorityRejectBlockOutdated = 75;
|
||||||
consensus.nMajorityWindow = 400;
|
consensus.nMajorityWindow = 400;
|
||||||
consensus.powLimit = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
consensus.powLimit = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||||
|
consensus.powAlternate = uint256S("07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||||
consensus.nPowAveragingWindow = 17;
|
consensus.nPowAveragingWindow = 17;
|
||||||
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
||||||
consensus.nMaxFutureBlockTime = 7 * 60;
|
consensus.nMaxFutureBlockTime = 7 * 60;
|
||||||
@@ -521,6 +523,7 @@ public:
|
|||||||
consensus.nMajorityRejectBlockOutdated = 950;
|
consensus.nMajorityRejectBlockOutdated = 950;
|
||||||
consensus.nMajorityWindow = 1000;
|
consensus.nMajorityWindow = 1000;
|
||||||
consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||||
|
consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||||
consensus.nPowAveragingWindow = 17;
|
consensus.nPowAveragingWindow = 17;
|
||||||
consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins
|
consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins
|
||||||
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow);
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ struct Params {
|
|||||||
|
|
||||||
/** Proof of work parameters */
|
/** Proof of work parameters */
|
||||||
uint256 powLimit;
|
uint256 powLimit;
|
||||||
|
uint256 powAlternate;
|
||||||
int64_t nPowAveragingWindow;
|
int64_t nPowAveragingWindow;
|
||||||
int64_t nPowMaxAdjustDown;
|
int64_t nPowMaxAdjustDown;
|
||||||
int64_t nPowMaxAdjustUp;
|
int64_t nPowMaxAdjustUp;
|
||||||
|
|||||||
14
src/pow.cpp
14
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 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
|
// Find the first block in the averaging interval as we total the linearly weighted average
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
const CBlockIndex* pindexFirst = pindexLast;
|
||||||
const CBlockIndex* pindexNext;
|
const CBlockIndex* pindexNext;
|
||||||
arith_uint256 nextTarget {0}, sumTarget {0}, bnTmp;
|
|
||||||
int64_t t = 0, solvetime, k = params.nLwmaAjustedWeight, N = params.nPowAveragingWindow;
|
int64_t t = 0, solvetime, k = params.nLwmaAjustedWeight, N = params.nPowAveragingWindow;
|
||||||
|
|
||||||
for (int i = 0, j = N - 1; pindexFirst && i < N; i++, j--) {
|
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)
|
if (t < N * k / 3)
|
||||||
t = N * k / 3;
|
t = N * k / 3;
|
||||||
|
|
||||||
bnTmp = UintToArith256(params.powLimit);
|
bnTmp = bnLimit;
|
||||||
nextTarget = t * sumTarget;
|
nextTarget = t * sumTarget;
|
||||||
if (nextTarget > bnTmp)
|
if (nextTarget > bnTmp)
|
||||||
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");
|
return error("CheckProofOfWork(): nBits below minimum work");
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash) > bnTarget )
|
if ( UintToArith256(hash) > bnTarget )
|
||||||
|
|||||||
Reference in New Issue
Block a user