From 86e7f91cece6da9476fd8b10196d8fb0a0b616fe Mon Sep 17 00:00:00 2001 From: galactus <96341601+godmodegalactus@users.noreply.github.com> Date: Fri, 19 Jan 2024 22:08:03 +0100 Subject: [PATCH] Updating the transport config to match with solana endpoint (#292) * Updating the transport config to match with solana endpoint * Setting max MTU after groovies comments --- services/src/quic_connection_utils.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/services/src/quic_connection_utils.rs b/services/src/quic_connection_utils.rs index c8f70ae1..dcdf9156 100644 --- a/services/src/quic_connection_utils.rs +++ b/services/src/quic_connection_utils.rs @@ -2,7 +2,7 @@ use log::trace; use prometheus::{core::GenericGauge, opts, register_int_gauge}; use quinn::{ ClientConfig, Connection, ConnectionError, Endpoint, EndpointConfig, IdleTimeout, SendStream, - TokioRuntime, TransportConfig, + TokioRuntime, TransportConfig, VarInt, }; use solana_lite_rpc_core::network_utils::apply_gso_workaround; use solana_sdk::pubkey::Pubkey; @@ -55,12 +55,20 @@ pub struct QuicConnectionUtils {} impl QuicConnectionUtils { pub fn create_endpoint(certificate: rustls::Certificate, key: rustls::PrivateKey) -> Endpoint { + const DATAGRAM_RECEIVE_BUFFER_SIZE: usize = 64 * 1024 * 1024; + const DATAGRAM_SEND_BUFFER_SIZE: usize = 64 * 1024 * 1024; + const INITIAL_MAXIMUM_TRANSMISSION_UNIT: u16 = MINIMUM_MAXIMUM_TRANSMISSION_UNIT; + const MINIMUM_MAXIMUM_TRANSMISSION_UNIT: u16 = 1280; + let mut endpoint = { let client_socket = solana_net_utils::bind_in_range(IpAddr::V4(Ipv4Addr::UNSPECIFIED), (8000, 10000)) .expect("create_endpoint bind_in_range") .1; - let config = EndpointConfig::default(); + let mut config = EndpointConfig::default(); + config + .max_udp_payload_size(MINIMUM_MAXIMUM_TRANSMISSION_UNIT) + .expect("Should set max MTU"); quinn::Endpoint::new(config, None, client_socket, Arc::new(TokioRuntime)) .expect("create_endpoint quinn::Endpoint::new") }; @@ -79,6 +87,13 @@ impl QuicConnectionUtils { let timeout = IdleTimeout::try_from(Duration::from_secs(1)).unwrap(); transport_config.max_idle_timeout(Some(timeout)); transport_config.keep_alive_interval(Some(Duration::from_millis(500))); + transport_config.datagram_receive_buffer_size(Some(DATAGRAM_RECEIVE_BUFFER_SIZE)); + transport_config.datagram_send_buffer_size(DATAGRAM_SEND_BUFFER_SIZE); + transport_config.initial_mtu(INITIAL_MAXIMUM_TRANSMISSION_UNIT); + transport_config.max_concurrent_bidi_streams(VarInt::from(0u8)); + transport_config.max_concurrent_uni_streams(VarInt::from(0u8)); + transport_config.min_mtu(MINIMUM_MAXIMUM_TRANSMISSION_UNIT); + transport_config.mtu_discovery_config(None); apply_gso_workaround(&mut transport_config); config.transport_config(Arc::new(transport_config));