@@ -45,7 +45,9 @@ BlockAssembler::Options::Options() {
4545 nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
4646}
4747
48- BlockAssembler::BlockAssembler (const CChainParams& params, const Options& options) : chainparams(params)
48+ BlockAssembler::BlockAssembler (const CTxMemPool& mempool, const CChainParams& params, const Options& options)
49+ : chainparams(params),
50+ m_mempool(mempool)
4951{
5052 blockMinFeeRate = options.blockMinFeeRate ;
5153 // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
@@ -67,7 +69,8 @@ static BlockAssembler::Options DefaultOptions()
6769 return options;
6870}
6971
70- BlockAssembler::BlockAssembler (const CChainParams& params) : BlockAssembler(params, DefaultOptions()) {}
72+ BlockAssembler::BlockAssembler (const CTxMemPool& mempool, const CChainParams& params)
73+ : BlockAssembler(mempool, params, DefaultOptions()) {}
7174
7275void BlockAssembler::resetBlock ()
7376{
@@ -103,7 +106,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
103106 pblocktemplate->vTxFees .push_back (-1 ); // updated at end
104107 pblocktemplate->vTxSigOpsCost .push_back (-1 ); // updated at end
105108
106- LOCK2 (cs_main, mempool .cs );
109+ LOCK2 (cs_main, m_mempool .cs );
107110 CBlockIndex* pindexPrev = ::ChainActive ().Tip ();
108111 assert (pindexPrev != nullptr );
109112 nHeight = pindexPrev->nHeight + 1 ;
@@ -236,7 +239,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
236239 int nDescendantsUpdated = 0 ;
237240 for (CTxMemPool::txiter it : alreadyAdded) {
238241 CTxMemPool::setEntries descendants;
239- mempool .CalculateDescendants (it, descendants);
242+ m_mempool .CalculateDescendants (it, descendants);
240243 // Insert all descendants (not yet in block) into the modified set
241244 for (CTxMemPool::txiter desc : descendants) {
242245 if (alreadyAdded.count (desc))
@@ -268,7 +271,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
268271// cached size/sigops/fee values that are not actually correct.
269272bool BlockAssembler::SkipMapTxEntry (CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx)
270273{
271- assert (it != mempool .mapTx .end ());
274+ assert (it != m_mempool .mapTx .end ());
272275 return mapModifiedTx.count (it) || inBlock.count (it) || failedTx.count (it);
273276}
274277
@@ -305,7 +308,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
305308 // and modifying them for their already included ancestors
306309 UpdatePackagesForAdded (inBlock, mapModifiedTx);
307310
308- CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool .mapTx .get <ancestor_score>().begin ();
311+ CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = m_mempool .mapTx .get <ancestor_score>().begin ();
309312 CTxMemPool::txiter iter;
310313
311314 // Limit the number of attempts to add transactions to the block when it is
@@ -314,11 +317,10 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
314317 const int64_t MAX_CONSECUTIVE_FAILURES = 1000 ;
315318 int64_t nConsecutiveFailed = 0 ;
316319
317- while (mi != mempool.mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ())
318- {
320+ while (mi != m_mempool.mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ()) {
319321 // First try to find a new transaction in mapTx to evaluate.
320- if (mi != mempool .mapTx .get <ancestor_score>().end () &&
321- SkipMapTxEntry (mempool .mapTx .project <0 >(mi), mapModifiedTx, failedTx)) {
322+ if (mi != m_mempool .mapTx .get <ancestor_score>().end () &&
323+ SkipMapTxEntry (m_mempool .mapTx .project <0 >(mi), mapModifiedTx, failedTx)) {
322324 ++mi;
323325 continue ;
324326 }
@@ -328,13 +330,13 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
328330 bool fUsingModified = false ;
329331
330332 modtxscoreiter modit = mapModifiedTx.get <ancestor_score>().begin ();
331- if (mi == mempool .mapTx .get <ancestor_score>().end ()) {
333+ if (mi == m_mempool .mapTx .get <ancestor_score>().end ()) {
332334 // We're out of entries in mapTx; use the entry from mapModifiedTx
333335 iter = modit->iter ;
334336 fUsingModified = true ;
335337 } else {
336338 // Try to compare the mapTx entry to the mapModifiedTx entry
337- iter = mempool .mapTx .project <0 >(mi);
339+ iter = m_mempool .mapTx .project <0 >(mi);
338340 if (modit != mapModifiedTx.get <ancestor_score>().end () &&
339341 CompareTxMemPoolEntryByAncestorFee ()(*modit, CTxMemPoolModifiedEntry (iter))) {
340342 // The best entry in mapModifiedTx has higher score
@@ -389,7 +391,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
389391 CTxMemPool::setEntries ancestors;
390392 uint64_t nNoLimit = std::numeric_limits<uint64_t >::max ();
391393 std::string dummy;
392- mempool .CalculateMemPoolAncestors (*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
394+ m_mempool .CalculateMemPoolAncestors (*iter, ancestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false );
393395
394396 onlyUnconfirmed (ancestors);
395397 ancestors.insert (iter);
0 commit comments