Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | int64_t UpdateTime(CBlockHeader *pblock, const Config &config, | ||||
// Updating time can change work required on testnet: | // Updating time can change work required on testnet: | ||||
if (consensusParams.fPowAllowMinDifficultyBlocks) { | if (consensusParams.fPowAllowMinDifficultyBlocks) { | ||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, config); | pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, config); | ||||
} | } | ||||
return nNewTime - nOldTime; | return nNewTime - nOldTime; | ||||
} | } | ||||
static uint64_t ComputeMaxGeneratedBlockSize(const Config &config, | BlockAssembler::Options::Options() { | ||||
const CBlockIndex *pindexPrev) { | blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | ||||
// Block resource limits | nBlockMaxSize = DEFAULT_MAX_GENERATED_BLOCK_SIZE; | ||||
// If -blockmaxsize is not given, limit to DEFAULT_MAX_GENERATED_BLOCK_SIZE | |||||
// If only one is given, only restrict the specified resource. | |||||
// If both are given, restrict both. | |||||
uint64_t nMaxGeneratedBlockSize = DEFAULT_MAX_GENERATED_BLOCK_SIZE; | |||||
if (gArgs.IsArgSet("-blockmaxsize")) { | |||||
nMaxGeneratedBlockSize = | |||||
gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | |||||
} | } | ||||
// Limit size to between 1K and MaxBlockSize-1K for sanity: | BlockAssembler::BlockAssembler(const Config &_config, const CTxMemPool &mpool, | ||||
const Options &options) | |||||
: config(&_config), mempool(&mpool) { | |||||
Fabien: Nit: for consistency, `_mempool` instead of `mpool` | |||||
blockMinFeeRate = options.blockMinFeeRate; | |||||
// Limit size to between 1K and max block size-1K for sanity: | |||||
nMaxGeneratedBlockSize = | nMaxGeneratedBlockSize = | ||||
std::max(uint64_t(1000), std::min(config.GetMaxBlockSize() - 1000, | std::max(uint64_t(1000), std::min(config->GetMaxBlockSize() - 1000, | ||||
nMaxGeneratedBlockSize)); | options.nBlockMaxSize)); | ||||
return nMaxGeneratedBlockSize; | |||||
} | } | ||||
BlockAssembler::BlockAssembler(const Config &_config, const CTxMemPool &mpool) | static BlockAssembler::Options DefaultOptions() { | ||||
: config(&_config), mempool(&mpool) { | BlockAssembler::Options options; | ||||
options.nBlockMaxSize = DEFAULT_MAX_GENERATED_BLOCK_SIZE; | |||||
if (gArgs.IsArgSet("-blockmaxsize")) { | |||||
options.nBlockMaxSize = | |||||
gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | |||||
} | |||||
if (gArgs.IsArgSet("-blockmintxfee")) { | if (gArgs.IsArgSet("-blockmintxfee")) { | ||||
Amount n = Amount::zero(); | Amount n = Amount::zero(); | ||||
ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n); | ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n); | ||||
blockMinFeeRate = CFeeRate(n); | options.blockMinFeeRate = CFeeRate(n); | ||||
} else { | } else { | ||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | options.blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | ||||
} | } | ||||
return options; | |||||
LOCK(cs_main); | |||||
nMaxGeneratedBlockSize = | |||||
ComputeMaxGeneratedBlockSize(*config, chainActive.Tip()); | |||||
} | } | ||||
BlockAssembler::BlockAssembler(const Config &_config, const CTxMemPool &mpool) | |||||
: BlockAssembler(_config, mpool, DefaultOptions()) {} | |||||
FabienUnsubmitted Not Done Inline ActionsDito Fabien: Dito | |||||
void BlockAssembler::resetBlock() { | void BlockAssembler::resetBlock() { | ||||
inBlock.clear(); | inBlock.clear(); | ||||
// Reserve space for coinbase tx. | // Reserve space for coinbase tx. | ||||
nBlockSize = 1000; | nBlockSize = 1000; | ||||
nBlockSigOps = 100; | nBlockSigOps = 100; | ||||
// These counters do not include coinbase tx. | // These counters do not include coinbase tx. | ||||
Show All 38 Lines | pblock->nVersion = | ||||
ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); | ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); | ||||
// -regtest only: allow overriding block.nVersion with | // -regtest only: allow overriding block.nVersion with | ||||
// -blockversion=N to test forking scenarios | // -blockversion=N to test forking scenarios | ||||
if (chainparams.MineBlocksOnDemand()) { | if (chainparams.MineBlocksOnDemand()) { | ||||
pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); | pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); | ||||
} | } | ||||
pblock->nTime = GetAdjustedTime(); | pblock->nTime = GetAdjustedTime(); | ||||
nMaxGeneratedBlockSize = ComputeMaxGeneratedBlockSize(*config, pindexPrev); | |||||
nMedianTimePast = pindexPrev->GetMedianTimePast(); | nMedianTimePast = pindexPrev->GetMedianTimePast(); | ||||
nLockTimeCutoff = | nLockTimeCutoff = | ||||
(STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) | (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) | ||||
? nMedianTimePast | ? nMedianTimePast | ||||
: pblock->GetBlockTime(); | : pblock->GetBlockTime(); | ||||
addPriorityTxs(); | addPriorityTxs(); | ||||
int nPackagesSelected = 0; | int nPackagesSelected = 0; | ||||
int nDescendantsUpdated = 0; | int nDescendantsUpdated = 0; | ||||
▲ Show 20 Lines • Show All 550 Lines • Show Last 20 Lines |
Nit: for consistency, _mempool instead of mpool