Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | BlockAssembler::BlockAssembler(const CChainParams ¶ms, | ||||
const CTxMemPool &_mempool, | const CTxMemPool &_mempool, | ||||
const Options &options) | const Options &options) | ||||
: chainparams(params), mempool(&_mempool) { | : chainparams(params), mempool(&_mempool) { | ||||
blockMinFeeRate = options.blockMinFeeRate; | blockMinFeeRate = options.blockMinFeeRate; | ||||
// Limit size to between 1K and options.nExcessiveBlockSize -1K for sanity: | // Limit size to between 1K and options.nExcessiveBlockSize -1K for sanity: | ||||
nMaxGeneratedBlockSize = std::max<uint64_t>( | nMaxGeneratedBlockSize = std::max<uint64_t>( | ||||
1000, std::min<uint64_t>(options.nExcessiveBlockSize - 1000, | 1000, std::min<uint64_t>(options.nExcessiveBlockSize - 1000, | ||||
options.nMaxGeneratedBlockSize)); | options.nMaxGeneratedBlockSize)); | ||||
// Calculate the max consensus sigchecks for this block. | |||||
auto nMaxBlockSigChecks = | |||||
GetMaxBlockSigChecksCount(options.nExcessiveBlockSize); | |||||
// Allow the full amount of signature check operations in lieu of a separate | |||||
// config option. (We are mining relayed transactions with validity cached | |||||
// by everyone else, and so the block will propagate quickly, regardless of | |||||
// how many sigchecks it contains.) | |||||
nMaxGeneratedBlockSigChecks = nMaxBlockSigChecks; | |||||
} | } | ||||
static BlockAssembler::Options DefaultOptions(const Config &config) { | static BlockAssembler::Options DefaultOptions(const Config &config) { | ||||
// Block resource limits | // 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 only one is given, only restrict the specified resource. | ||||
// If both are given, restrict both. | // If both are given, restrict both. | ||||
BlockAssembler::Options options; | BlockAssembler::Options options; | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
pblock->nTime = GetAdjustedTime(); | pblock->nTime = GetAdjustedTime(); | ||||
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(); | ||||
// After the sigchecks activation we repurpose the 'sigops' tracking in | |||||
// mempool/mining to actually track sigchecks instead. (Proper SigOps will | |||||
// not need to be counted any more since it's getting deactivated.) | |||||
fUseSigChecks = IsPhononEnabled(chainparams.GetConsensus(), pindexPrev); | |||||
int nPackagesSelected = 0; | int nPackagesSelected = 0; | ||||
int nDescendantsUpdated = 0; | int nDescendantsUpdated = 0; | ||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated); | addPackageTxs(nPackagesSelected, nDescendantsUpdated); | ||||
if (IsMagneticAnomalyEnabled(consensusParams, pindexPrev)) { | if (IsMagneticAnomalyEnabled(consensusParams, pindexPrev)) { | ||||
// If magnetic anomaly is enabled, we make sure transaction are | // If magnetic anomaly is enabled, we make sure transaction are | ||||
// canonically ordered. | // canonically ordered. | ||||
std::sort(std::begin(pblocktemplate->entries) + 1, | std::sort(std::begin(pblocktemplate->entries) + 1, | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | for (CTxMemPool::setEntries::iterator iit = testSet.begin(); | ||||
if (inBlock.count(*iit)) { | if (inBlock.count(*iit)) { | ||||
testSet.erase(iit++); | testSet.erase(iit++); | ||||
} else { | } else { | ||||
iit++; | iit++; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
uint64_t BlockAssembler::MaxBlockSigOpsCountForSize(uint64_t blockSize) const { | |||||
return fUseSigChecks ? nMaxGeneratedBlockSigChecks | |||||
: GetMaxBlockSigOpsCount(blockSize); | |||||
} | |||||
bool BlockAssembler::TestPackage(uint64_t packageSize, | bool BlockAssembler::TestPackage(uint64_t packageSize, | ||||
int64_t packageSigOps) const { | int64_t packageSigOps) const { | ||||
auto blockSizeWithPackage = nBlockSize + packageSize; | auto blockSizeWithPackage = nBlockSize + packageSize; | ||||
if (blockSizeWithPackage >= nMaxGeneratedBlockSize) { | if (blockSizeWithPackage >= nMaxGeneratedBlockSize) { | ||||
return false; | return false; | ||||
} | } | ||||
if (nBlockSigOps + packageSigOps >= | if (nBlockSigOps + packageSigOps >= | ||||
GetMaxBlockSigOpsCount(blockSizeWithPackage)) { | MaxBlockSigOpsCountForSize(blockSizeWithPackage)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Perform transaction-level checks before adding to block: | * Perform transaction-level checks before adding to block: | ||||
▲ Show 20 Lines • Show All 305 Lines • Show Last 20 Lines |