From 9a26f36b7ee2a8b7c14da872fa6228ea8644ef6d Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Fri, 5 Apr 2024 19:16:26 +0200 Subject: [PATCH] Fix clippy and PR comments --- Cargo.lock | 1 + gossip/src/cluster_info.rs | 6 +----- net-utils/src/lib.rs | 2 +- streamer/Cargo.toml | 1 + streamer/src/nonblocking/quic.rs | 36 +++++++++++++------------------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22cdcb099eac05..78ce399d156041 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7291,6 +7291,7 @@ dependencies = [ "solana-logger", "solana-measure", "solana-metrics", + "solana-net-utils", "solana-perf", "solana-sdk", "solana-transaction-metrics-tracker", diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 79c148e454b433..5fdd3709e74575 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -2831,10 +2831,6 @@ impl Node { quic_config.clone(), ) .unwrap(); - let quic_config = SocketConfig { - reuseaddr: false, - reuseport: true, - }; let tpu_quic = bind_more_with_config(tpu_quic, QUIC_ENDPOINTS, quic_config.clone()).unwrap(); let (gossip_port, (gossip, ip_echo)) = @@ -3099,7 +3095,7 @@ impl Node { quic_config.clone(), ); let tpu_forwards_quic = - bind_more_with_config(tpu_forwards_quic, QUIC_ENDPOINTS, quic_config.clone()).unwrap(); + bind_more_with_config(tpu_forwards_quic, QUIC_ENDPOINTS, quic_config).unwrap(); let (tpu_vote_port, tpu_vote_sockets) = multi_bind_in_range(bind_ip_addr, port_range, 1).expect("tpu_vote multi_bind"); diff --git a/net-utils/src/lib.rs b/net-utils/src/lib.rs index 8ea956b18f6506..b4d47a3c416803 100644 --- a/net-utils/src/lib.rs +++ b/net-utils/src/lib.rs @@ -407,7 +407,7 @@ fn udp_socket(_reuseaddr: bool) -> io::Result { } #[cfg(any(windows, target_os = "ios"))] -fn udp_socket_with_config(config: SocketConfig) -> io::Result { +fn udp_socket_with_config(_config: SocketConfig) -> io::Result { let sock = Socket::new(Domain::IPV4, Type::DGRAM, None)?; Ok(sock) } diff --git a/streamer/Cargo.toml b/streamer/Cargo.toml index aa3f04c3996a06..b884e811c231ec 100644 --- a/streamer/Cargo.toml +++ b/streamer/Cargo.toml @@ -29,6 +29,7 @@ rand = { workspace = true } rustls = { workspace = true, features = ["dangerous_configuration"] } solana-measure = { workspace = true } solana-metrics = { workspace = true } +solana-net-utils = { workspace = true } solana-perf = { workspace = true } solana-sdk = { workspace = true } solana-transaction-metrics-tracker = { workspace = true } diff --git a/streamer/src/nonblocking/quic.rs b/streamer/src/nonblocking/quic.rs index 39997fa3aab555..29a0855e39fa52 100644 --- a/streamer/src/nonblocking/quic.rs +++ b/streamer/src/nonblocking/quic.rs @@ -1296,18 +1296,14 @@ pub mod test { async_channel::unbounded as async_unbounded, crossbeam_channel::{unbounded, Receiver}, quinn::{ClientConfig, IdleTimeout, TransportConfig}, - socket2, + solana_net_utils::{bind_more_with_config, bind_to_with_config, SocketConfig}, solana_sdk::{ net::DEFAULT_TPU_COALESCE, quic::{QUIC_KEEP_ALIVE, QUIC_MAX_TIMEOUT}, signature::Keypair, signer::Signer, }, - std::{ - collections::HashMap, - os::fd::{FromRawFd, IntoRawFd}, - str::FromStr as _, - }, + std::collections::HashMap, tokio::time::sleep, }; @@ -1356,6 +1352,16 @@ pub mod test { config } + fn make_quic_sockets() -> Vec { + const NUM_QUIC_SOCKETS: usize = 10; + let config = SocketConfig { + reuseaddr: false, + reuseport: true, + }; + let socket = bind_to_with_config("127.0.0.1".parse().unwrap(), 0, config.clone()).unwrap(); + bind_more_with_config(socket, NUM_QUIC_SOCKETS - 1, config).unwrap() + } + fn setup_quic_server( option_staked_nodes: Option, max_connections_per_peer: usize, @@ -1366,28 +1372,14 @@ pub mod test { SocketAddr, Arc, ) { - let sockets = (0..10) - .map(|_| { - let sock = socket2::Socket::new( - socket2::Domain::IPV4, - socket2::Type::DGRAM, - Some(socket2::Protocol::UDP), - ) - .unwrap(); - sock.set_reuse_port(true).unwrap(); - sock.bind(&SocketAddr::from_str("127.0.0.1:42069").unwrap().into()) - .unwrap(); - unsafe { UdpSocket::from_raw_fd(sock.into_raw_fd()) } - }) - .collect::>(); - + let sockets = make_quic_sockets(); let exit = Arc::new(AtomicBool::new(false)); let (sender, receiver) = unbounded(); let keypair = Keypair::new(); let server_address = sockets[0].local_addr().unwrap(); let staked_nodes = Arc::new(RwLock::new(option_staked_nodes.unwrap_or_default())); let (_, stats, t) = spawn_server_multi( - "one-million-sol", + "quic_streamer_test", sockets, &keypair, sender,