From 47ddb84078ae76265cfe2678dc10f34a27b8b68d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 2 Apr 2020 20:43:19 -0700 Subject: [PATCH] cli: Add --follow option to catchup command to allow for easy ongoing monitoring between two nodes (bp #9260) (#9278) automerge --- cli/src/cli.rs | 12 +++++++++++- cli/src/cluster_query.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 13dfa441b0..11e4c34816 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -173,6 +173,8 @@ pub enum CliCommand { Catchup { node_pubkey: Pubkey, node_json_rpc_url: Option, + commitment_config: CommitmentConfig, + follow: bool, }, ClusterVersion, CreateAddressWithSeed { @@ -1593,7 +1595,15 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { CliCommand::Catchup { node_pubkey, node_json_rpc_url, - } => process_catchup(&rpc_client, node_pubkey, node_json_rpc_url), + commitment_config, + follow, + } => process_catchup( + &rpc_client, + node_pubkey, + node_json_rpc_url, + *commitment_config, + *follow, + ), CliCommand::ClusterVersion => process_cluster_version(&rpc_client), CliCommand::CreateAddressWithSeed { from_pubkey, diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index a24e78a80d..7998a44c0c 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -69,6 +69,20 @@ impl ClusterQuerySubCommands for App<'_, '_> { .takes_value(true) .validator(is_url) .help("JSON RPC URL for validator, which is useful for validators with a private RPC service") + ) + .arg( + Arg::with_name("confirmed") + .long("confirmed") + .takes_value(false) + .help( + "Return information at maximum-lockout commitment level", + ), + ) + .arg( + Arg::with_name("follow") + .long("follow") + .takes_value(false) + .help("Continue reporting progress even after the validator has caught up"), ), ) .subcommand( @@ -273,10 +287,18 @@ pub fn parse_catchup( ) -> Result { let node_pubkey = pubkey_of_signer(matches, "node_pubkey", wallet_manager)?.unwrap(); let node_json_rpc_url = value_t!(matches, "node_json_rpc_url", String).ok(); + let commitment_config = if matches.is_present("confirmed") { + CommitmentConfig::default() + } else { + CommitmentConfig::recent() + }; + let follow = matches.is_present("follow"); Ok(CliCommandInfo { command: CliCommand::Catchup { node_pubkey, node_json_rpc_url, + commitment_config, + follow, }, signers: vec![], }) @@ -432,6 +454,8 @@ pub fn process_catchup( rpc_client: &RpcClient, node_pubkey: &Pubkey, node_json_rpc_url: &Option, + commitment_config: CommitmentConfig, + follow: bool, ) -> ProcessResult { let sleep_interval = 5; @@ -479,9 +503,9 @@ pub fn process_catchup( let mut previous_rpc_slot = std::u64::MAX; let mut previous_slot_distance = 0; loop { - let rpc_slot = rpc_client.get_slot_with_commitment(CommitmentConfig::recent())?; - let node_slot = node_client.get_slot_with_commitment(CommitmentConfig::recent())?; - if node_slot > std::cmp::min(previous_rpc_slot, rpc_slot) { + let rpc_slot = rpc_client.get_slot_with_commitment(commitment_config)?; + let node_slot = node_client.get_slot_with_commitment(commitment_config)?; + if !follow && node_slot > std::cmp::min(previous_rpc_slot, rpc_slot) { progress_bar.finish_and_clear(); return Ok(format!( "{} has caught up (us:{} them:{})", @@ -495,7 +519,7 @@ pub fn process_catchup( slot_distance, node_slot, rpc_slot, - if previous_rpc_slot == std::u64::MAX { + if slot_distance == 0 || previous_rpc_slot == std::u64::MAX { "".to_string() } else { let slots_per_second =