diff --git a/sdk/src/quic.rs b/sdk/src/quic.rs index d0012ba71286e1..5038ab0ee4055d 100644 --- a/sdk/src/quic.rs +++ b/sdk/src/quic.rs @@ -7,6 +7,9 @@ pub const QUIC_MIN_STAKED_CONCURRENT_STREAMS: usize = 128; pub const QUIC_TOTAL_STAKED_CONCURRENT_STREAMS: usize = 100_000; +// Set the maximum concurrent stream numbers to avoid excessive streams +pub const QUIC_MAX_STAKED_CONCURRENT_STREAMS: usize = 2048; + pub const QUIC_MAX_TIMEOUT_MS: u32 = 2_000; pub const QUIC_KEEP_ALIVE_MS: u64 = 1_000; diff --git a/streamer/src/nonblocking/quic.rs b/streamer/src/nonblocking/quic.rs index c39eed495551b1..ef162f4cb252b6 100644 --- a/streamer/src/nonblocking/quic.rs +++ b/streamer/src/nonblocking/quic.rs @@ -19,10 +19,10 @@ use { packet::{Packet, PACKET_DATA_SIZE}, pubkey::Pubkey, quic::{ - QUIC_CONNECTION_HANDSHAKE_TIMEOUT_MS, QUIC_MAX_STAKED_RECEIVE_WINDOW_RATIO, - QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS, QUIC_MIN_STAKED_CONCURRENT_STREAMS, - QUIC_MIN_STAKED_RECEIVE_WINDOW_RATIO, QUIC_TOTAL_STAKED_CONCURRENT_STREAMS, - QUIC_UNSTAKED_RECEIVE_WINDOW_RATIO, + QUIC_CONNECTION_HANDSHAKE_TIMEOUT_MS, QUIC_MAX_STAKED_CONCURRENT_STREAMS, + QUIC_MAX_STAKED_RECEIVE_WINDOW_RATIO, QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS, + QUIC_MIN_STAKED_CONCURRENT_STREAMS, QUIC_MIN_STAKED_RECEIVE_WINDOW_RATIO, + QUIC_TOTAL_STAKED_CONCURRENT_STREAMS, QUIC_UNSTAKED_RECEIVE_WINDOW_RATIO, }, signature::Keypair, timing, @@ -205,8 +205,12 @@ pub fn compute_max_allowed_uni_streams( - QUIC_MIN_STAKED_CONCURRENT_STREAMS) as f64; - ((peer_stake as f64 / total_stake as f64) * delta) as usize - + QUIC_MIN_STAKED_CONCURRENT_STREAMS + (((peer_stake as f64 / total_stake as f64) * delta) as usize + + QUIC_MIN_STAKED_CONCURRENT_STREAMS) + .clamp( + QUIC_MIN_STAKED_CONCURRENT_STREAMS, + QUIC_MAX_STAKED_CONCURRENT_STREAMS, + ) } } _ => QUIC_MAX_UNSTAKED_CONCURRENT_STREAMS, @@ -1636,7 +1640,7 @@ pub mod test { (QUIC_TOTAL_STAKED_CONCURRENT_STREAMS - QUIC_MIN_STAKED_CONCURRENT_STREAMS) as f64; assert_eq!( compute_max_allowed_uni_streams(ConnectionPeerType::Staked, 1000, 10000), - (delta / (10_f64)) as usize + QUIC_MIN_STAKED_CONCURRENT_STREAMS + QUIC_MAX_STAKED_CONCURRENT_STREAMS, ); assert_eq!( compute_max_allowed_uni_streams(ConnectionPeerType::Staked, 100, 10000),