Skip to content

Commit

Permalink
removes QUIC port offsetting and checks in LegacyContactInfo (#4507)
Browse files Browse the repository at this point in the history
With the new ContactInfo we no longer need QUIC_PORT_OFFSET.
Working towards removing QUIC_PORT_OFFSET, this commit removes QUIC port
offsetting and checks in LegacyContactInfo.
  • Loading branch information
behzadnouri authored Jan 17, 2025
1 parent baf53a4 commit bf09fd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
33 changes: 11 additions & 22 deletions gossip/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ fn sanitize_entries(addrs: &[IpAddr], sockets: &[SocketEntry]) -> Result<(), Err

// Verifies that the other socket is at QUIC_PORT_OFFSET from the first one.
#[cfg(test)]
pub(crate) fn sanitize_quic_offset(
fn sanitize_quic_offset(
socket: &Option<SocketAddr>, // udp
other: &Option<SocketAddr>, // quic: udp + QUIC_PORT_OFFSET
) -> Result<(), Error> {
Expand All @@ -647,7 +647,7 @@ pub(crate) fn sanitize_quic_offset(
}

// Returns the socket at QUIC_PORT_OFFSET from the given one.
pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
Ok(SocketAddr::new(
socket.ip(),
socket
Expand Down Expand Up @@ -964,34 +964,23 @@ mod tests {
old.serve_repair(Protocol::UDP).unwrap(),
node.serve_repair(Protocol::UDP).unwrap()
);
assert_eq!(old.tpu().unwrap(), node.tpu(Protocol::UDP).unwrap());
assert_eq!(
old.tpu(Protocol::QUIC).unwrap(),
node.tpu(Protocol::QUIC).unwrap()
);
assert_eq!(
old.tpu(Protocol::UDP).unwrap(),
node.tpu(Protocol::UDP).unwrap()
);
assert_eq!(
old.tpu_forwards(Protocol::QUIC).unwrap(),
node.tpu_forwards(Protocol::QUIC).unwrap()
node.tpu(Protocol::QUIC).unwrap(),
SocketAddr::new(
old.tpu().unwrap().ip(),
old.tpu().unwrap().port() + QUIC_PORT_OFFSET
)
);
assert_eq!(
old.tpu_forwards(Protocol::UDP).unwrap(),
old.tpu_forwards().unwrap(),
node.tpu_forwards(Protocol::UDP).unwrap()
);
assert_eq!(
node.tpu_forwards(Protocol::QUIC).unwrap(),
SocketAddr::new(
old.tpu_forwards(Protocol::UDP).unwrap().ip(),
old.tpu_forwards(Protocol::UDP).unwrap().port() + QUIC_PORT_OFFSET
)
);
assert_eq!(
node.tpu(Protocol::QUIC).unwrap(),
SocketAddr::new(
old.tpu(Protocol::UDP).unwrap().ip(),
old.tpu(Protocol::UDP).unwrap().port() + QUIC_PORT_OFFSET
old.tpu_forwards().unwrap().ip(),
old.tpu_forwards().unwrap().port() + QUIC_PORT_OFFSET
)
);
assert_eq!(
Expand Down
25 changes: 3 additions & 22 deletions gossip/src/legacy_contact_info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#[cfg(test)]
use crate::contact_info::{
get_quic_socket, sanitize_quic_offset, sanitize_socket, ContactInfo, Error, Protocol,
SOCKET_ADDR_UNSPECIFIED,
};
use crate::contact_info::{sanitize_socket, ContactInfo, Error, Protocol, SOCKET_ADDR_UNSPECIFIED};
use {
crate::crds_data::MAX_WALLCLOCK,
solana_pubkey::Pubkey,
Expand Down Expand Up @@ -71,17 +68,6 @@ macro_rules! get_socket {
Some(socket)
}
};
(@quic $name:ident) => {
#[cfg(test)]
pub(crate) fn $name(&self, protocol: Protocol) -> Option<SocketAddr> {
let socket = self.$name;
sanitize_socket(&socket).ok()?;
match protocol {
Protocol::QUIC => get_quic_socket(&socket).ok(),
Protocol::UDP => Some(socket),
}
}
};
}

#[macro_export]
Expand Down Expand Up @@ -145,8 +131,8 @@ impl LegacyContactInfo {
}

get_socket!(tvu, tvu_quic);
get_socket!(@quic tpu);
get_socket!(@quic tpu_forwards);
get_socket!(tpu);
get_socket!(tpu_forwards);
get_socket!(tpu_vote);
get_socket!(rpc);
get_socket!(rpc_pubsub);
Expand Down Expand Up @@ -180,11 +166,6 @@ impl TryFrom<&ContactInfo> for LegacyContactInfo {
node.$name($protocol).unwrap_or(SOCKET_ADDR_UNSPECIFIED)
};
}
sanitize_quic_offset(&node.tpu(Protocol::UDP), &node.tpu(Protocol::QUIC))?;
sanitize_quic_offset(
&node.tpu_forwards(Protocol::UDP),
&node.tpu_forwards(Protocol::QUIC),
)?;
Ok(Self {
id: *node.pubkey(),
gossip: unwrap_socket!(gossip),
Expand Down

0 comments on commit bf09fd5

Please sign in to comment.