From 974fd8586304046de7faf514450bd998762e538d Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Fri, 10 Jan 2025 09:14:50 -0600 Subject: [PATCH] removes SocketAddrCache from pub interface --- gossip/src/contact_info.rs | 2 +- turbine/src/cluster_nodes.rs | 38 ++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/gossip/src/contact_info.rs b/gossip/src/contact_info.rs index 42c7dd67d52f2a..1c727b9082698f 100644 --- a/gossip/src/contact_info.rs +++ b/gossip/src/contact_info.rs @@ -43,7 +43,7 @@ const SOCKET_TAG_TVU_QUIC: u8 = 11; const_assert_eq!(SOCKET_CACHE_SIZE, 13); const SOCKET_CACHE_SIZE: usize = SOCKET_TAG_TPU_VOTE_QUIC as usize + 1usize; -pub type SocketAddrCache = [SocketAddr; SOCKET_CACHE_SIZE]; +pub(crate) type SocketAddrCache = [SocketAddr; SOCKET_CACHE_SIZE]; // A trait alias for a function that reads data from a ContactInfo entry stored // in the gossip CRDS table. diff --git a/turbine/src/cluster_nodes.rs b/turbine/src/cluster_nodes.rs index d2262ad29e01d3..43f3b20c7492d5 100644 --- a/turbine/src/cluster_nodes.rs +++ b/turbine/src/cluster_nodes.rs @@ -6,7 +6,7 @@ use { solana_feature_set as feature_set, solana_gossip::{ cluster_info::ClusterInfo, - contact_info::{ContactInfo as GossipContactInfo, Protocol, SocketAddrCache}, + contact_info::{ContactInfo as GossipContactInfo, Protocol}, crds::GossipRoute, crds_data::CrdsData, crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS, @@ -26,7 +26,6 @@ use { solana_streamer::socket::SocketAddrSpace, std::{ any::TypeId, - borrow::Borrow, cmp::Ordering, collections::{HashMap, HashSet}, iter::repeat_with, @@ -310,6 +309,23 @@ pub fn new_cluster_nodes( } } +// Defines a closure which converts from &GossipContactInfo<_> to ContactInfo. +// Same can be achieved with +// impl> From<&GossipContactInfo> for ContactInfo +// but SocketAddrCache type is a private to gossip. +macro_rules! from_gossip_node { + () => { + |node: &GossipContactInfo<_>| -> ContactInfo { + ContactInfo { + pubkey: *node.pubkey(), + wallclock: node.wallclock(), + tvu_quic: node.tvu(Protocol::QUIC), + tvu_udp: node.tvu(Protocol::UDP), + } + } + }; +} + // All staked nodes + other known tvu-peers + the node itself; // sorted by (stake, pubkey) in descending order. fn get_nodes( @@ -325,14 +341,14 @@ fn get_nodes( let mut nodes: Vec = std::iter::once({ // The local node itself. let stake = stakes.get(&self_pubkey).copied().unwrap_or_default(); - let node = ContactInfo::from(&cluster_info.my_contact_info()); + let node = from_gossip_node!()(&cluster_info.my_contact_info()); let node = NodeId::from(node); Node { node, stake } }) // All known tvu-peers from gossip. .chain( cluster_info - .tvu_peers(|node| ContactInfo::from(node)) + .tvu_peers(from_gossip_node!()) .into_iter() .map(|node| { let stake = stakes.get(node.pubkey()).copied().unwrap_or_default(); @@ -572,18 +588,6 @@ impl From for NodeId { } } -impl> From<&GossipContactInfo> for ContactInfo { - #[inline] - fn from(node: &GossipContactInfo) -> Self { - Self { - pubkey: *node.pubkey(), - wallclock: node.wallclock(), - tvu_quic: node.tvu(Protocol::QUIC), - tvu_udp: node.tvu(Protocol::UDP), - } - } -} - #[inline] pub(crate) fn get_broadcast_protocol(_: &ShredId) -> Protocol { Protocol::UDP @@ -992,7 +996,7 @@ mod tests { let node = GossipContactInfo::new_localhost(&pubkey, /*wallclock:*/ timestamp()); [ Node { - node: NodeId::from(ContactInfo::from(&node)), + node: NodeId::from(from_gossip_node!()(&node)), stake, }, Node {