diff --git a/src/node/miner.cpp b/src/node/miner.cpp index 181ae2ef05a..790ee1c1466 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -138,8 +138,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc int nPackagesSelected = 0; int nDescendantsUpdated = 0; if (m_mempool) { - LOCK(m_mempool->cs); - addPackageTxs(*m_mempool, nPackagesSelected, nDescendantsUpdated); + addPackageTxs(nPackagesSelected, nDescendantsUpdated); } const auto time_1{SteadyClock::now()}; @@ -288,9 +287,10 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve // Each time through the loop, we compare the best transaction in // mapModifiedTxs with the next transaction in the mempool to decide what // transaction package to work on next. -void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSelected, int& nDescendantsUpdated) +void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated) { - AssertLockHeld(mempool.cs); + const auto& mempool{*Assert(m_mempool)}; + LOCK(mempool.cs); // mapModifiedTx will store sorted packages after they are modified // because some of their txs are already in the block diff --git a/src/node/miner.h b/src/node/miner.h index 1b829437669..25ce110b348 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -187,8 +187,11 @@ class BlockAssembler // Methods for how to add transactions to a block. /** Add transactions based on feerate including unconfirmed ancestors * Increments nPackagesSelected / nDescendantsUpdated with corresponding - * statistics from the package selection (for logging statistics). */ - void addPackageTxs(const CTxMemPool& mempool, int& nPackagesSelected, int& nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs); + * statistics from the package selection (for logging statistics). + * + * @pre BlockAssembler::m_mempool must not be nullptr + */ + void addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(!m_mempool->cs); // helper functions for addPackageTxs() /** Remove confirmed (inBlock) entries from given set */