From 1f7ee4af70ece8759f7a4e6d8df9c39284bb1482 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 4 Oct 2018 23:26:05 +0100 Subject: [PATCH] Rename min-difficulty flag to remove off-by-one in the name --- src/chainparams.cpp | 6 +++--- src/consensus/params.h | 2 +- src/miner.cpp | 4 ++-- src/pow.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 25f9f45f3..8ebf04c6f 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.nPowAllowMinDifficultyBlocksFromHeight = boost::none; + consensus.nPowAllowMinDifficultyBlocksAfterHeight = 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.nPowAllowMinDifficultyBlocksFromHeight = 299187; + consensus.nPowAllowMinDifficultyBlocksAfterHeight = 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.nPowAllowMinDifficultyBlocksFromHeight = 0; + consensus.nPowAllowMinDifficultyBlocksAfterHeight = 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 4e6f7b86a..26288f243 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -93,7 +93,7 @@ struct Params { NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]; /** Proof of work parameters */ uint256 powLimit; - boost::optional nPowAllowMinDifficultyBlocksFromHeight; + boost::optional nPowAllowMinDifficultyBlocksAfterHeight; int64_t nPowAveragingWindow; int64_t nPowMaxAdjustDown; int64_t nPowMaxAdjustUp; diff --git a/src/miner.cpp b/src/miner.cpp index 960ac60de..b76226ecc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -103,7 +103,7 @@ 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.nPowAllowMinDifficultyBlocksFromHeight) { + if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight) { pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } } @@ -727,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().nPowAllowMinDifficultyBlocksFromHeight) + if (chainparams.GetConsensus().nPowAllowMinDifficultyBlocksAfterHeight) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); diff --git a/src/pow.cpp b/src/pow.cpp index 7bc2fa79f..82c817efb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -25,8 +25,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return nProofOfWorkLimit; { - if (params.nPowAllowMinDifficultyBlocksFromHeight && - pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksFromHeight.get()) + // Comparing to pindexLast->nHeight with >= because this function + // returns the work required for the block after pindexLast. + if (params.nPowAllowMinDifficultyBlocksAfterHeight && + pindexLast->nHeight >= params.nPowAllowMinDifficultyBlocksAfterHeight.get()) { // Special difficulty rule for testnet: // If the new block's timestamp is more than 6 * 2.5 minutes