From 298b7de2e264e6adddf2f4b65d9dc3b02947110e Mon Sep 17 00:00:00 2001 From: Grimes <39311140+solana-grimes@users.noreply.github.com> Date: Wed, 4 Mar 2020 12:48:18 -0800 Subject: [PATCH] `catchup` now supports an optional RPC URL argument for validators with private RPC (#8629) (#8633) 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 f484ffc507..89102111b4 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 aa66ec40ad..f614868c92 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -59,6 +59,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( @@ -237,8 +245,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![], }) } @@ -361,20 +373,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;