Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | 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, | static uint64_t ComputeMaxGeneratedBlockSize(const Config &config, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
// Block resource limits | |||||
// If -blockmaxsize is not given, limit to 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; | uint64_t nMaxGeneratedBlockSize = DEFAULT_MAX_GENERATED_BLOCK_SIZE; | ||||
if (gArgs.IsArgSet("-blockmaxsize")) { | if (gArgs.IsArgSet("-blockmaxsize")) { | ||||
nMaxGeneratedBlockSize = | nMaxGeneratedBlockSize = | ||||
gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); | ||||
} | } | ||||
// Limit size to between 1K and MaxBlockSize-1K for sanity: | // Limit size to between 1K and MaxBlockSize-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)); | nMaxGeneratedBlockSize)); | ||||
return nMaxGeneratedBlockSize; | return nMaxGeneratedBlockSize; | ||||
} | } | ||||
BlockAssembler::BlockAssembler(const Config &_config, const CTxMemPool &mpool) | BlockAssembler::Options::Options() { | ||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB); | |||||
nBlockMaxSize = DEFAULT_MAX_BLOCK_SIZE; | |||||
} | |||||
BlockAssembler::BlockAssembler(const Config &_config, const CTxMemPool &mpool, | |||||
const Options &options) | |||||
: config(&_config), mempool(&mpool) { | : config(&_config), mempool(&mpool) { | ||||
blockMinFeeRate = options.blockMinFeeRate; | |||||
// Limit size to between 1K and max block size-1K for sanity: | |||||
nMaxGeneratedBlockSize = | |||||
std::max(uint64_t(1000), std::min(config->GetMaxBlockSize() - 1000, | |||||
options.nBlockMaxSize)); | |||||
} | |||||
static BlockAssembler::Options DefaultOptions(const Config &config) { | |||||
BlockAssembler::Options options; | |||||
{ | |||||
LOCK(cs_main); | |||||
options.nBlockMaxSize = | |||||
ComputeMaxGeneratedBlockSize(config, chainActive.Tip()); | |||||
} | |||||
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(_config)) {} | |||||
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 20 Lines • Show All 607 Lines • Show Last 20 Lines |