From 7de8a55b54d3e11058b82f9483bb405d143b455c Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 14 Sep 2021 20:17:59 -0500 Subject: [PATCH] Use f64 for stake math in get_stake_percent_in_gossip (#19892) --- core/src/validator.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index 303daac75e..41ac91745c 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -1512,21 +1512,22 @@ fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: boo } } + let online_stake_percentage = (online_stake as f64 / total_activated_stake as f64) * 100.; if log { info!( - "{}% of active stake visible in gossip", - online_stake * 100 / total_activated_stake + "{:.3}% of active stake visible in gossip", + online_stake_percentage ); if !wrong_shred_nodes.is_empty() { info!( - "{}% of active stake has the wrong shred version in gossip", - wrong_shred_stake * 100 / total_activated_stake, + "{:.3}% of active stake has the wrong shred version in gossip", + (wrong_shred_stake as f64 / total_activated_stake as f64) * 100., ); for (stake, identity) in wrong_shred_nodes { info!( - " {}% - {}", - stake * 100 / total_activated_stake, + " {:.3}% - {}", + (stake as f64 / total_activated_stake as f64) * 100., identity ); } @@ -1534,20 +1535,20 @@ fn get_stake_percent_in_gossip(bank: &Bank, cluster_info: &ClusterInfo, log: boo if !offline_nodes.is_empty() { info!( - "{}% of active stake is not visible in gossip", - offline_stake * 100 / total_activated_stake + "{:.3}% of active stake is not visible in gossip", + (offline_stake as f64 / total_activated_stake as f64) * 100. ); for (stake, identity) in offline_nodes { info!( - " {}% - {}", - stake * 100 / total_activated_stake, + " {:.3}% - {}", + (stake as f64 / total_activated_stake as f64) * 100., identity ); } } } - online_stake * 100 / total_activated_stake + online_stake_percentage as u64 } // Cleanup anything that looks like an accounts append-vec