Limit the maximum staked streams to avoid excessive streams from staked nodes (#27973)
* Limit the maximum staked streams to avoid excessive streams from staked nodes. * Fixed a clippy issue
This commit is contained in:
parent
42cc76e33d
commit
ad24e37cc0
|
@ -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;
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue