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:
0iff --git a/src/net_processing.cpp b/src/net_processing.cpp
1index 80655c61e7..636b4d1102 100644
2--- a/src/net_processing.cpp
3+++ b/src/net_processing.cpp
4@@ -2288,7 +2288,6 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
5 break;
6 }
7 }
8- m_mempool.check(m_chainman.ActiveChainstate());
9 }
10
11 bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
12@@ -3250,7 +3249,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
13 const TxValidationState& state = result.m_state;
14
15 if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
16- m_mempool.check(m_chainman.ActiveChainstate());
17 // As this version of the transaction was acceptable, we can forget about any
18 // requests for it.
19 m_txrequest.ForgetTxHash(tx.GetHash());
20diff --git a/src/validation.cpp b/src/validation.cpp
21index 2a66d96f22..8f1f33782b 100644
22--- a/src/validation.cpp
23+++ b/src/validation.cpp
24@@ -1041,7 +1041,9 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
25 MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
26 bool bypass_limits, bool test_accept)
27 {
28- return AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept);
29+ auto ret = AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept);
30+ pool.check(active_chainstate);
31+ return ret;
32 }
33
34 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?