CLI: Add arg to adjust RPC timeout

This commit is contained in:
Trent Nelson 2020-07-23 09:21:59 -06:00 committed by mergify[bot]
parent bece8cfbc2
commit 6f7e121b68
2 changed files with 26 additions and 3 deletions

View File

@ -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<RpcClient>,
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

View File

@ -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<bool, Box<dyn error::Error>> {
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<dyn error::Error>> {
.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")