Merge bitcoin/bitcoin#33946: interfaces: remove redundant mempool lock in ChainImpl::isInMempool()

2909655fba fix: remove redundant mempool lock in ChainImpl::isInMempool() (Fibonacci747)

Pull request description:

  This PR removes an unnecessary `LOCK(mempool->cs)` in `ChainImpl::isInMempool()`. The method calls `CTxMemPool::exists()`, which already locks `mempool->cs` internally. Because the mempool mutex is a RecursiveMutex, double-locking was safe but redundant. Dropping the outer lock matches patterns used elsewhere in ChainImpl (e.g. `hasDescendantsInMempool()` and `GetTransactionAncestry()` callers) where mempool read APIs are invoked without an additional lock and rely on the callee’s internal locking. `isRBFOptIn()` remains unchanged since `IsRBFOptIn(tx, pool)` explicitly requires the caller to hold `pool.cs` as indicated by its thread-safety annotation.

ACKs for top commit:
  maflcko:
    lgtm ACK 2909655fba
  instagibbs:
    utACK 2909655fba
  stickies-v:
    ACK 2909655fba

Tree-SHA512: 4dfd88e01d8c7a4b6ceb3c736243fb22bfee5ccfc422d134acb633b908ca14c807637a2aa20de89e86e583b23ec70a1d121d77e35af60e114d93971b2a4bfd3b
This commit is contained in:
merge-script
2025-11-26 14:55:38 +00:00

View File

@@ -658,7 +658,6 @@ public:
bool isInMempool(const Txid& txid) override
{
if (!m_node.mempool) return false;
LOCK(m_node.mempool->cs);
return m_node.mempool->exists(txid);
}
bool hasDescendantsInMempool(const Txid& txid) override