diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b0352a66d..25f9f45f3 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -95,7 +95,7 @@ public: consensus.nPowMaxAdjustDown = 32; // 32% adjustment down consensus.nPowMaxAdjustUp = 16; // 16% adjustment up consensus.nPowTargetSpacing = 2.5 * 60; - consensus.fPowAllowMinDifficultyBlocks = false; + consensus.nPowAllowMinDifficultyBlocksFromHeight = boost::none; consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = Consensus::NetworkUpgrade::ALWAYS_ACTIVE; @@ -272,7 +272,7 @@ public: consensus.nPowMaxAdjustDown = 32; // 32% adjustment down consensus.nPowMaxAdjustUp = 16; // 16% adjustment up consensus.nPowTargetSpacing = 2.5 * 60; - consensus.fPowAllowMinDifficultyBlocks = true; + consensus.nPowAllowMinDifficultyBlocksFromHeight = 299187; consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = Consensus::NetworkUpgrade::ALWAYS_ACTIVE; @@ -393,7 +393,7 @@ public: consensus.nPowMaxAdjustDown = 0; // Turn off adjustment down consensus.nPowMaxAdjustUp = 0; // Turn off adjustment up consensus.nPowTargetSpacing = 2.5 * 60; - consensus.fPowAllowMinDifficultyBlocks = true; + consensus.nPowAllowMinDifficultyBlocksFromHeight = 0; consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = Consensus::NetworkUpgrade::ALWAYS_ACTIVE; diff --git a/src/consensus/params.h b/src/consensus/params.h index 50eb69a45..4e6f7b86a 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -8,6 +8,8 @@ #include "uint256.h" +#include + namespace Consensus { /** @@ -91,7 +93,7 @@ struct Params { NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]; /** Proof of work parameters */ uint256 powLimit; - bool fPowAllowMinDifficultyBlocks; + boost::optional nPowAllowMinDifficultyBlocksFromHeight; int64_t nPowAveragingWindow; int64_t nPowMaxAdjustDown; int64_t nPowMaxAdjustUp; diff --git a/src/miner.cpp b/src/miner.cpp index 19912eb67..960ac60de 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -103,8 +103,9 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); // Updating time can change work required on testnet: - if (consensusParams.fPowAllowMinDifficultyBlocks) + if (consensusParams.nPowAllowMinDifficultyBlocksFromHeight) { pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); + } } CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) @@ -726,7 +727,7 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); - if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) + if (chainparams.GetConsensus().nPowAllowMinDifficultyBlocksFromHeight) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); diff --git a/src/pow.cpp b/src/pow.cpp index 40e69bb52..7bc2fa79f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -25,7 +25,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return nProofOfWorkLimit; { - if (params.fPowAllowMinDifficultyBlocks) + if (params.nPowAllowMinDifficultyBlocksFromHeight && + pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksFromHeight.get()) { // Special difficulty rule for testnet: // If the new block's timestamp is more than 6 * 2.5 minutes