It'd be nice to remove these calls to mempool.check() from net_processing. It shouldn't be the client's responsibility to call into validation/mempool to check its invariants.
The diff is really easy:
iff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 80655c61e7..636b4d1102 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2288,7 +2288,6 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
break;
}
}
- m_mempool.check(m_chainman.ActiveChainstate());
}
bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
@@ -3250,7 +3249,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
const TxValidationState& state = result.m_state;
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
- m_mempool.check(m_chainman.ActiveChainstate());
// As this version of the transaction was acceptable, we can forget about any
// requests for it.
m_txrequest.ForgetTxHash(tx.GetHash());
diff --git a/src/validation.cpp b/src/validation.cpp
index 2a66d96f22..8f1f33782b 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1041,7 +1041,9 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
bool bypass_limits, bool test_accept)
{
- return AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept);
+ auto ret = AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept);
+ pool.check(active_chainstate);
+ return ret;
}
PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTxMemPool& pool,
branch here: https://github.com/jnewbery/bitcoin/tree/2021-09-no-mempool-check-in-net-processing
That's a slight behaviour change since check() will get called a little more often, so it doesn't fit inside this PR, but by doing it first, this PR wouldn't need to touch net_processing. Thoughts?