Avoid panic caused by converting non-positive / non-normal floating points values to duration (#9867)

This commit is contained in:
Kristofer Peterson
2020-05-04 21:08:27 +01:00
committed by GitHub
parent f8ad3aca25
commit 3aedb81d48

View File

@ -481,14 +481,13 @@ pub fn process_catchup(
let slot_distance = rpc_slot as i64 - node_slot as i64; let slot_distance = rpc_slot as i64 - node_slot as i64;
let slots_per_second = let slots_per_second =
(previous_slot_distance - slot_distance) as f64 / f64::from(sleep_interval); (previous_slot_distance - slot_distance) as f64 / f64::from(sleep_interval);
let time_remaining = if slots_per_second <= 0.0 { let time_remaining = (slot_distance as f64 / slots_per_second).round();
let time_remaining = if !time_remaining.is_normal() || time_remaining <= 0.0 {
"".to_string() "".to_string()
} else { } else {
format!( format!(
". Time remaining: {}", ". Time remaining: {}",
humantime::format_duration(Duration::from_secs_f64( humantime::format_duration(Duration::from_secs_f64(time_remaining))
(slot_distance as f64 / slots_per_second).round()
))
) )
}; };