Unify GetNextWorkRequired (#1737)
* unify GetNextWorkRequired * drop enum
This commit is contained in:
parent
3280097495
commit
865b61b503
@ -96,6 +96,8 @@ public:
|
||||
consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes
|
||||
consensus.fPowAllowMinDifficultyBlocks = false;
|
||||
consensus.fPowNoRetargeting = false;
|
||||
consensus.nPowKGWHeight = 15200;
|
||||
consensus.nPowDGWHeight = 34140;
|
||||
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
|
||||
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
||||
@ -235,6 +237,8 @@ public:
|
||||
consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes
|
||||
consensus.fPowAllowMinDifficultyBlocks = true;
|
||||
consensus.fPowNoRetargeting = false;
|
||||
consensus.nPowKGWHeight = 4001; // nPowKGWHeight >= nPowDGWHeight means "no KGW"
|
||||
consensus.nPowDGWHeight = 4001;
|
||||
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
|
||||
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
||||
@ -352,6 +356,8 @@ public:
|
||||
consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes
|
||||
consensus.fPowAllowMinDifficultyBlocks = true;
|
||||
consensus.fPowNoRetargeting = true;
|
||||
consensus.nPowKGWHeight = 15200; // same as mainnet
|
||||
consensus.nPowDGWHeight = 34140; // same as mainnet
|
||||
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
|
||||
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
||||
|
@ -79,6 +79,8 @@ struct Params {
|
||||
bool fPowNoRetargeting;
|
||||
int64_t nPowTargetSpacing;
|
||||
int64_t nPowTargetTimespan;
|
||||
int nPowKGWHeight;
|
||||
int nPowDGWHeight;
|
||||
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
|
||||
uint256 nMinimumChainWork;
|
||||
uint256 defaultAssumeValid;
|
||||
|
31
src/pow.cpp
31
src/pow.cpp
@ -171,33 +171,16 @@ unsigned int GetNextWorkRequiredBTC(const CBlockIndex* pindexLast, const CBlockH
|
||||
|
||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
|
||||
{
|
||||
unsigned int retarget = DIFF_DGW;
|
||||
|
||||
// mainnet/regtest share a configuration
|
||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN || Params().NetworkIDString() == CBaseChainParams::REGTEST) {
|
||||
if (pindexLast->nHeight + 1 >= 34140) retarget = DIFF_DGW;
|
||||
else if (pindexLast->nHeight + 1 >= 15200) retarget = DIFF_KGW;
|
||||
else retarget = DIFF_BTC;
|
||||
// testnet -- we want a lot of coins in existance early on
|
||||
} else {
|
||||
if (pindexLast->nHeight + 1 >= 4001) retarget = DIFF_DGW;
|
||||
else retarget = DIFF_BTC;
|
||||
// Most recent algo first
|
||||
if (pindexLast->nHeight + 1 >= params.nPowDGWHeight) {
|
||||
return DarkGravityWave(pindexLast, params);
|
||||
}
|
||||
|
||||
// Bitcoin style retargeting
|
||||
if (retarget == DIFF_BTC)
|
||||
{
|
||||
return GetNextWorkRequiredBTC(pindexLast, pblock, params);
|
||||
}
|
||||
|
||||
// Retarget using Kimoto Gravity Wave
|
||||
else if (retarget == DIFF_KGW)
|
||||
{
|
||||
else if (pindexLast->nHeight + 1 >= params.nPowKGWHeight) {
|
||||
return KimotoGravityWell(pindexLast, params);
|
||||
}
|
||||
|
||||
// Retarget using Dark Gravity Wave 3 by default
|
||||
return DarkGravityWave(pindexLast, params);
|
||||
else {
|
||||
return GetNextWorkRequiredBTC(pindexLast, pblock, params);
|
||||
}
|
||||
}
|
||||
|
||||
// for DIFF_BTC only!
|
||||
|
@ -15,13 +15,6 @@ class CBlockIndex;
|
||||
class uint256;
|
||||
class arith_uint256;
|
||||
|
||||
// Define difficulty retarget algorithms
|
||||
enum DiffMode {
|
||||
DIFF_DEFAULT = 0, // Default to invalid 0
|
||||
DIFF_BTC = 1, // Retarget every x blocks (Bitcoin style)
|
||||
DIFF_KGW = 2, // Retarget using Kimoto Gravity Well
|
||||
DIFF_DGW = 3, // Retarget using Dark Gravity Wave v3
|
||||
};
|
||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);
|
||||
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user