Skip to content

Commit 9ab7cbf

Browse files
committed
Merge pull request #5998
bebe728 Chainparams: Refactor: Remove redundant AllowMinDifficultyBlocks() getter (Jorge Timón)
2 parents ea2b425 + bebe728 commit 9ab7cbf

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/chainparams.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class CChainParams
5656
bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
5757
/** Default value for -checkmempool and -checkblockindex argument */
5858
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
59-
/** Allow mining of a min-difficulty block */
60-
bool AllowMinDifficultyBlocks() const { return consensus.fPowAllowMinDifficultyBlocks; }
6159
/** Make standard checks */
6260
bool RequireStandard() const { return fRequireStandard; }
6361
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */

src/miner.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include "miner.h"
77

88
#include "amount.h"
9-
#include "primitives/transaction.h"
9+
#include "chainparams.h"
1010
#include "hash.h"
1111
#include "main.h"
1212
#include "net.h"
1313
#include "pow.h"
14+
#include "primitives/transaction.h"
1415
#include "timedata.h"
1516
#include "util.h"
1617
#include "utilmoneystr.h"
@@ -78,13 +79,13 @@ class TxPriorityCompare
7879
}
7980
};
8081

81-
void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
82+
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
8283
{
8384
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
8485

8586
// Updating time can change work required on testnet:
86-
if (Params().AllowMinDifficultyBlocks())
87-
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
87+
if (consensusParams.fPowAllowMinDifficultyBlocks)
88+
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
8889
}
8990

9091
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
@@ -325,7 +326,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
325326

326327
// Fill in header
327328
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
328-
UpdateTime(pblock, pindexPrev);
329+
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
329330
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
330331
pblock->nNonce = 0;
331332
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
@@ -440,14 +441,15 @@ void static BitcoinMiner(CWallet *pwallet)
440441
LogPrintf("BitcoinMiner started\n");
441442
SetThreadPriority(THREAD_PRIORITY_LOWEST);
442443
RenameThread("bitcoin-miner");
444+
const CChainParams& chainparams = Params();
443445

444446
// Each thread has its own key and counter
445447
CReserveKey reservekey(pwallet);
446448
unsigned int nExtraNonce = 0;
447449

448450
try {
449451
while (true) {
450-
if (Params().MiningRequiresPeers()) {
452+
if (chainparams.MiningRequiresPeers()) {
451453
// Busy-wait for the network to come online so we don't waste time mining
452454
// on an obsolete chain. In regtest mode we expect to fly solo.
453455
while (vNodes.empty())
@@ -496,7 +498,7 @@ void static BitcoinMiner(CWallet *pwallet)
496498
SetThreadPriority(THREAD_PRIORITY_LOWEST);
497499

498500
// In regression test mode, stop mining after a block is found.
499-
if (Params().MineBlocksOnDemand())
501+
if (chainparams.MineBlocksOnDemand())
500502
throw boost::thread_interrupted();
501503

502504
break;
@@ -506,7 +508,7 @@ void static BitcoinMiner(CWallet *pwallet)
506508
// Check for stop or if block needs to be rebuilt
507509
boost::this_thread::interruption_point();
508510
// Regtest mode doesn't require peers
509-
if (vNodes.empty() && Params().MiningRequiresPeers())
511+
if (vNodes.empty() && chainparams.MiningRequiresPeers())
510512
break;
511513
if (nNonce >= 0xffff0000)
512514
break;
@@ -516,8 +518,8 @@ void static BitcoinMiner(CWallet *pwallet)
516518
break;
517519

518520
// Update nTime every few seconds
519-
UpdateTime(pblock, pindexPrev);
520-
if (Params().AllowMinDifficultyBlocks())
521+
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
522+
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
521523
{
522524
// Changing pblock->nTime can change work required on testnet:
523525
hashTarget.SetCompact(pblock->nBits);

src/miner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CBlockIndex;
1414
class CReserveKey;
1515
class CScript;
1616
class CWallet;
17+
namespace Consensus { class Params; };
1718

1819
struct CBlockTemplate
1920
{
@@ -29,6 +30,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
2930
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
3031
/** Modify the extranonce in a block */
3132
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
32-
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
33+
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
3334

3435
#endif // BITCOIN_MINER_H

src/rpcmining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
514514
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
515515

516516
// Update nTime
517-
UpdateTime(pblock, pindexPrev);
517+
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
518518
pblock->nNonce = 0;
519519

520520
static const Array aCaps = boost::assign::list_of("proposal");

0 commit comments

Comments
 (0)