Skip to content

Commit bf09fd5

Browse files
authored
removes QUIC port offsetting and checks in LegacyContactInfo (#4507)
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.
1 parent baf53a4 commit bf09fd5

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

gossip/src/contact_info.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn sanitize_entries(addrs: &[IpAddr], sockets: &[SocketEntry]) -> Result<(), Err
637637

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

649649
// Returns the socket at QUIC_PORT_OFFSET from the given one.
650-
pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
650+
fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
651651
Ok(SocketAddr::new(
652652
socket.ip(),
653653
socket
@@ -964,34 +964,23 @@ mod tests {
964964
old.serve_repair(Protocol::UDP).unwrap(),
965965
node.serve_repair(Protocol::UDP).unwrap()
966966
);
967+
assert_eq!(old.tpu().unwrap(), node.tpu(Protocol::UDP).unwrap());
967968
assert_eq!(
968-
old.tpu(Protocol::QUIC).unwrap(),
969-
node.tpu(Protocol::QUIC).unwrap()
970-
);
971-
assert_eq!(
972-
old.tpu(Protocol::UDP).unwrap(),
973-
node.tpu(Protocol::UDP).unwrap()
974-
);
975-
assert_eq!(
976-
old.tpu_forwards(Protocol::QUIC).unwrap(),
977-
node.tpu_forwards(Protocol::QUIC).unwrap()
969+
node.tpu(Protocol::QUIC).unwrap(),
970+
SocketAddr::new(
971+
old.tpu().unwrap().ip(),
972+
old.tpu().unwrap().port() + QUIC_PORT_OFFSET
973+
)
978974
);
979975
assert_eq!(
980-
old.tpu_forwards(Protocol::UDP).unwrap(),
976+
old.tpu_forwards().unwrap(),
981977
node.tpu_forwards(Protocol::UDP).unwrap()
982978
);
983979
assert_eq!(
984980
node.tpu_forwards(Protocol::QUIC).unwrap(),
985981
SocketAddr::new(
986-
old.tpu_forwards(Protocol::UDP).unwrap().ip(),
987-
old.tpu_forwards(Protocol::UDP).unwrap().port() + QUIC_PORT_OFFSET
988-
)
989-
);
990-
assert_eq!(
991-
node.tpu(Protocol::QUIC).unwrap(),
992-
SocketAddr::new(
993-
old.tpu(Protocol::UDP).unwrap().ip(),
994-
old.tpu(Protocol::UDP).unwrap().port() + QUIC_PORT_OFFSET
982+
old.tpu_forwards().unwrap().ip(),
983+
old.tpu_forwards().unwrap().port() + QUIC_PORT_OFFSET
995984
)
996985
);
997986
assert_eq!(

gossip/src/legacy_contact_info.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#[cfg(test)]
2-
use crate::contact_info::{
3-
get_quic_socket, sanitize_quic_offset, sanitize_socket, ContactInfo, Error, Protocol,
4-
SOCKET_ADDR_UNSPECIFIED,
5-
};
2+
use crate::contact_info::{sanitize_socket, ContactInfo, Error, Protocol, SOCKET_ADDR_UNSPECIFIED};
63
use {
74
crate::crds_data::MAX_WALLCLOCK,
85
solana_pubkey::Pubkey,
@@ -71,17 +68,6 @@ macro_rules! get_socket {
7168
Some(socket)
7269
}
7370
};
74-
(@quic $name:ident) => {
75-
#[cfg(test)]
76-
pub(crate) fn $name(&self, protocol: Protocol) -> Option<SocketAddr> {
77-
let socket = self.$name;
78-
sanitize_socket(&socket).ok()?;
79-
match protocol {
80-
Protocol::QUIC => get_quic_socket(&socket).ok(),
81-
Protocol::UDP => Some(socket),
82-
}
83-
}
84-
};
8571
}
8672

8773
#[macro_export]
@@ -145,8 +131,8 @@ impl LegacyContactInfo {
145131
}
146132

147133
get_socket!(tvu, tvu_quic);
148-
get_socket!(@quic tpu);
149-
get_socket!(@quic tpu_forwards);
134+
get_socket!(tpu);
135+
get_socket!(tpu_forwards);
150136
get_socket!(tpu_vote);
151137
get_socket!(rpc);
152138
get_socket!(rpc_pubsub);
@@ -180,11 +166,6 @@ impl TryFrom<&ContactInfo> for LegacyContactInfo {
180166
node.$name($protocol).unwrap_or(SOCKET_ADDR_UNSPECIFIED)
181167
};
182168
}
183-
sanitize_quic_offset(&node.tpu(Protocol::UDP), &node.tpu(Protocol::QUIC))?;
184-
sanitize_quic_offset(
185-
&node.tpu_forwards(Protocol::UDP),
186-
&node.tpu_forwards(Protocol::QUIC),
187-
)?;
188169
Ok(Self {
189170
id: *node.pubkey(),
190171
gossip: unwrap_socket!(gossip),

0 commit comments

Comments
 (0)