@@ -62,7 +62,7 @@ BlockAssembler::Options::Options()
62
62
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
63
63
}
64
64
65
- BlockAssembler::BlockAssembler (CChainState& chainstate, const CTxMemPool& mempool, const Options& options)
65
+ BlockAssembler::BlockAssembler (CChainState& chainstate, const CTxMemPool* mempool, const Options& options)
66
66
: chainparams{chainstate.m_chainman .GetParams ()},
67
67
m_mempool (mempool),
68
68
m_chainstate (chainstate)
@@ -87,7 +87,7 @@ static BlockAssembler::Options DefaultOptions()
87
87
return options;
88
88
}
89
89
90
- BlockAssembler::BlockAssembler (CChainState& chainstate, const CTxMemPool& mempool)
90
+ BlockAssembler::BlockAssembler (CChainState& chainstate, const CTxMemPool* mempool)
91
91
: BlockAssembler(chainstate, mempool, DefaultOptions()) {}
92
92
93
93
void BlockAssembler::resetBlock ()
@@ -121,7 +121,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
121
121
pblocktemplate->vTxFees .push_back (-1 ); // updated at end
122
122
pblocktemplate->vTxSigOpsCost .push_back (-1 ); // updated at end
123
123
124
- LOCK2 ( cs_main, m_mempool. cs );
124
+ LOCK (:: cs_main);
125
125
CBlockIndex* pindexPrev = m_chainstate.m_chain .Tip ();
126
126
assert (pindexPrev != nullptr );
127
127
nHeight = pindexPrev->nHeight + 1 ;
@@ -138,7 +138,10 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
138
138
139
139
int nPackagesSelected = 0 ;
140
140
int nDescendantsUpdated = 0 ;
141
- addPackageTxs (nPackagesSelected, nDescendantsUpdated);
141
+ if (m_mempool) {
142
+ LOCK (m_mempool->cs );
143
+ addPackageTxs (*m_mempool, nPackagesSelected, nDescendantsUpdated);
144
+ }
142
145
143
146
int64_t nTime1 = GetTimeMicros ();
144
147
@@ -287,17 +290,17 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
287
290
// Each time through the loop, we compare the best transaction in
288
291
// mapModifiedTxs with the next transaction in the mempool to decide what
289
292
// transaction package to work on next.
290
- void BlockAssembler::addPackageTxs (int & nPackagesSelected, int & nDescendantsUpdated)
293
+ void BlockAssembler::addPackageTxs (const CTxMemPool& mempool, int & nPackagesSelected, int & nDescendantsUpdated)
291
294
{
292
- AssertLockHeld (m_mempool .cs );
295
+ AssertLockHeld (mempool .cs );
293
296
294
297
// mapModifiedTx will store sorted packages after they are modified
295
298
// because some of their txs are already in the block
296
299
indexed_modified_transaction_set mapModifiedTx;
297
300
// Keep track of entries that failed inclusion, to avoid duplicate work
298
301
CTxMemPool::setEntries failedTx;
299
302
300
- CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = m_mempool .mapTx .get <ancestor_score>().begin ();
303
+ CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool .mapTx .get <ancestor_score>().begin ();
301
304
CTxMemPool::txiter iter;
302
305
303
306
// Limit the number of attempts to add transactions to the block when it is
@@ -306,7 +309,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
306
309
const int64_t MAX_CONSECUTIVE_FAILURES = 1000 ;
307
310
int64_t nConsecutiveFailed = 0 ;
308
311
309
- while (mi != m_mempool .mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ()) {
312
+ while (mi != mempool .mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ()) {
310
313
// First try to find a new transaction in mapTx to evaluate.
311
314
//
312
315
// Skip entries in mapTx that are already in a block or are present
@@ -320,9 +323,9 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
320
323
// cached size/sigops/fee values that are not actually correct.
321
324
/* * Return true if given transaction from mapTx has already been evaluated,
322
325
* or if the transaction's cached data in mapTx is incorrect. */
323
- if (mi != m_mempool .mapTx .get <ancestor_score>().end ()) {
324
- auto it = m_mempool .mapTx .project <0 >(mi);
325
- assert (it != m_mempool .mapTx .end ());
326
+ if (mi != mempool .mapTx .get <ancestor_score>().end ()) {
327
+ auto it = mempool .mapTx .project <0 >(mi);
328
+ assert (it != mempool .mapTx .end ());
326
329
if (mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it)) {
327
330
++mi;
328
331
continue ;
@@ -334,13 +337,13 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
334
337
bool fUsingModified = false ;
335
338
336
339
modtxscoreiter modit = mapModifiedTx.get <ancestor_score>().begin ();
337
- if (mi == m_mempool .mapTx .get <ancestor_score>().end ()) {
340
+ if (mi == mempool .mapTx .get <ancestor_score>().end ()) {
338
341
// We're out of entries in mapTx; use the entry from mapModifiedTx
339
342
iter = modit->iter ;
340
343
fUsingModified = true ;
341
344
} else {
342
345
// Try to compare the mapTx entry to the mapModifiedTx entry
343
- iter = m_mempool .mapTx .project <0 >(mi);
346
+ iter = mempool .mapTx .project <0 >(mi);
344
347
if (modit != mapModifiedTx.get <ancestor_score>().end () &&
345
348
CompareTxMemPoolEntryByAncestorFee ()(*modit, CTxMemPoolModifiedEntry (iter))) {
346
349
// The best entry in mapModifiedTx has higher score
@@ -395,7 +398,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
395
398
CTxMemPool::setEntries ancestors;
396
399
uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
397
400
std::string dummy;
398
- m_mempool .CalculateMemPoolAncestors (*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
401
+ mempool .CalculateMemPoolAncestors (*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
399
402
400
403
onlyUnconfirmed (ancestors);
401
404
ancestors.insert (iter);
@@ -425,7 +428,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
425
428
++nPackagesSelected;
426
429
427
430
// Update transactions that depend on each of these
428
- nDescendantsUpdated += UpdatePackagesForAdded (m_mempool , ancestors, mapModifiedTx);
431
+ nDescendantsUpdated += UpdatePackagesForAdded (mempool , ancestors, mapModifiedTx);
429
432
}
430
433
}
431
434
} // namespace node
0 commit comments