NIT: maybe add an additional assume. the size Assume (L348) rests on "doesn't conflict with the mempool", but that premise isn't checked itself.
If a conflict did occur and the replacement was rejected, the size is unchanged and the reason can be one IsExpectedReorgRejection accepts. So a broken invariant would go unnoticed. Asserting the premise before AcceptToMemoryPool closes that, and also catches txn-already-in-mempool / txn-same-nonwitness-data-in-mempool earlier:
// A transaction from a disconnected block doesn't conflict with the mempool: the
// mempool was consistent with the old chain, in which this transaction spent its inputs.
Assume(std::ranges::none_of((*it)->vin, [&](const CTxIn& txin) EXCLUSIVE_LOCKS_REQUIRED(m_mempool->cs) {
return m_mempool->GetConflictTx(txin.prevout) != nullptr;
}));
const auto size_before{m_mempool->size()};