From 77526d2129e5ecce3e9870b77db9034c0a6644db Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:05:52 +0000 Subject: [PATCH] net: rename `Peer::m_block_relay_only` to `Peer::m_can_tx_relay` The true purpose of `m_block_relay_only` is to use it in place of `m_tx_relay == nullptr`, used to indicate if the node is permitted to relay transactions. In upcoming commits, being a block-relay-only node will not be the only reason to not relay transactions, so let's rename the variable to what we actually use it for. --- src/net_processing.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index b82a79e807..f024b286d4 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -336,8 +336,8 @@ struct Peer { * This field must correlate with whether m_addr_known has been * initialized.*/ std::atomic_bool m_addr_relay_enabled{false}; - /** Whether a Peer can only be relayed blocks */ - const bool m_block_relay_only{false}; + /** Whether a peer can relay transactions */ + const bool m_can_tx_relay{false}; /** Whether a getaddr request to this peer is outstanding. */ bool m_getaddr_sent GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false}; /** Guards address sending timers. */ @@ -375,11 +375,11 @@ struct Peer { /** Time of the last getheaders message to this peer */ std::atomic m_last_getheaders_timestamp GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0s}; - explicit Peer(NodeId id, ServiceFlags our_services, bool block_relay_only) + explicit Peer(NodeId id, ServiceFlags our_services, bool tx_relay) : m_id(id) , m_our_services{our_services} , m_tx_relay(std::make_unique()) - , m_block_relay_only{block_relay_only} + , m_can_tx_relay{tx_relay} {} }; @@ -1552,7 +1552,7 @@ void PeerManagerImpl::InitializeNode(CNode& node, ServiceFlags our_services) { LOCK(cs_main); m_node_states.emplace_hint(m_node_states.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(node.IsInboundConn())); } - PeerRef peer = std::make_shared(nodeid, our_services, /* block_relay_only = */ node.IsBlockOnlyConn()); + PeerRef peer = std::make_shared(nodeid, our_services, /*tx_relay=*/!node.IsBlockOnlyConn()); { LOCK(m_peer_mutex); m_peer_map.emplace_hint(m_peer_map.end(), nodeid, peer); @@ -1685,7 +1685,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c ping_wait = GetTime() - peer->m_ping_start.load(); } - if (!peer->m_block_relay_only) { + if (peer->m_can_tx_relay) { stats.m_relay_txs = WITH_LOCK(peer->m_tx_relay->m_bloom_filter_mutex, return peer->m_tx_relay->m_relay_txs); } else { stats.m_relay_txs = false; @@ -2211,7 +2211,7 @@ bool PeerManagerImpl::IsInvInFilter(NodeId nodeid, const uint256& hash) const PeerRef peer = GetPeerRef(nodeid); if (peer == nullptr) return false; - if (peer->m_block_relay_only) + if (!peer->m_can_tx_relay) return false; LOCK(peer->m_tx_relay->m_tx_inventory_mutex); return peer->m_tx_relay->m_tx_inventory_known_filter.contains(hash); @@ -2547,7 +2547,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic } ++it; - if (peer.m_block_relay_only && NetMessageViolatesBlocksOnly(inv.GetCommand())) { + if (!peer.m_can_tx_relay && NetMessageViolatesBlocksOnly(inv.GetCommand())) { // Note that if we receive a getdata for non-block messages // from a block-relay-only outbound peer that violate the policy, // we skip such getdata messages from this peer