Skip to content

Commit

Permalink
div by zero fix (solana-labs#138)
Browse files Browse the repository at this point in the history
* div by zero fix

* fmt

* use cur slot instead of 0
  • Loading branch information
0xripleys authored Apr 10, 2023
1 parent 5122002 commit 153bc00
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion token-lending/sdk/src/state/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ impl Default for RateLimiterConfig {
impl RateLimiter {
/// initialize rate limiter
pub fn new(config: RateLimiterConfig, cur_slot: u64) -> Self {
let slot_start = cur_slot / config.window_duration * config.window_duration;
let slot_start = if config.window_duration != 0 {
cur_slot / config.window_duration * config.window_duration
} else {
cur_slot
};

Self {
config,
prev_qty: Decimal::zero(),
Expand Down

0 comments on commit 153bc00

Please sign in to comment.