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