Skip to content

Commit

Permalink
removes SocketAddrCache from pub interface
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri committed Jan 10, 2025
1 parent 0253818 commit fd18c66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gossip/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

// An alias for a function that reads data from a ContactInfo entry stored in
// the gossip CRDS table.
Expand Down
38 changes: 21 additions & 17 deletions turbine/src/cluster_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,7 +26,6 @@ use {
solana_streamer::socket::SocketAddrSpace,
std::{
any::TypeId,
borrow::Borrow,
cmp::Ordering,
collections::{HashMap, HashSet},
iter::repeat_with,
Expand Down Expand Up @@ -310,6 +309,23 @@ pub fn new_cluster_nodes<T: 'static>(
}
}

// Defines a closure which converts from &GossipContactInfo<_> to ContactInfo.
// Same can be achieved with
// impl<T: Borrow<SocketAddrCache>> From<&GossipContactInfo<T>> 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(
Expand All @@ -325,14 +341,14 @@ fn get_nodes(
let mut nodes: Vec<Node> = 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();
Expand Down Expand Up @@ -572,18 +588,6 @@ impl From<Pubkey> for NodeId {
}
}

impl<T: Borrow<SocketAddrCache>> From<&GossipContactInfo<T>> for ContactInfo {
#[inline]
fn from(node: &GossipContactInfo<T>) -> 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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fd18c66

Please sign in to comment.