From af4759e95dd9a8349f232389bc52dc3957928ffb Mon Sep 17 00:00:00 2001 From: Illia Bobyr Date: Mon, 22 Apr 2024 15:52:48 -0700 Subject: [PATCH] cli::stake: Remove `allow(clippy::arithmetic_side_effects)` (#934) --- cli/src/stake.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 47f022011e0ec0..1c76baef40984b 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1,5 +1,3 @@ -#![allow(clippy::arithmetic_side_effects)] - use { crate::{ checks::{check_account_for_fee_with_commitment, check_unique_pubkeys}, @@ -2474,7 +2472,12 @@ pub fn get_epoch_boundary_timestamps( break block_time; } Err(_) => { - epoch_start_slot += 1; + // TODO This is wrong. We should not just increase the slot index if the RPC + // request failed. It could have failed for a number of reasons, including, for + // example a network failure. + epoch_start_slot = epoch_start_slot + .checked_add(1) + .ok_or("Reached last slot that fits into u64")?; } } }; @@ -2488,7 +2491,8 @@ pub fn make_cli_reward( ) -> Option { let wallclock_epoch_duration = epoch_end_time.checked_sub(epoch_start_time)?; if reward.post_balance > reward.amount { - let rate_change = reward.amount as f64 / (reward.post_balance - reward.amount) as f64; + let rate_change = + reward.amount as f64 / (reward.post_balance.saturating_sub(reward.amount)) as f64; let wallclock_epochs_per_year = (SECONDS_PER_DAY * 365) as f64 / wallclock_epoch_duration as f64;