@@ -230,8 +230,25 @@ struct Peer {
230230 * We initialize this filter for outbound peers (other than
231231 * block-relay-only connections) or when an inbound peer sends us an
232232 * address related message (ADDR, ADDRV2, GETADDR).
233+ *
234+ * Presence of this filter must correlate with m_addr_relay_enabled.
233235 **/
234236 std::unique_ptr<CRollingBloomFilter> m_addr_known;
237+ /* * Whether we are participating in address relay with this connection.
238+ *
239+ * We set this bool to true for outbound peers (other than
240+ * block-relay-only connections), or when an inbound peer sends us an
241+ * address related message (ADDR, ADDRV2, GETADDR).
242+ *
243+ * We use this bool to decide whether a peer is eligible for gossiping
244+ * addr messages. This avoids relaying to peers that are unlikely to
245+ * forward them, effectively blackholing self announcements. Reasons
246+ * peers might support addr relay on the link include that they connected
247+ * to us as a block-relay-only peer or they are a light client.
248+ *
249+ * This field must correlate with whether m_addr_known has been
250+ * initialized.*/
251+ std::atomic_bool m_addr_relay_enabled{false };
235252 /* * Whether a getaddr request to this peer is outstanding. */
236253 bool m_getaddr_sent{false };
237254 /* * Guards address sending timers. */
@@ -617,8 +634,8 @@ class PeerManagerImpl final : public PeerManager
617634 */
618635 void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv);
619636
620- /* * Checks if address relay is permitted with peer. Initializes
621- * ` m_addr_known` bloom filter if needed .
637+ /* * Checks if address relay is permitted with peer. If needed, initializes
638+ * the m_addr_known bloom filter and sets m_addr_relay_enabled to true .
622639 *
623640 * @return True if address relay is enabled with peer
624641 * False if address relay is disallowed
@@ -746,7 +763,7 @@ static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
746763
747764static bool RelayAddrsWithPeer (const Peer& peer)
748765{
749- return peer.m_addr_known != nullptr ;
766+ return peer.m_addr_relay_enabled ;
750767}
751768
752769/* *
@@ -4449,6 +4466,7 @@ bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& peer)
44494466 // First addr message we have received from the peer, initialize
44504467 // m_addr_known
44514468 peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000 , 0.001 );
4469+ peer.m_addr_relay_enabled = true ;
44524470 }
44534471
44544472 return true ;
0 commit comments