Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
catchup now supports an optional RPC URL argument for validators wi…
Browse files Browse the repository at this point in the history
…th private RPC (#8629)

automerge
  • Loading branch information
solana-grimes authored Mar 4, 2020
1 parent 408d5da commit 09a0325
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
6 changes: 5 additions & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub enum CliCommand {
// Cluster Query Commands
Catchup {
node_pubkey: Pubkey,
node_json_rpc_url: Option<String>,
},
ClusterVersion,
CreateAddressWithSeed {
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 30 additions & 9 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -238,8 +246,12 @@ impl ClusterQuerySubCommands for App<'_, '_> {

pub fn parse_catchup(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
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![],
})
}
Expand Down Expand Up @@ -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<String>,
) -> 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;
Expand Down

0 comments on commit 09a0325

Please sign in to comment.