Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const Config &config, | ||||
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; | ||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated); | addPackageTxs(config, nPackagesSelected, nDescendantsUpdated); | ||||
if (IsMagneticAnomalyEnabled(config, pindexPrev)) { | if (IsMagneticAnomalyEnabled(config, 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. | ||||
// FIXME: Use a zipped list. See T479 | // FIXME: Use a zipped list. See T479 | ||||
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) | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Perform transaction-level checks before adding to block: | * Perform transaction-level checks before adding to block: | ||||
* - Transaction finality (locktime) | * - Transaction finality (locktime) | ||||
* - Serialized size (in case -blockmaxsize is in use) | * - Serialized size (in case -blockmaxsize is in use) | ||||
*/ | */ | ||||
bool BlockAssembler::TestPackageTransactions( | bool BlockAssembler::TestPackageTransactions( | ||||
const CTxMemPool::setEntries &package) { | const Config &config, const CTxMemPool::setEntries &package) { | ||||
uint64_t nPotentialBlockSize = nBlockSize; | uint64_t nPotentialBlockSize = nBlockSize; | ||||
for (const CTxMemPool::txiter it : package) { | for (const CTxMemPool::txiter it : package) { | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | if (!ContextualCheckTransaction(config, it->GetTx(), state, nHeight, | ||||
nLockTimeCutoff, nMedianTimePast)) { | nLockTimeCutoff, nMedianTimePast)) { | ||||
return false; | return false; | ||||
} | } | ||||
uint64_t nTxSize = | uint64_t nTxSize = | ||||
::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | ::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | ||||
if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 130 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(const Config &config, int &nPackagesSelected, | ||||
int &nDescendantsUpdated) { | int &nDescendantsUpdated) { | ||||
// 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 | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | while (mi != mempool->mapTx.get<ancestor_score>().end() || | ||||
std::string dummy; | std::string dummy; | ||||
mempool->CalculateMemPoolAncestors(*iter, ancestors, nNoLimit, nNoLimit, | mempool->CalculateMemPoolAncestors(*iter, ancestors, nNoLimit, nNoLimit, | ||||
nNoLimit, nNoLimit, dummy, false); | nNoLimit, nNoLimit, dummy, false); | ||||
onlyUnconfirmed(ancestors); | onlyUnconfirmed(ancestors); | ||||
ancestors.insert(iter); | ancestors.insert(iter); | ||||
// Test if all tx's are Final. | // Test if all tx's are Final. | ||||
if (!TestPackageTransactions(ancestors)) { | if (!TestPackageTransactions(config, ancestors)) { | ||||
if (fUsingModified) { | if (fUsingModified) { | ||||
mapModifiedTx.get<ancestor_score>().erase(modit); | mapModifiedTx.get<ancestor_score>().erase(modit); | ||||
failedTx.insert(iter); | failedTx.insert(iter); | ||||
} | } | ||||
continue; | continue; | ||||
} | } | ||||
// This transaction will make it in; reset the failed counter. | // This transaction will make it in; reset the failed counter. | ||||
▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines |