From 09a0325534a34234a7b648c44d40597dcd76aadd Mon Sep 17 00:00:00 2001 From: Grimes <39311140+solana-grimes@users.noreply.github.com> Date: Wed, 4 Mar 2020 11:44:13 -0800 Subject: [PATCH] `catchup` now supports an optional RPC URL argument for validators with private RPC (#8629) automerge --- cli/src/cli.rs | 6 +++++- cli/src/cluster_query.rs | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d3efaf539..42ef1f843 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -167,6 +167,7 @@ pub enum CliCommand { // Cluster Query Commands Catchup { node_pubkey: Pubkey, + node_json_rpc_url: Option, }, ClusterVersion, CreateAddressWithSeed { @@ -1550,7 +1551,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { CliCommand::Address => Ok(format!("{}", config.pubkey()?)), // Return software version of solana-cli and cluster entrypoint node - CliCommand::Catchup { node_pubkey } => process_catchup(&rpc_client, node_pubkey), + CliCommand::Catchup { + node_pubkey, + node_json_rpc_url, + } => process_catchup(&rpc_client, node_pubkey, node_json_rpc_url), 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 e90879ae3..f156d0983 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -60,6 +60,14 @@ impl ClusterQuerySubCommands for App<'_, '_> { .validator(is_pubkey_or_keypair) .required(true) .help("Identity pubkey of the validator"), + ) + .arg( + Arg::with_name("node_json_rpc_url") + .index(2) + .value_name("URL") + .takes_value(true) + .validator(is_url) + .help("JSON RPC URL for validator, which is useful for validators with a private RPC service") ), ) .subcommand( @@ -238,8 +246,12 @@ impl ClusterQuerySubCommands for App<'_, '_> { pub fn parse_catchup(matches: &ArgMatches<'_>) -> Result { let node_pubkey = pubkey_of(matches, "node_pubkey").unwrap(); + let node_json_rpc_url = value_t!(matches, "node_json_rpc_url", String).ok(); Ok(CliCommandInfo { - command: CliCommand::Catchup { node_pubkey }, + command: CliCommand::Catchup { + node_pubkey, + node_json_rpc_url, + }, signers: vec![], }) } @@ -362,20 +374,29 @@ fn new_spinner_progress_bar() -> ProgressBar { progress_bar } -pub fn process_catchup(rpc_client: &RpcClient, node_pubkey: &Pubkey) -> ProcessResult { +pub fn process_catchup( + rpc_client: &RpcClient, + node_pubkey: &Pubkey, + node_json_rpc_url: &Option, +) -> ProcessResult { let cluster_nodes = rpc_client.get_cluster_nodes()?; - let rpc_addr = cluster_nodes - .iter() - .find(|contact_info| contact_info.pubkey == node_pubkey.to_string()) - .ok_or_else(|| format!("Contact information not found for {}", node_pubkey))? - .rpc - .ok_or_else(|| format!("RPC service not found for {}", node_pubkey))?; + let node_client = if let Some(node_json_rpc_url) = node_json_rpc_url { + RpcClient::new(node_json_rpc_url.to_string()) + } else { + RpcClient::new_socket( + cluster_nodes + .iter() + .find(|contact_info| contact_info.pubkey == node_pubkey.to_string()) + .ok_or_else(|| format!("Contact information not found for {}", node_pubkey))? + .rpc + .ok_or_else(|| format!("RPC service not found for {}", node_pubkey))?, + ) + }; let progress_bar = new_spinner_progress_bar(); progress_bar.set_message("Connecting..."); - let node_client = RpcClient::new_socket(rpc_addr); let mut previous_rpc_slot = std::u64::MAX; let mut previous_slot_distance = 0; let sleep_interval = 5;