fuzz coverage

Coverage Report

Created: 2025-06-01 19:34

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