6
6
#include " miner.h"
7
7
8
8
#include " amount.h"
9
- #include " primitives/transaction .h"
9
+ #include " chainparams .h"
10
10
#include " hash.h"
11
11
#include " main.h"
12
12
#include " net.h"
13
13
#include " pow.h"
14
+ #include " primitives/transaction.h"
14
15
#include " timedata.h"
15
16
#include " util.h"
16
17
#include " utilmoneystr.h"
@@ -78,13 +79,13 @@ class TxPriorityCompare
78
79
}
79
80
};
80
81
81
- void UpdateTime (CBlockHeader* pblock, const CBlockIndex* pindexPrev)
82
+ void UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
82
83
{
83
84
pblock->nTime = std::max (pindexPrev->GetMedianTimePast ()+1 , GetAdjustedTime ());
84
85
85
86
// 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 );
88
89
}
89
90
90
91
CBlockTemplate* CreateNewBlock (const CScript& scriptPubKeyIn)
@@ -325,7 +326,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
325
326
326
327
// Fill in header
327
328
pblock->hashPrevBlock = pindexPrev->GetBlockHash ();
328
- UpdateTime (pblock, pindexPrev);
329
+ UpdateTime (pblock, Params (). GetConsensus (), pindexPrev);
329
330
pblock->nBits = GetNextWorkRequired (pindexPrev, pblock, Params ().GetConsensus ());
330
331
pblock->nNonce = 0 ;
331
332
pblocktemplate->vTxSigOps [0 ] = GetLegacySigOpCount (pblock->vtx [0 ]);
@@ -440,14 +441,15 @@ void static BitcoinMiner(CWallet *pwallet)
440
441
LogPrintf (" BitcoinMiner started\n " );
441
442
SetThreadPriority (THREAD_PRIORITY_LOWEST);
442
443
RenameThread (" bitcoin-miner" );
444
+ const CChainParams& chainparams = Params ();
443
445
444
446
// Each thread has its own key and counter
445
447
CReserveKey reservekey (pwallet);
446
448
unsigned int nExtraNonce = 0 ;
447
449
448
450
try {
449
451
while (true ) {
450
- if (Params () .MiningRequiresPeers ()) {
452
+ if (chainparams .MiningRequiresPeers ()) {
451
453
// Busy-wait for the network to come online so we don't waste time mining
452
454
// on an obsolete chain. In regtest mode we expect to fly solo.
453
455
while (vNodes.empty ())
@@ -496,7 +498,7 @@ void static BitcoinMiner(CWallet *pwallet)
496
498
SetThreadPriority (THREAD_PRIORITY_LOWEST);
497
499
498
500
// In regression test mode, stop mining after a block is found.
499
- if (Params () .MineBlocksOnDemand ())
501
+ if (chainparams .MineBlocksOnDemand ())
500
502
throw boost::thread_interrupted ();
501
503
502
504
break ;
@@ -506,7 +508,7 @@ void static BitcoinMiner(CWallet *pwallet)
506
508
// Check for stop or if block needs to be rebuilt
507
509
boost::this_thread::interruption_point ();
508
510
// Regtest mode doesn't require peers
509
- if (vNodes.empty () && Params () .MiningRequiresPeers ())
511
+ if (vNodes.empty () && chainparams .MiningRequiresPeers ())
510
512
break ;
511
513
if (nNonce >= 0xffff0000 )
512
514
break ;
@@ -516,8 +518,8 @@ void static BitcoinMiner(CWallet *pwallet)
516
518
break ;
517
519
518
520
// Update nTime every few seconds
519
- UpdateTime (pblock, pindexPrev);
520
- if (Params (). AllowMinDifficultyBlocks () )
521
+ UpdateTime (pblock, chainparams. GetConsensus (), pindexPrev);
522
+ if (chainparams. GetConsensus (). fPowAllowMinDifficultyBlocks )
521
523
{
522
524
// Changing pblock->nTime can change work required on testnet:
523
525
hashTarget.SetCompact (pblock->nBits );
0 commit comments