From 6f7e121b684fbedb8a15101913a67e38293777aa Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Thu, 23 Jul 2020 09:21:59 -0600 Subject: [PATCH] CLI: Add arg to adjust RPC timeout --- cli/src/cli.rs | 7 ++++++- cli/src/main.rs | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 65b9b16bfb..ede5c7cf0c 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -63,6 +63,7 @@ use std::{ fs::File, io::{Read, Write}, net::{IpAddr, SocketAddr}, + str::FromStr, sync::Arc, thread::sleep, time::Duration, @@ -116,6 +117,7 @@ pub(crate) fn generate_unique_signers( } const DATA_CHUNK_SIZE: usize = 229; // Keep program chunks under PACKET_DATA_SIZE +pub const DEFAULT_RPC_TIMEOUT_SECONDS: &str = "30"; pub const FEE_PAYER_ARG: ArgConstant<'static> = ArgConstant { name: "fee_payer", @@ -495,6 +497,7 @@ pub struct CliConfig<'a> { pub signers: Vec<&'a dyn Signer>, pub keypair_path: String, pub rpc_client: Option, + pub rpc_timeout: Duration, pub verbose: bool, pub output_format: OutputFormat, pub commitment: CommitmentConfig, @@ -599,6 +602,7 @@ impl Default for CliConfig<'_> { signers: Vec::new(), keypair_path: Self::default_keypair_path(), rpc_client: None, + rpc_timeout: Duration::from_secs(u64::from_str(DEFAULT_RPC_TIMEOUT_SECONDS).unwrap()), verbose: false, output_format: OutputFormat::Display, commitment: CommitmentConfig::default(), @@ -1800,7 +1804,8 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { let mut _rpc_client; let rpc_client = if config.rpc_client.is_none() { - _rpc_client = RpcClient::new(config.json_rpc_url.to_string()); + _rpc_client = + RpcClient::new_with_timeout(config.json_rpc_url.to_string(), config.rpc_timeout); &_rpc_client } else { // Primarily for testing diff --git a/cli/src/main.rs b/cli/src/main.rs index d2006754a1..6014ee7e27 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -9,14 +9,17 @@ use solana_clap_utils::{ keypair::SKIP_SEED_PHRASE_VALIDATION_ARG, DisplayError, }; use solana_cli::{ - cli::{app, parse_command, process_command, CliCommandInfo, CliConfig, CliSigners}, + cli::{ + app, parse_command, process_command, CliCommandInfo, CliConfig, CliSigners, + DEFAULT_RPC_TIMEOUT_SECONDS, + }, cli_output::OutputFormat, display::{println_name_value, println_name_value_or}, }; use solana_cli_config::{Config, CONFIG_FILE}; use solana_client::rpc_config::RpcSendTransactionConfig; use solana_remote_wallet::remote_wallet::RemoteWalletManager; -use std::{collections::HashMap, error, path::PathBuf, sync::Arc}; +use std::{collections::HashMap, error, path::PathBuf, sync::Arc, time::Duration}; fn parse_settings(matches: &ArgMatches<'_>) -> Result> { let parse_args = match matches.subcommand() { @@ -126,6 +129,10 @@ pub fn parse_args<'a>( matches.value_of("json_rpc_url").unwrap_or(""), &config.json_rpc_url, ); + + let rpc_timeout = value_t_or_exit!(matches, "rpc_timeout", u64); + let rpc_timeout = Duration::from_secs(rpc_timeout); + let (_, websocket_url) = CliConfig::compute_websocket_url_setting( matches.value_of("websocket_url").unwrap_or(""), &config.websocket_url, @@ -169,6 +176,7 @@ pub fn parse_args<'a>( signers: vec![], keypair_path: default_signer_path, rpc_client: None, + rpc_timeout, verbose: matches.is_present("verbose"), output_format, commitment, @@ -256,6 +264,16 @@ fn main() -> Result<(), Box> { .global(true) .help(SKIP_SEED_PHRASE_VALIDATION_ARG.help), ) + .arg( + Arg::with_name("rpc_timeout") + .long("rpc-timeout") + .value_name("SECONDS") + .takes_value(true) + .default_value(DEFAULT_RPC_TIMEOUT_SECONDS) + .global(true) + .hidden(true) + .help("Timeout value for RPC requests"), + ) .subcommand( SubCommand::with_name("config") .about("Solana command-line tool configuration settings")