Merge pull request #5998
bebe728
Chainparams: Refactor: Remove redundant AllowMinDifficultyBlocks() getter (Jorge Timón)
This commit is contained in:
commit
9ab7cbffce
@ -56,8 +56,6 @@ public:
|
|||||||
bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
|
bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
|
||||||
/** Default value for -checkmempool and -checkblockindex argument */
|
/** Default value for -checkmempool and -checkblockindex argument */
|
||||||
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
|
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
|
||||||
/** Allow mining of a min-difficulty block */
|
|
||||||
bool AllowMinDifficultyBlocks() const { return consensus.fPowAllowMinDifficultyBlocks; }
|
|
||||||
/** Make standard checks */
|
/** Make standard checks */
|
||||||
bool RequireStandard() const { return fRequireStandard; }
|
bool RequireStandard() const { return fRequireStandard; }
|
||||||
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
|
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
#include "miner.h"
|
#include "miner.h"
|
||||||
|
|
||||||
#include "amount.h"
|
#include "amount.h"
|
||||||
#include "primitives/transaction.h"
|
#include "chainparams.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "pow.h"
|
#include "pow.h"
|
||||||
|
#include "primitives/transaction.h"
|
||||||
#include "timedata.h"
|
#include "timedata.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "utilmoneystr.h"
|
#include "utilmoneystr.h"
|
||||||
@ -78,13 +79,13 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
|
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
|
||||||
{
|
{
|
||||||
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||||
|
|
||||||
// Updating time can change work required on testnet:
|
// Updating time can change work required on testnet:
|
||||||
if (Params().AllowMinDifficultyBlocks())
|
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||||
@ -325,7 +326,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
|
|
||||||
// Fill in header
|
// Fill in header
|
||||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||||
UpdateTime(pblock, pindexPrev);
|
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||||
pblock->nNonce = 0;
|
pblock->nNonce = 0;
|
||||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||||
@ -440,6 +441,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
LogPrintf("BitcoinMiner started\n");
|
LogPrintf("BitcoinMiner started\n");
|
||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||||
RenameThread("bitcoin-miner");
|
RenameThread("bitcoin-miner");
|
||||||
|
const CChainParams& chainparams = Params();
|
||||||
|
|
||||||
// Each thread has its own key and counter
|
// Each thread has its own key and counter
|
||||||
CReserveKey reservekey(pwallet);
|
CReserveKey reservekey(pwallet);
|
||||||
@ -447,7 +449,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (Params().MiningRequiresPeers()) {
|
if (chainparams.MiningRequiresPeers()) {
|
||||||
// Busy-wait for the network to come online so we don't waste time mining
|
// Busy-wait for the network to come online so we don't waste time mining
|
||||||
// on an obsolete chain. In regtest mode we expect to fly solo.
|
// on an obsolete chain. In regtest mode we expect to fly solo.
|
||||||
while (vNodes.empty())
|
while (vNodes.empty())
|
||||||
@ -496,7 +498,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||||
|
|
||||||
// In regression test mode, stop mining after a block is found.
|
// In regression test mode, stop mining after a block is found.
|
||||||
if (Params().MineBlocksOnDemand())
|
if (chainparams.MineBlocksOnDemand())
|
||||||
throw boost::thread_interrupted();
|
throw boost::thread_interrupted();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -506,7 +508,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
// Check for stop or if block needs to be rebuilt
|
// Check for stop or if block needs to be rebuilt
|
||||||
boost::this_thread::interruption_point();
|
boost::this_thread::interruption_point();
|
||||||
// Regtest mode doesn't require peers
|
// Regtest mode doesn't require peers
|
||||||
if (vNodes.empty() && Params().MiningRequiresPeers())
|
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
||||||
break;
|
break;
|
||||||
if (nNonce >= 0xffff0000)
|
if (nNonce >= 0xffff0000)
|
||||||
break;
|
break;
|
||||||
@ -516,8 +518,8 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// Update nTime every few seconds
|
// Update nTime every few seconds
|
||||||
UpdateTime(pblock, pindexPrev);
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||||
if (Params().AllowMinDifficultyBlocks())
|
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||||
{
|
{
|
||||||
// Changing pblock->nTime can change work required on testnet:
|
// Changing pblock->nTime can change work required on testnet:
|
||||||
hashTarget.SetCompact(pblock->nBits);
|
hashTarget.SetCompact(pblock->nBits);
|
||||||
|
@ -14,6 +14,7 @@ class CBlockIndex;
|
|||||||
class CReserveKey;
|
class CReserveKey;
|
||||||
class CScript;
|
class CScript;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
|
namespace Consensus { class Params; };
|
||||||
|
|
||||||
struct CBlockTemplate
|
struct CBlockTemplate
|
||||||
{
|
{
|
||||||
@ -29,6 +30,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
|
|||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
|
||||||
/** Modify the extranonce in a block */
|
/** Modify the extranonce in a block */
|
||||||
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
|
||||||
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
|
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
|
||||||
|
|
||||||
#endif // BITCOIN_MINER_H
|
#endif // BITCOIN_MINER_H
|
||||||
|
@ -514,7 +514,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
|||||||
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
|
|
||||||
// Update nTime
|
// Update nTime
|
||||||
UpdateTime(pblock, pindexPrev);
|
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||||
pblock->nNonce = 0;
|
pblock->nNonce = 0;
|
||||||
|
|
||||||
static const Array aCaps = boost::assign::list_of("proposal");
|
static const Array aCaps = boost::assign::list_of("proposal");
|
||||||
|
Loading…
Reference in New Issue
Block a user