From 527024aef3de465b6350d7fc49495de4086fe581 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Mon, 22 Jan 2024 16:07:13 -0800 Subject: [PATCH] Allow some minimum number of streams for a staked connection --- streamer/src/nonblocking/quic.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/streamer/src/nonblocking/quic.rs b/streamer/src/nonblocking/quic.rs index 951ec6cb317fcd..04b2e66e8f319e 100644 --- a/streamer/src/nonblocking/quic.rs +++ b/streamer/src/nonblocking/quic.rs @@ -695,9 +695,13 @@ fn max_streams_for_connection_in_100ms( .apply_to(MAX_STREAMS_PER_100MS) .saturating_div(MAX_UNSTAKED_CONNECTIONS as u64) } else { + const MIN_STAKED_STREAMS: u64 = 8; let max_total_staked_streams: u64 = MAX_STREAMS_PER_100MS - Percentage::from(MAX_UNSTAKED_STREAMS_PERCENT).apply_to(MAX_STREAMS_PER_100MS); - ((max_total_staked_streams as f64 / total_stake as f64) * stake as f64) as u64 + std::cmp::max( + MIN_STAKED_STREAMS, + ((max_total_staked_streams as f64 / total_stake as f64) * stake as f64) as u64, + ) } } @@ -2063,5 +2067,12 @@ pub mod test { max_streams_for_connection_in_100ms(ConnectionPeerType::Staked, 1000, 10000), 4000 ); + + // max staked streams = 50K packets per ms * 80% = 40K + // minimum staked streams. + assert_eq!( + max_streams_for_connection_in_100ms(ConnectionPeerType::Staked, 1, 50000), + 8 + ); } }