Skip to content

Commit

Permalink
Allow some minimum number of streams for a staked connection
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed Jan 24, 2024
1 parent 74b0830 commit de962cc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}

Expand Down Expand Up @@ -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
);
}
}

0 comments on commit de962cc

Please sign in to comment.