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
9091CBlockTemplate* 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 );
0 commit comments