Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 149 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(); | ||||
const bool fLimitSigOpCount = | |||||
!IsPhononEnabled(chainparams.GetConsensus(), pindexPrev); | |||||
int nPackagesSelected = 0; | int nPackagesSelected = 0; | ||||
int nDescendantsUpdated = 0; | int nDescendantsUpdated = 0; | ||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated); | addPackageTxs(nPackagesSelected, nDescendantsUpdated, fLimitSigOpCount); | ||||
if (IsMagneticAnomalyEnabled(chainparams.GetConsensus(), pindexPrev)) { | if (IsMagneticAnomalyEnabled(chainparams.GetConsensus(), 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, | ||||
std::end(pblocktemplate->entries), | std::end(pblocktemplate->entries), | ||||
[](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b) | [](const CBlockTemplateEntry &a, const CBlockTemplateEntry &b) | ||||
-> bool { return a.tx->GetId() < b.tx->GetId(); }); | -> bool { return a.tx->GetId() < b.tx->GetId(); }); | ||||
▲ Show 20 Lines • Show All 73 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++; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool BlockAssembler::TestPackage(uint64_t packageSize, | bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOps, | ||||
int64_t packageSigOps) const { | bool fLimitSigOpCount) const { | ||||
auto blockSizeWithPackage = nBlockSize + packageSize; | auto blockSizeWithPackage = nBlockSize + packageSize; | ||||
if (blockSizeWithPackage >= nMaxGeneratedBlockSize) { | if (blockSizeWithPackage >= nMaxGeneratedBlockSize) { | ||||
return false; | return false; | ||||
} | } | ||||
if (nBlockSigOps + packageSigOps >= | if (fLimitSigOpCount && nBlockSigOps + packageSigOps >= | ||||
GetMaxBlockSigOpsCount(blockSizeWithPackage)) { | GetMaxBlockSigOpsCount(blockSizeWithPackage)) { | ||||
deadalnix: Passing a bool al over the place is messy and not really good. IMO you are better off creating… | |||||
markblundebergAuthorUnsubmitted Done Inline ActionsTrue, BlockAssembler already has chain context variables so it can go there. markblundeberg: True, BlockAssembler already has chain context variables so it can go there. | |||||
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 101 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* addPackageTx includes transactions paying a fee by ensuring that | * addPackageTx includes transactions paying a fee by ensuring that | ||||
* the partial ordering of transactions is maintained. That is to say | * the partial ordering of transactions is maintained. That is to say | ||||
* children come after parents, despite having a potentially larger fee. | * children come after parents, despite having a potentially larger fee. | ||||
* @param[out] nPackagesSelected How many packages were selected | * @param[out] nPackagesSelected How many packages were selected | ||||
* @param[out] nDescendantsUpdated Number of descendant transactions updated | * @param[out] nDescendantsUpdated Number of descendant transactions updated | ||||
*/ | */ | ||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, | void BlockAssembler::addPackageTxs(int &nPackagesSelected, | ||||
int &nDescendantsUpdated) { | int &nDescendantsUpdated, | ||||
bool fLimitSigOpCount) { | |||||
// selection algorithm orders the mempool based on feerate of a | // selection algorithm orders the mempool based on feerate of a | ||||
// transaction including all unconfirmed ancestors. Since we don't remove | // transaction including all unconfirmed ancestors. Since we don't remove | ||||
// transactions from the mempool as we select them for block inclusion, we | // transactions from the mempool as we select them for block inclusion, we | ||||
// need an alternate method of updating the feerate of a transaction with | // need an alternate method of updating the feerate of a transaction with | ||||
// its not-yet-selected ancestors as we go. This is accomplished by | // its not-yet-selected ancestors as we go. This is accomplished by | ||||
// walking the in-mempool descendants of selected transactions and storing | // walking the in-mempool descendants of selected transactions and storing | ||||
// a temporary modified state in mapModifiedTxs. Each time through the | // a temporary modified state in mapModifiedTxs. Each time through the | ||||
// loop, we compare the best transaction in mapModifiedTxs with the next | // loop, we compare the best transaction in mapModifiedTxs with the next | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | while (mi != mempool->mapTx.get<ancestor_score>().end() || | ||||
failedTx.insert(iter); | failedTx.insert(iter); | ||||
} | } | ||||
continue; | continue; | ||||
} | } | ||||
// The following must not use virtual size since TestPackage relies on | // The following must not use virtual size since TestPackage relies on | ||||
// having an accurate call to | // having an accurate call to | ||||
// GetMaxBlockSigOpsCount(blockSizeWithPackage). | // GetMaxBlockSigOpsCount(blockSizeWithPackage). | ||||
if (!TestPackage(packageSize, packageSigOps)) { | if (!TestPackage(packageSize, packageSigOps, fLimitSigOpCount)) { | ||||
if (fUsingModified) { | if (fUsingModified) { | ||||
// Since we always look at the best entry in mapModifiedTx, we | // Since we always look at the best entry in mapModifiedTx, we | ||||
// must erase failed entries so that we can consider the next | // must erase failed entries so that we can consider the next | ||||
// best entry on the next loop iteration | // best entry on the next loop iteration | ||||
mapModifiedTx.get<ancestor_score>().erase(modit); | mapModifiedTx.get<ancestor_score>().erase(modit); | ||||
failedTx.insert(iter); | failedTx.insert(iter); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |
Passing a bool al over the place is messy and not really good. IMO you are better off creating a member function that return either GetMaxBlockSigOpsCount or the sigcheck limit depending on activation state.