@@ -230,8 +230,25 @@ struct Peer {
230
230
* We initialize this filter for outbound peers (other than
231
231
* block-relay-only connections) or when an inbound peer sends us an
232
232
* address related message (ADDR, ADDRV2, GETADDR).
233
+ *
234
+ * Presence of this filter must correlate with m_addr_relay_enabled.
233
235
**/
234
236
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 };
235
252
/* * Whether a getaddr request to this peer is outstanding. */
236
253
bool m_getaddr_sent{false };
237
254
/* * Guards address sending timers. */
@@ -617,8 +634,8 @@ class PeerManagerImpl final : public PeerManager
617
634
*/
618
635
void ProcessGetCFCheckPt (CNode& peer, CDataStream& vRecv);
619
636
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 .
622
639
*
623
640
* @return True if address relay is enabled with peer
624
641
* False if address relay is disallowed
@@ -746,7 +763,7 @@ static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
746
763
747
764
static bool RelayAddrsWithPeer (const Peer& peer)
748
765
{
749
- return peer.m_addr_known != nullptr ;
766
+ return peer.m_addr_relay_enabled ;
750
767
}
751
768
752
769
/* *
@@ -4449,6 +4466,7 @@ bool PeerManagerImpl::SetupAddressRelay(CNode& node, Peer& peer)
4449
4466
// First addr message we have received from the peer, initialize
4450
4467
// m_addr_known
4451
4468
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000 , 0.001 );
4469
+ peer.m_addr_relay_enabled = true ;
4452
4470
}
4453
4471
4454
4472
return true ;
0 commit comments