From 87b3756c8c7a1ae14b90aea51d452c2d72815511 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 19 Aug 2016 11:04:16 -0500 Subject: [PATCH] server: Remove superfluous check in OnMemPool. (#736) This reduces the mempool lock contention by removing an unnecessary check when responding to a "mempool" request. In particular, the code first gets a list of all transactions from the mempool and then iterates them in order to construct the inventory vectors and apply bloom filtering if it is enabled. Since it is possible that the transaction was removed from the mempool by another thread while that list is being iterated, the code was checking if each transaction was still in the mempool. This is a pointless check because the transaction might still be removed at any point after the check anyways. For example, it might be removed after the mempool response has been sent to the remote peer or even while the loop is still iterating. --- server.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/server.go b/server.go index c23ecc00f..89487b80e 100644 --- a/server.go +++ b/server.go @@ -426,18 +426,11 @@ func (sp *serverPeer) OnMemPool(p *peer.Peer, msg *wire.MsgMemPool) { invMsg := wire.NewMsgInvSizeHint(uint(len(txDescs))) for i, txDesc := range txDescs { - // Another thread might have removed the transaction from the - // pool since the initial query. - hash := txDesc.Tx.Hash() - if !txMemPool.IsTransactionInPool(hash) { - continue - } - // Either add all transactions when there is no bloom filter, // or only the transactions that match the filter when there is // one. if !sp.filter.IsLoaded() || sp.filter.MatchTxAndUpdate(txDesc.Tx) { - iv := wire.NewInvVect(wire.InvTypeTx, hash) + iv := wire.NewInvVect(wire.InvTypeTx, txDesc.Tx.Hash()) invMsg.AddInvVect(iv) if i+1 >= wire.MaxInvPerMsg { break