Skip to content

Commit c85ee76

Browse files
committed
[net processin] Don't take cs_main in FindTxForGetData
Taking cs_main is no longer necessary since we moved `m_recently_announced_invs` to `Peer` and `mapRelay` is actually only accessed from the message processing thread.
1 parent 6b9fedd commit c85ee76

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/net_processing.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ class PeerManagerImpl final : public PeerManager
909909

910910
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
911911
CTransactionRef FindTxForGetData(const Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now)
912-
LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
912+
EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);
913913

914914
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
915915
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex, NetEventsInterface::g_msgproc_mutex)
@@ -920,9 +920,9 @@ class PeerManagerImpl final : public PeerManager
920920

921921
/** Relay map (txid or wtxid -> CTransactionRef) */
922922
typedef std::map<uint256, CTransactionRef> MapRelay;
923-
MapRelay mapRelay GUARDED_BY(cs_main);
923+
MapRelay mapRelay GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
924924
/** Expiration-time ordered list of (expire time, relay map entry) pairs. */
925-
std::deque<std::pair<std::chrono::microseconds, MapRelay::iterator>> g_relay_expiration GUARDED_BY(cs_main);
925+
std::deque<std::pair<std::chrono::microseconds, MapRelay::iterator>> g_relay_expiration GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
926926

927927
/**
928928
* When a peer sends us a valid block, instruct it to announce blocks to us
@@ -2270,16 +2270,13 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const GenTxi
22702270
}
22712271
}
22722272

2273-
{
2274-
LOCK(cs_main);
2275-
// Otherwise, the transaction must have been announced recently.
2276-
if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(gtxid.GetHash())) {
2277-
// If it was, it can be relayed from either the mempool...
2278-
if (txinfo.tx) return std::move(txinfo.tx);
2279-
// ... or the relay pool.
2280-
auto mi = mapRelay.find(gtxid.GetHash());
2281-
if (mi != mapRelay.end()) return mi->second;
2282-
}
2273+
// Otherwise, the transaction must have been announced recently.
2274+
if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(gtxid.GetHash())) {
2275+
// If it was, it can be relayed from either the mempool...
2276+
if (txinfo.tx) return std::move(txinfo.tx);
2277+
// ... or the relay pool.
2278+
auto mi = mapRelay.find(gtxid.GetHash());
2279+
if (mi != mapRelay.end()) return mi->second;
22832280
}
22842281

22852282
return {};

0 commit comments

Comments
 (0)