Skip to content

Commit 153bc00

Browse files
authored
div by zero fix (solana-labs#138)
* div by zero fix * fmt * use cur slot instead of 0
1 parent 5122002 commit 153bc00

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

token-lending/sdk/src/state/rate_limiter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ impl Default for RateLimiterConfig {
4949
impl RateLimiter {
5050
/// initialize rate limiter
5151
pub fn new(config: RateLimiterConfig, cur_slot: u64) -> Self {
52-
let slot_start = cur_slot / config.window_duration * config.window_duration;
52+
let slot_start = if config.window_duration != 0 {
53+
cur_slot / config.window_duration * config.window_duration
54+
} else {
55+
cur_slot
56+
};
57+
5358
Self {
5459
config,
5560
prev_qty: Decimal::zero(),

0 commit comments

Comments
 (0)