Skip to content

Commit

Permalink
adds tpu_quic field to RpcContactInfo
Browse files Browse the repository at this point in the history
New ContactInfo implemented in
solana-labs#29596
specifies sockets for QUIC protocols explicitly.
The commit adds tpu_quic field to RpcContactInfo in preparation of
LegacyContactInfo => ContactInfo migration.
  • Loading branch information
behzadnouri committed Apr 21, 2023
1 parent 74e02ad commit cde6c90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gossip/src/contact_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ pub(crate) fn sanitize_quic_offset(
}

// Returns the socket at QUIC_PORT_OFFSET from the given one.
fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
pub(crate) fn get_quic_socket(socket: &SocketAddr) -> Result<SocketAddr, Error> {
Ok(SocketAddr::new(
socket.ip(),
socket
Expand Down
7 changes: 6 additions & 1 deletion gossip/src/legacy_contact_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use {
crate::{
contact_info::{
sanitize_quic_offset, sanitize_socket, socket_addr_unspecified, ContactInfo, Error,
get_quic_socket, sanitize_quic_offset, sanitize_socket, socket_addr_unspecified,
ContactInfo, Error,
},
crds_value::MAX_WALLCLOCK,
},
Expand Down Expand Up @@ -169,6 +170,10 @@ impl LegacyContactInfo {
set_socket!(set_gossip, gossip);
set_socket!(set_rpc, rpc);

pub fn tpu_quic(&self) -> Result<SocketAddr, Error> {
self.tpu().and_then(|addr| get_quic_socket(&addr))
}

fn is_valid_ip(addr: IpAddr) -> bool {
!(addr.is_unspecified() || addr.is_multicast())
// || (addr.is_loopback() && !cfg_test))
Expand Down
4 changes: 3 additions & 1 deletion rpc-client-api/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ pub struct RpcContactInfo {
pub pubkey: String,
/// Gossip port
pub gossip: Option<SocketAddr>,
/// Tpu port
/// Tpu UDP port
pub tpu: Option<SocketAddr>,
/// Tpu QUIC port
pub tpu_quic: Option<SocketAddr>,
/// JSON RPC port
pub rpc: Option<SocketAddr>,
/// WebSocket PubSub port
Expand Down
1 change: 1 addition & 0 deletions rpc-client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl RpcSender for MockSender {
pubkey: PUBKEY.to_string(),
gossip: Some(SocketAddr::from(([10, 239, 6, 48], 8899))),
tpu: Some(SocketAddr::from(([10, 239, 6, 48], 8856))),
tpu_quic: Some(SocketAddr::from(([10, 239, 6, 48], 8862))),
rpc: Some(SocketAddr::from(([10, 239, 6, 48], 8899))),
pubsub: Some(SocketAddr::from(([10, 239, 6, 48], 8900))),
version: Some("1.0.0 c375ce1f".to_string()),
Expand Down
6 changes: 6 additions & 0 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3472,6 +3472,10 @@ pub mod rpc_full {
.tpu()
.ok()
.filter(|addr| socket_addr_space.check(addr)),
tpu_quic: contact_info
.tpu_quic()
.ok()
.filter(|addr| socket_addr_space.check(addr)),
rpc: contact_info
.rpc()
.ok()
Expand Down Expand Up @@ -5138,6 +5142,7 @@ pub mod tests {
"gossip": "127.0.0.1:8000",
"shredVersion": 0u16,
"tpu": "127.0.0.1:8003",
"tpuQuic": "127.0.0.1:8009",
"rpc": format!("127.0.0.1:{}", rpc_port::DEFAULT_RPC_PORT),
"pubsub": format!("127.0.0.1:{}", rpc_port::DEFAULT_RPC_PUBSUB_PORT),
"version": null,
Expand All @@ -5147,6 +5152,7 @@ pub mod tests {
"gossip": "127.0.0.1:1235",
"shredVersion": 0u16,
"tpu": "127.0.0.1:1234",
"tpuQuic": "127.0.0.1:1240",
"rpc": format!("127.0.0.1:{}", rpc_port::DEFAULT_RPC_PORT),
"pubsub": format!("127.0.0.1:{}", rpc_port::DEFAULT_RPC_PUBSUB_PORT),
"version": null,
Expand Down

0 comments on commit cde6c90

Please sign in to comment.