From e710964d057826c2edb7632e28e78f96932eeb53 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Fri, 17 Jan 2020 09:39:47 +0900 Subject: [PATCH] Revamp the progress of current epoch in get-epoch-info (#7838) * Revamp the progress of current epoch in get-epoch-info * Incorporate suggested more concise labelling --- cli/src/cluster_query.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index f25f9db818..ccc8eba3be 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -369,30 +369,44 @@ pub fn process_get_block_time(rpc_client: &RpcClient, slot: Slot) -> ProcessResu Ok(timestamp.to_string()) } +fn slot_to_human_time(slot: Slot) -> String { + humantime::format_duration(Duration::from_secs( + slot * clock::DEFAULT_TICKS_PER_SLOT / clock::DEFAULT_TICKS_PER_SECOND, + )) + .to_string() +} + pub fn process_get_epoch_info( rpc_client: &RpcClient, commitment_config: &CommitmentConfig, ) -> ProcessResult { let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?; println!(); - println_name_value("Current epoch:", &epoch_info.epoch.to_string()); - println_name_value("Current slot:", &epoch_info.absolute_slot.to_string()); + println_name_value("Slot:", &epoch_info.absolute_slot.to_string()); + println_name_value("Epoch:", &epoch_info.epoch.to_string()); println_name_value( - "Total slots in current epoch:", - &epoch_info.slots_in_epoch.to_string(), + "Epoch completed percent:", + &format!( + "{:>3.3}%", + epoch_info.slot_index as f64 / epoch_info.slots_in_epoch as f64 * 100_f64 + ), ); let remaining_slots_in_epoch = epoch_info.slots_in_epoch - epoch_info.slot_index; println_name_value( - "Remaining slots in current epoch:", - &remaining_slots_in_epoch.to_string(), - ); - - let remaining_time_in_epoch = Duration::from_secs( - remaining_slots_in_epoch * clock::DEFAULT_TICKS_PER_SLOT / clock::DEFAULT_TICKS_PER_SECOND, + "Epoch completed slots:", + &format!( + "{}/{} ({} remaining)", + epoch_info.slot_index, epoch_info.slots_in_epoch, remaining_slots_in_epoch + ), ); println_name_value( - "Time remaining in current epoch:", - &humantime::format_duration(remaining_time_in_epoch).to_string(), + "Epoch completed time:", + &format!( + "{}/{} ({} remaining)", + slot_to_human_time(epoch_info.slot_index), + slot_to_human_time(epoch_info.slots_in_epoch), + slot_to_human_time(remaining_slots_in_epoch) + ), ); Ok("".to_string()) }