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