Skip to content

Commit 2b5528d

Browse files
committed
Apply Copilot suggestions
1 parent 88bfa6e commit 2b5528d

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ hex = { version = "^0.4.3" }
2929
serde = { version = "1.0", features = ["derive"] }
3030
serde_json = { version = "^1.0" }
3131
tokio = { version = "1", features = ["full"] }
32-
tokio-util = { version = "0.7.17" }
3332
tower = { version = "0.5.2", features = ["full"] }
3433
libp2p = { version = "0.56", features = ["full", "secp256k1"] }
3534
prost = "0.14"

crates/charon/src/expbackoff/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
let mut backoff = self.base_delay;
3535
let mut retries = self.retries;
3636

37-
// SAFE: Substraction is only performed when retries > 0
37+
// SAFE: Subtraction is only performed when retries > 0
3838
#[allow(clippy::arithmetic_side_effects)]
3939
while backoff < self.max_delay && retries > 0 {
4040
backoff = backoff.mul_f64(self.multiplier);
@@ -173,12 +173,15 @@ impl<R> ExponentialBackoffBuilder<R> {
173173
if self.jitter > 100.0 {
174174
return Err(InvalidBackoff("jitter must not be greater than 100"));
175175
}
176-
if !self.jitter.is_finite() {
176+
if self.jitter.is_infinite() || self.jitter.is_nan() {
177177
return Err(InvalidBackoff("jitter must be finite"));
178178
}
179179
if self.multiplier < 0.0 {
180180
return Err(InvalidBackoff("multiplier must not be negative"));
181181
}
182+
if self.multiplier.is_infinite() || self.multiplier.is_nan() {
183+
return Err(InvalidBackoff("multiplier must be finite"));
184+
}
182185

183186
Ok(ExponentialBackoff {
184187
base_delay: self.base_delay,
@@ -323,15 +326,15 @@ mod tests {
323326
instance.tried();
324327
assert_eq!(total_time, Duration::from_secs(7));
325328

326-
// third backoff
329+
// fourth backoff
327330
total_time += instance.backoff();
328331
instance.tried();
329332
assert_eq!(total_time, Duration::from_secs(15));
330333

331334
// reset
332335
instance.reset();
333336

334-
// fourth backoff
337+
// fifth backoff
335338
total_time += instance.backoff();
336339
instance.tried();
337340
assert_eq!(total_time, Duration::from_secs(16));

0 commit comments

Comments
 (0)