I feel a bit uneasy about adding this no-op, it makes understanding the program flow more difficult and I feel like it is a potential footgun. What do you think about asserting the mempool is configured instead?
<details>
<summary>git diff on 60a0f2ac88</summary>
diff --git a/src/node/miner.cpp b/src/node/miner.cpp
index 9e6954d257..afa410da10 100644
--- a/src/node/miner.cpp
+++ b/src/node/miner.cpp
@@ -141,7 +141,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
int nPackagesSelected = 0;
int nDescendantsUpdated = 0;
- addPackageTxs(nPackagesSelected, nDescendantsUpdated);
+ if (m_mempool) {
+ addPackageTxs(nPackagesSelected, nDescendantsUpdated);
+ }
const auto time_1{SteadyClock::now()};
@@ -291,9 +293,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
// transaction package to work on next.
void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
{
- if (m_mempool == nullptr) return;
-
- const auto& mempool{*m_mempool};
+ const auto& mempool{*Assert(m_mempool)};
LOCK(mempool.cs);
// mapModifiedTx will store sorted packages after they are modified
diff --git a/src/node/miner.h b/src/node/miner.h
index a262fb7dc5..25ce110b34 100644
--- a/src/node/miner.h
+++ b/src/node/miner.h
@@ -188,7 +188,9 @@ private:
/** Add transactions based on feerate including unconfirmed ancestors
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
* statistics from the package selection (for logging statistics).
- * No-op if the BlockAssembler has been configured without a mempool.*/
+ *
+ * [@pre](/bitcoin-bitcoin/contributor/pre/) BlockAssembler::m_mempool must not be nullptr
+ */
void addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(!m_mempool->cs);
// helper functions for addPackageTxs()
</details>