Branch data Line data Source code
# 1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
# 2 : : // Copyright (c) 2009-2021 The Bitcoin Core developers
# 3 : : // Distributed under the MIT software license, see the accompanying
# 4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
# 5 : :
# 6 : : #include <node/miner.h>
# 7 : :
# 8 : : #include <chain.h>
# 9 : : #include <chainparams.h>
# 10 : : #include <coins.h>
# 11 : : #include <consensus/amount.h>
# 12 : : #include <consensus/consensus.h>
# 13 : : #include <consensus/merkle.h>
# 14 : : #include <consensus/tx_verify.h>
# 15 : : #include <consensus/validation.h>
# 16 : : #include <deploymentstatus.h>
# 17 : : #include <policy/feerate.h>
# 18 : : #include <policy/policy.h>
# 19 : : #include <pow.h>
# 20 : : #include <primitives/transaction.h>
# 21 : : #include <timedata.h>
# 22 : : #include <util/moneystr.h>
# 23 : : #include <util/system.h>
# 24 : : #include <validation.h>
# 25 : :
# 26 : : #include <algorithm>
# 27 : : #include <utility>
# 28 : :
# 29 : : namespace node {
# 30 : : int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
# 31 : 28291 : {
# 32 : 28291 : int64_t nOldTime = pblock->nTime;
# 33 : 28291 : int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
# 34 : :
# 35 [ + + ]: 28291 : if (nOldTime < nNewTime) {
# 36 : 19940 : pblock->nTime = nNewTime;
# 37 : 19940 : }
# 38 : :
# 39 : : // Updating time can change work required on testnet:
# 40 [ + + ]: 28291 : if (consensusParams.fPowAllowMinDifficultyBlocks) {
# 41 : 28248 : pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
# 42 : 28248 : }
# 43 : :
# 44 : 28291 : return nNewTime - nOldTime;
# 45 : 28291 : }
# 46 : :
# 47 : : void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
# 48 : 5745 : {
# 49 : 5745 : CMutableTransaction tx{*block.vtx.at(0)};
# 50 : 5745 : tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
# 51 : 5745 : block.vtx.at(0) = MakeTransactionRef(tx);
# 52 : :
# 53 : 5745 : const CBlockIndex* prev_block = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
# 54 : 5745 : GenerateCoinbaseCommitment(block, prev_block, Params().GetConsensus());
# 55 : :
# 56 : 5745 : block.hashMerkleRoot = BlockMerkleRoot(block);
# 57 : 5745 : }
# 58 : :
# 59 : : BlockAssembler::Options::Options()
# 60 : 28236 : {
# 61 : 28236 : blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
# 62 : 28236 : nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
# 63 : 28236 : }
# 64 : :
# 65 : : BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params, const Options& options)
# 66 : : : chainparams(params),
# 67 : : m_mempool(mempool),
# 68 : : m_chainstate(chainstate)
# 69 : 28236 : {
# 70 : 28236 : blockMinFeeRate = options.blockMinFeeRate;
# 71 : : // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
# 72 : 28236 : nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight));
# 73 : 28236 : }
# 74 : :
# 75 : : static BlockAssembler::Options DefaultOptions()
# 76 : 28198 : {
# 77 : : // Block resource limits
# 78 : : // If -blockmaxweight is not given, limit to DEFAULT_BLOCK_MAX_WEIGHT
# 79 : 28198 : BlockAssembler::Options options;
# 80 : 28198 : options.nBlockMaxWeight = gArgs.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
# 81 [ - + ]: 28198 : if (gArgs.IsArgSet("-blockmintxfee")) {
# 82 : 0 : std::optional<CAmount> parsed = ParseMoney(gArgs.GetArg("-blockmintxfee", ""));
# 83 : 0 : options.blockMinFeeRate = CFeeRate{parsed.value_or(DEFAULT_BLOCK_MIN_TX_FEE)};
# 84 : 28198 : } else {
# 85 : 28198 : options.blockMinFeeRate = CFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
# 86 : 28198 : }
# 87 : 28198 : return options;
# 88 : 28198 : }
# 89 : :
# 90 : : BlockAssembler::BlockAssembler(CChainState& chainstate, const CTxMemPool& mempool, const CChainParams& params)
# 91 : 28198 : : BlockAssembler(chainstate, mempool, params, DefaultOptions()) {}
# 92 : :
# 93 : : void BlockAssembler::resetBlock()
# 94 : 28236 : {
# 95 : 28236 : inBlock.clear();
# 96 : :
# 97 : : // Reserve space for coinbase tx
# 98 : 28236 : nBlockWeight = 4000;
# 99 : 28236 : nBlockSigOpsCost = 400;
# 100 : :
# 101 : : // These counters do not include coinbase tx
# 102 : 28236 : nBlockTx = 0;
# 103 : 28236 : nFees = 0;
# 104 : 28236 : }
# 105 : :
# 106 : : std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
# 107 : 28236 : {
# 108 : 28236 : int64_t nTimeStart = GetTimeMicros();
# 109 : :
# 110 : 28236 : resetBlock();
# 111 : :
# 112 : 28236 : pblocktemplate.reset(new CBlockTemplate());
# 113 : :
# 114 [ - + ]: 28236 : if (!pblocktemplate.get()) {
# 115 : 0 : return nullptr;
# 116 : 0 : }
# 117 : 28236 : CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
# 118 : :
# 119 : : // Add dummy coinbase tx as first transaction
# 120 : 28236 : pblock->vtx.emplace_back();
# 121 : 28236 : pblocktemplate->vTxFees.push_back(-1); // updated at end
# 122 : 28236 : pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
# 123 : :
# 124 : 28236 : LOCK2(cs_main, m_mempool.cs);
# 125 : 28236 : CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip();
# 126 : 28236 : assert(pindexPrev != nullptr);
# 127 : 0 : nHeight = pindexPrev->nHeight + 1;
# 128 : :
# 129 : 28236 : pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
# 130 : : // -regtest only: allow overriding block.nVersion with
# 131 : : // -blockversion=N to test forking scenarios
# 132 [ + + ]: 28236 : if (chainparams.MineBlocksOnDemand()) {
# 133 : 28195 : pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
# 134 : 28195 : }
# 135 : :
# 136 : 28236 : pblock->nTime = GetAdjustedTime();
# 137 : 28236 : m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
# 138 : :
# 139 : 28236 : int nPackagesSelected = 0;
# 140 : 28236 : int nDescendantsUpdated = 0;
# 141 : 28236 : addPackageTxs(nPackagesSelected, nDescendantsUpdated);
# 142 : :
# 143 : 28236 : int64_t nTime1 = GetTimeMicros();
# 144 : :
# 145 : 28236 : m_last_block_num_txs = nBlockTx;
# 146 : 28236 : m_last_block_weight = nBlockWeight;
# 147 : :
# 148 : : // Create coinbase transaction.
# 149 : 28236 : CMutableTransaction coinbaseTx;
# 150 : 28236 : coinbaseTx.vin.resize(1);
# 151 : 28236 : coinbaseTx.vin[0].prevout.SetNull();
# 152 : 28236 : coinbaseTx.vout.resize(1);
# 153 : 28236 : coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
# 154 : 28236 : coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
# 155 : 28236 : coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
# 156 : 28236 : pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
# 157 : 28236 : pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
# 158 : 28236 : pblocktemplate->vTxFees[0] = -nFees;
# 159 : :
# 160 : 28236 : LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops %d\n", GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost);
# 161 : :
# 162 : : // Fill in header
# 163 : 28236 : pblock->hashPrevBlock = pindexPrev->GetBlockHash();
# 164 : 28236 : UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
# 165 : 28236 : pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
# 166 : 28236 : pblock->nNonce = 0;
# 167 : 28236 : pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
# 168 : :
# 169 : 28236 : BlockValidationState state;
# 170 [ + + ]: 28236 : if (!TestBlockValidity(state, chainparams, m_chainstate, *pblock, pindexPrev, false, false)) {
# 171 : 10 : throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
# 172 : 10 : }
# 173 : 28226 : int64_t nTime2 = GetTimeMicros();
# 174 : :
# 175 [ + - ]: 28226 : LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
# 176 : :
# 177 : 28226 : return std::move(pblocktemplate);
# 178 : 28236 : }
# 179 : :
# 180 : : void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
# 181 : 7533 : {
# 182 [ + + ]: 28061 : for (CTxMemPool::setEntries::iterator iit = testSet.begin(); iit != testSet.end(); ) {
# 183 : : // Only test txs not already in the block
# 184 [ + + ]: 20528 : if (inBlock.count(*iit)) {
# 185 : 15724 : testSet.erase(iit++);
# 186 : 15724 : } else {
# 187 : 4804 : iit++;
# 188 : 4804 : }
# 189 : 20528 : }
# 190 : 7533 : }
# 191 : :
# 192 : : bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
# 193 : 39587 : {
# 194 : : // TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
# 195 [ + + ]: 39587 : if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
# 196 : 32026 : return false;
# 197 : 32026 : }
# 198 [ + + ]: 7561 : if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
# 199 : 28 : return false;
# 200 : 28 : }
# 201 : 7533 : return true;
# 202 : 7561 : }
# 203 : :
# 204 : : // Perform transaction-level checks before adding to block:
# 205 : : // - transaction finality (locktime)
# 206 : : bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
# 207 : 7533 : {
# 208 [ + + ]: 12337 : for (CTxMemPool::txiter it : package) {
# 209 [ + + ]: 12337 : if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
# 210 : 4 : return false;
# 211 : 4 : }
# 212 : 12337 : }
# 213 : 7529 : return true;
# 214 : 7533 : }
# 215 : :
# 216 : : void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
# 217 : 12333 : {
# 218 : 12333 : pblocktemplate->block.vtx.emplace_back(iter->GetSharedTx());
# 219 : 12333 : pblocktemplate->vTxFees.push_back(iter->GetFee());
# 220 : 12333 : pblocktemplate->vTxSigOpsCost.push_back(iter->GetSigOpCost());
# 221 : 12333 : nBlockWeight += iter->GetTxWeight();
# 222 : 12333 : ++nBlockTx;
# 223 : 12333 : nBlockSigOpsCost += iter->GetSigOpCost();
# 224 : 12333 : nFees += iter->GetFee();
# 225 : 12333 : inBlock.insert(iter);
# 226 : :
# 227 : 12333 : bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
# 228 [ + + ]: 12333 : if (fPrintPriority) {
# 229 : 128 : LogPrintf("fee rate %s txid %s\n",
# 230 : 128 : CFeeRate(iter->GetModifiedFee(), iter->GetTxSize()).ToString(),
# 231 : 128 : iter->GetTx().GetHash().ToString());
# 232 : 128 : }
# 233 : 12333 : }
# 234 : :
# 235 : : int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded,
# 236 : : indexed_modified_transaction_set &mapModifiedTx)
# 237 : 35765 : {
# 238 : 35765 : AssertLockHeld(m_mempool.cs);
# 239 : :
# 240 : 35765 : int nDescendantsUpdated = 0;
# 241 [ + + ]: 35765 : for (CTxMemPool::txiter it : alreadyAdded) {
# 242 : 12333 : CTxMemPool::setEntries descendants;
# 243 : 12333 : m_mempool.CalculateDescendants(it, descendants);
# 244 : : // Insert all descendants (not yet in block) into the modified set
# 245 [ + + ]: 2037827 : for (CTxMemPool::txiter desc : descendants) {
# 246 [ + + ]: 2037827 : if (alreadyAdded.count(desc)) {
# 247 : 1537110 : continue;
# 248 : 1537110 : }
# 249 : 500717 : ++nDescendantsUpdated;
# 250 : 500717 : modtxiter mit = mapModifiedTx.find(desc);
# 251 [ + + ]: 500717 : if (mit == mapModifiedTx.end()) {
# 252 : 2899 : CTxMemPoolModifiedEntry modEntry(desc);
# 253 : 2899 : modEntry.nSizeWithAncestors -= it->GetTxSize();
# 254 : 2899 : modEntry.nModFeesWithAncestors -= it->GetModifiedFee();
# 255 : 2899 : modEntry.nSigOpCostWithAncestors -= it->GetSigOpCost();
# 256 : 2899 : mapModifiedTx.insert(modEntry);
# 257 : 497818 : } else {
# 258 : 497818 : mapModifiedTx.modify(mit, update_for_parent_inclusion(it));
# 259 : 497818 : }
# 260 : 500717 : }
# 261 : 12333 : }
# 262 : 35765 : return nDescendantsUpdated;
# 263 : 35765 : }
# 264 : :
# 265 : : // Skip entries in mapTx that are already in a block or are present
# 266 : : // in mapModifiedTx (which implies that the mapTx ancestor state is
# 267 : : // stale due to ancestor inclusion in the block)
# 268 : : // Also skip transactions that we've already failed to add. This can happen if
# 269 : : // we consider a transaction in mapModifiedTx and it fails: we can then
# 270 : : // potentially consider it again while walking mapTx. It's currently
# 271 : : // guaranteed to fail again, but as a belt-and-suspenders check we put it in
# 272 : : // failedTx and avoid re-evaluation, since the re-evaluation would be using
# 273 : : // cached size/sigops/fee values that are not actually correct.
# 274 : : bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
# 275 : 44973 : {
# 276 : 44973 : AssertLockHeld(m_mempool.cs);
# 277 : :
# 278 : 44973 : assert(it != m_mempool.mapTx.end());
# 279 [ + + ][ + + ]: 44973 : return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
# [ - + ]
# 280 : 44973 : }
# 281 : :
# 282 : : void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries)
# 283 : 7529 : {
# 284 : : // Sort package by ancestor count
# 285 : : // If a transaction A depends on transaction B, then A's ancestor count
# 286 : : // must be greater than B's. So this is sufficient to validly order the
# 287 : : // transactions for block inclusion.
# 288 : 7529 : sortedEntries.clear();
# 289 : 7529 : sortedEntries.insert(sortedEntries.begin(), package.begin(), package.end());
# 290 : 7529 : std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByAncestorCount());
# 291 : 7529 : }
# 292 : :
# 293 : : // This transaction selection algorithm orders the mempool based
# 294 : : // on feerate of a transaction including all unconfirmed ancestors.
# 295 : : // Since we don't remove transactions from the mempool as we select them
# 296 : : // for block inclusion, we need an alternate method of updating the feerate
# 297 : : // of a transaction with its not-yet-selected ancestors as we go.
# 298 : : // This is accomplished by walking the in-mempool descendants of selected
# 299 : : // transactions and storing a temporary modified state in mapModifiedTxs.
# 300 : : // Each time through the loop, we compare the best transaction in
# 301 : : // mapModifiedTxs with the next transaction in the mempool to decide what
# 302 : : // transaction package to work on next.
# 303 : : void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
# 304 : 28236 : {
# 305 : 28236 : AssertLockHeld(m_mempool.cs);
# 306 : :
# 307 : : // mapModifiedTx will store sorted packages after they are modified
# 308 : : // because some of their txs are already in the block
# 309 : 28236 : indexed_modified_transaction_set mapModifiedTx;
# 310 : : // Keep track of entries that failed inclusion, to avoid duplicate work
# 311 : 28236 : CTxMemPool::setEntries failedTx;
# 312 : :
# 313 : : // Start by adding all descendants of previously added txs to mapModifiedTx
# 314 : : // and modifying them for their already included ancestors
# 315 : 28236 : UpdatePackagesForAdded(inBlock, mapModifiedTx);
# 316 : :
# 317 : 28236 : CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = m_mempool.mapTx.get<ancestor_score>().begin();
# 318 : 28236 : CTxMemPool::txiter iter;
# 319 : :
# 320 : : // Limit the number of attempts to add transactions to the block when it is
# 321 : : // close to full; this is just a simple heuristic to finish quickly if the
# 322 : : // mempool has a lot of entries.
# 323 : 28236 : const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
# 324 : 28236 : int64_t nConsecutiveFailed = 0;
# 325 : :
# 326 [ + + ][ + + ]: 73524 : while (mi != m_mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty()) {
# [ + + ]
# 327 : : // First try to find a new transaction in mapTx to evaluate.
# 328 [ + + ][ + + ]: 45313 : if (mi != m_mempool.mapTx.get<ancestor_score>().end() &&
# 329 [ + + ]: 45313 : SkipMapTxEntry(m_mempool.mapTx.project<0>(mi), mapModifiedTx, failedTx)) {
# 330 : 5706 : ++mi;
# 331 : 5706 : continue;
# 332 : 5706 : }
# 333 : :
# 334 : : // Now that mi is not stale, determine which transaction to evaluate:
# 335 : : // the next entry from mapTx, or the best from mapModifiedTx?
# 336 : 39607 : bool fUsingModified = false;
# 337 : :
# 338 : 39607 : modtxscoreiter modit = mapModifiedTx.get<ancestor_score>().begin();
# 339 [ + + ]: 39607 : if (mi == m_mempool.mapTx.get<ancestor_score>().end()) {
# 340 : : // We're out of entries in mapTx; use the entry from mapModifiedTx
# 341 : 340 : iter = modit->iter;
# 342 : 340 : fUsingModified = true;
# 343 : 39267 : } else {
# 344 : : // Try to compare the mapTx entry to the mapModifiedTx entry
# 345 : 39267 : iter = m_mempool.mapTx.project<0>(mi);
# 346 [ + + ][ + + ]: 39267 : if (modit != mapModifiedTx.get<ancestor_score>().end() &&
# 347 [ + + ]: 39267 : CompareTxMemPoolEntryByAncestorFee()(*modit, CTxMemPoolModifiedEntry(iter))) {
# 348 : : // The best entry in mapModifiedTx has higher score
# 349 : : // than the one from mapTx.
# 350 : : // Switch which transaction (package) to consider
# 351 : 640 : iter = modit->iter;
# 352 : 640 : fUsingModified = true;
# 353 : 38627 : } else {
# 354 : : // Either no entry in mapModifiedTx, or it's worse than mapTx.
# 355 : : // Increment mi for the next loop iteration.
# 356 : 38627 : ++mi;
# 357 : 38627 : }
# 358 : 39267 : }
# 359 : :
# 360 : : // We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
# 361 : : // contain anything that is inBlock.
# 362 : 39607 : assert(!inBlock.count(iter));
# 363 : :
# 364 : 0 : uint64_t packageSize = iter->GetSizeWithAncestors();
# 365 : 39607 : CAmount packageFees = iter->GetModFeesWithAncestors();
# 366 : 39607 : int64_t packageSigOpsCost = iter->GetSigOpCostWithAncestors();
# 367 [ + + ]: 39607 : if (fUsingModified) {
# 368 : 980 : packageSize = modit->nSizeWithAncestors;
# 369 : 980 : packageFees = modit->nModFeesWithAncestors;
# 370 : 980 : packageSigOpsCost = modit->nSigOpCostWithAncestors;
# 371 : 980 : }
# 372 : :
# 373 [ + + ]: 39607 : if (packageFees < blockMinFeeRate.GetFee(packageSize)) {
# 374 : : // Everything else we might consider has a lower fee rate
# 375 : 20 : return;
# 376 : 20 : }
# 377 : :
# 378 [ + + ]: 39587 : if (!TestPackage(packageSize, packageSigOpsCost)) {
# 379 [ + + ]: 32054 : if (fUsingModified) {
# 380 : : // Since we always look at the best entry in mapModifiedTx,
# 381 : : // we must erase failed entries so that we can consider the
# 382 : : // next best entry on the next loop iteration
# 383 : 132 : mapModifiedTx.get<ancestor_score>().erase(modit);
# 384 : 132 : failedTx.insert(iter);
# 385 : 132 : }
# 386 : :
# 387 : 32054 : ++nConsecutiveFailed;
# 388 : :
# 389 [ + + ][ + - ]: 32054 : if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
# 390 : 5 : nBlockMaxWeight - 4000) {
# 391 : : // Give up if we're close to full and haven't succeeded in a while
# 392 : 5 : break;
# 393 : 5 : }
# 394 : 32049 : continue;
# 395 : 32054 : }
# 396 : :
# 397 : 7533 : CTxMemPool::setEntries ancestors;
# 398 : 7533 : uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
# 399 : 7533 : std::string dummy;
# 400 : 7533 : m_mempool.CalculateMemPoolAncestors(*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
# 401 : :
# 402 : 7533 : onlyUnconfirmed(ancestors);
# 403 : 7533 : ancestors.insert(iter);
# 404 : :
# 405 : : // Test if all tx's are Final
# 406 [ + + ]: 7533 : if (!TestPackageTransactions(ancestors)) {
# 407 [ - + ]: 4 : if (fUsingModified) {
# 408 : 0 : mapModifiedTx.get<ancestor_score>().erase(modit);
# 409 : 0 : failedTx.insert(iter);
# 410 : 0 : }
# 411 : 4 : continue;
# 412 : 4 : }
# 413 : :
# 414 : : // This transaction will make it in; reset the failed counter.
# 415 : 7529 : nConsecutiveFailed = 0;
# 416 : :
# 417 : : // Package can be added. Sort the entries in a valid order.
# 418 : 7529 : std::vector<CTxMemPool::txiter> sortedEntries;
# 419 : 7529 : SortForBlock(ancestors, sortedEntries);
# 420 : :
# 421 [ + + ]: 19862 : for (size_t i = 0; i < sortedEntries.size(); ++i) {
# 422 : 12333 : AddToBlock(sortedEntries[i]);
# 423 : : // Erase from the modified set, if present
# 424 : 12333 : mapModifiedTx.erase(sortedEntries[i]);
# 425 : 12333 : }
# 426 : :
# 427 : 7529 : ++nPackagesSelected;
# 428 : :
# 429 : : // Update transactions that depend on each of these
# 430 : 7529 : nDescendantsUpdated += UpdatePackagesForAdded(ancestors, mapModifiedTx);
# 431 : 7529 : }
# 432 : 28236 : }
# 433 : : } // namespace node
|