Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit de8415c

Browse files
authored
Allow some minimum number of streams for a staked connection - v1.17 (#34894)
Allow some minimum number of streams for a staked connection
1 parent 74b0830 commit de8415c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

streamer/src/nonblocking/quic.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,13 @@ fn max_streams_for_connection_in_100ms(
695695
.apply_to(MAX_STREAMS_PER_100MS)
696696
.saturating_div(MAX_UNSTAKED_CONNECTIONS as u64)
697697
} else {
698+
const MIN_STAKED_STREAMS: u64 = 8;
698699
let max_total_staked_streams: u64 = MAX_STREAMS_PER_100MS
699700
- Percentage::from(MAX_UNSTAKED_STREAMS_PERCENT).apply_to(MAX_STREAMS_PER_100MS);
700-
((max_total_staked_streams as f64 / total_stake as f64) * stake as f64) as u64
701+
std::cmp::max(
702+
MIN_STAKED_STREAMS,
703+
((max_total_staked_streams as f64 / total_stake as f64) * stake as f64) as u64,
704+
)
701705
}
702706
}
703707

@@ -2063,5 +2067,12 @@ pub mod test {
20632067
max_streams_for_connection_in_100ms(ConnectionPeerType::Staked, 1000, 10000),
20642068
4000
20652069
);
2070+
2071+
// max staked streams = 50K packets per ms * 80% = 40K
2072+
// minimum staked streams.
2073+
assert_eq!(
2074+
max_streams_for_connection_in_100ms(ConnectionPeerType::Staked, 1, 50000),
2075+
8
2076+
);
20662077
}
20672078
}

0 commit comments

Comments
 (0)