From ddef2fb7fa77996ef929c0d724fedbef3cf3e259 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 20 Feb 2021 08:11:45 +0000 Subject: [PATCH] Prevent u64 overflow when calculating current stake percentage (#15453) (cherry picked from commit 5ae37b9675888c1eb218780d778c0825460f8105) Co-authored-by: Michael Vines --- watchtower/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/watchtower/src/main.rs b/watchtower/src/main.rs index d16faebca2..d9b26c8d97 100644 --- a/watchtower/src/main.rs +++ b/watchtower/src/main.rs @@ -241,9 +241,9 @@ fn main() -> Result<(), Box> { .sum(); let total_stake = total_current_stake + total_delinquent_stake; - let current_stake_percent = total_current_stake * 100 / total_stake; + let current_stake_percent = total_current_stake as f64 * 100. / total_stake as f64; info!( - "Current stake: {}% | Total stake: {}, current stake: {}, delinquent: {}", + "Current stake: {:.2}% | Total stake: {}, current stake: {}, delinquent: {}", current_stake_percent, Sol(total_stake), Sol(total_current_stake), @@ -271,10 +271,10 @@ fn main() -> Result<(), Box> { )); } - if config.monitor_active_stake && current_stake_percent < 80 { + if config.monitor_active_stake && current_stake_percent < 80. { failures.push(( "current-stake", - format!("Current stake is {}%", current_stake_percent), + format!("Current stake is {:.2}%", current_stake_percent), )); }