Prevent u64 overflow when calculating current stake percentage

This commit is contained in:
Michael Vines 2021-02-19 21:20:34 -08:00
parent 1a9956d1c6
commit 5ae37b9675
1 changed files with 4 additions and 4 deletions

View File

@ -241,9 +241,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.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<dyn error::Error>> {
));
}
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),
));
}