@@ -327,6 +327,11 @@ struct Peer {
327327 LOCK (m_tx_relay_mutex);
328328 return m_can_tx_relay ? m_tx_relay.get () : nullptr ;
329329 };
330+ const TxRelay* GetTxRelay () const LOCKS_EXCLUDED(m_tx_relay_mutex)
331+ {
332+ LOCK (m_tx_relay_mutex);
333+ return m_can_tx_relay ? m_tx_relay.get () : nullptr ;
334+ };
330335
331336 /* * A vector of addresses to send to the peer, limited to MAX_ADDR_TO_SEND. */
332337 std::vector<CAddress> m_addrs_to_send GUARDED_BY (NetEventsInterface::g_msgproc_mutex);
@@ -398,7 +403,7 @@ struct Peer {
398403 {}
399404
400405private:
401- Mutex m_tx_relay_mutex;
406+ mutable Mutex m_tx_relay_mutex;
402407
403408 /* * Transaction relay data.
404409 * (Bitcoin) Transaction relay data. May be a nullptr.
@@ -637,7 +642,7 @@ class PeerManagerImpl final : public PeerManager
637642 /* *
638643 * Private implementation of IsInvInFilter which does not call GetPeerRef; to be prefered when the PeerRef is available.
639644 */
640- bool IsInvInFilter (const PeerRef & peer, const uint256& hash) const ;
645+ bool IsInvInFilter (const Peer & peer, const uint256& hash) const ;
641646
642647 /* * Get a shared pointer to the Peer object.
643648 * May return an empty shared_ptr if the Peer object can't be found. */
@@ -2259,7 +2264,7 @@ void PeerManagerImpl::AskPeersForTransaction(const uint256& txid, bool is_master
22592264 if (peersToAsk.size () >= 4 ) {
22602265 break ;
22612266 }
2262- if (IsInvInFilter (peer, txid)) {
2267+ if (IsInvInFilter (* peer, txid)) {
22632268 peersToAsk.emplace_back (peer);
22642269 }
22652270 }
@@ -2280,14 +2285,14 @@ void PeerManagerImpl::AskPeersForTransaction(const uint256& txid, bool is_master
22802285bool PeerManagerImpl::IsInvInFilter (NodeId nodeid, const uint256& hash) const
22812286{
22822287 PeerRef peer = GetPeerRef (nodeid);
2283- return IsInvInFilter (peer, hash);
2288+ if (peer == nullptr )
2289+ return false ;
2290+ return IsInvInFilter (*peer, hash);
22842291}
22852292
2286- bool PeerManagerImpl::IsInvInFilter (const PeerRef & peer, const uint256& hash) const
2293+ bool PeerManagerImpl::IsInvInFilter (const Peer & peer, const uint256& hash) const
22872294{
2288- if (peer == nullptr )
2289- return false ;
2290- if (auto tx_relay = peer->GetTxRelay (); tx_relay != nullptr ) {
2295+ if (auto tx_relay = peer.GetTxRelay (); tx_relay != nullptr ) {
22912296 LOCK (tx_relay->m_tx_inventory_mutex );
22922297 return tx_relay->m_tx_inventory_known_filter .contains (hash);
22932298 }
0 commit comments