Add leader-schedule subcommand
This commit is contained in:
@ -193,6 +193,7 @@ pub enum CliCommand {
|
|||||||
GetTransactionCount {
|
GetTransactionCount {
|
||||||
commitment_config: CommitmentConfig,
|
commitment_config: CommitmentConfig,
|
||||||
},
|
},
|
||||||
|
LeaderSchedule,
|
||||||
Ping {
|
Ping {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
interval: Duration,
|
interval: Duration,
|
||||||
@ -456,6 +457,10 @@ pub fn parse_command(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Box<dyn
|
|||||||
}),
|
}),
|
||||||
("slot", Some(matches)) => parse_get_slot(matches),
|
("slot", Some(matches)) => parse_get_slot(matches),
|
||||||
("transaction-count", Some(matches)) => parse_get_transaction_count(matches),
|
("transaction-count", Some(matches)) => parse_get_transaction_count(matches),
|
||||||
|
("leader-schedule", Some(_matches)) => Ok(CliCommandInfo {
|
||||||
|
command: CliCommand::LeaderSchedule,
|
||||||
|
require_keypair: false,
|
||||||
|
}),
|
||||||
("ping", Some(matches)) => parse_cluster_ping(matches),
|
("ping", Some(matches)) => parse_cluster_ping(matches),
|
||||||
("block-production", Some(matches)) => parse_show_block_production(matches),
|
("block-production", Some(matches)) => parse_show_block_production(matches),
|
||||||
("gossip", Some(_matches)) => Ok(CliCommandInfo {
|
("gossip", Some(_matches)) => Ok(CliCommandInfo {
|
||||||
@ -1261,6 +1266,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
|||||||
CliCommand::GetTransactionCount { commitment_config } => {
|
CliCommand::GetTransactionCount { commitment_config } => {
|
||||||
process_get_transaction_count(&rpc_client, commitment_config)
|
process_get_transaction_count(&rpc_client, commitment_config)
|
||||||
}
|
}
|
||||||
|
CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client),
|
||||||
CliCommand::Ping {
|
CliCommand::Ping {
|
||||||
lamports,
|
lamports,
|
||||||
interval,
|
interval,
|
||||||
|
@ -67,6 +67,7 @@ impl ClusterQuerySubCommands for App<'_, '_> {
|
|||||||
.help("Slot number of the block to query")
|
.help("Slot number of the block to query")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.subcommand(SubCommand::with_name("leader-schedule").about("Display leader schedule"))
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("epoch-info")
|
SubCommand::with_name("epoch-info")
|
||||||
.about("Get information about the current epoch")
|
.about("Get information about the current epoch")
|
||||||
@ -406,6 +407,41 @@ pub fn process_fees(rpc_client: &RpcClient) -> ProcessResult {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process_leader_schedule(rpc_client: &RpcClient) -> ProcessResult {
|
||||||
|
let epoch_info = rpc_client.get_epoch_info()?;
|
||||||
|
let first_slot_in_epoch = epoch_info.absolute_slot - epoch_info.slot_index;
|
||||||
|
|
||||||
|
let leader_schedule = rpc_client.get_leader_schedule(Some(first_slot_in_epoch))?;
|
||||||
|
if leader_schedule.is_none() {
|
||||||
|
return Err(format!(
|
||||||
|
"Unable to fetch leader schedule for slot {}",
|
||||||
|
first_slot_in_epoch
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
let leader_schedule = leader_schedule.unwrap();
|
||||||
|
|
||||||
|
let mut leader_per_slot_index = Vec::new();
|
||||||
|
for (pubkey, leader_slots) in leader_schedule.iter() {
|
||||||
|
for slot_index in leader_slots.iter() {
|
||||||
|
if *slot_index >= leader_per_slot_index.len() {
|
||||||
|
leader_per_slot_index.resize(*slot_index + 1, "?");
|
||||||
|
}
|
||||||
|
leader_per_slot_index[*slot_index] = pubkey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (slot_index, leader) in leader_per_slot_index.iter().enumerate() {
|
||||||
|
println!(
|
||||||
|
" {:<15} {:<44}",
|
||||||
|
first_slot_in_epoch + slot_index as u64,
|
||||||
|
leader
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok("".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_get_block_time(rpc_client: &RpcClient, slot: Slot) -> ProcessResult {
|
pub fn process_get_block_time(rpc_client: &RpcClient, slot: Slot) -> ProcessResult {
|
||||||
let timestamp = rpc_client.get_block_time(slot)?;
|
let timestamp = rpc_client.get_block_time(slot)?;
|
||||||
Ok(timestamp.to_string())
|
Ok(timestamp.to_string())
|
||||||
|
Reference in New Issue
Block a user