Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

token-cli: Add confirm-tx timeout to RPC client #7484

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions token/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use {
},
token::ComputeUnitLimit,
},
std::{process::exit, rc::Rc, str::FromStr, sync::Arc},
std::{process::exit, rc::Rc, str::FromStr, sync::Arc, time::Duration},
};

type SignersOf = Vec<(Arc<dyn Signer>, Pubkey)>;
Expand Down Expand Up @@ -55,6 +55,9 @@ pub(crate) struct MintInfo {
pub decimals: u8,
}

const DEFAULT_RPC_TIMEOUT: Duration = Duration::from_secs(30);
const DEFAULT_CONFIRM_TX_TIMEOUT: Duration = Duration::from_secs(5);

pub struct Config<'a> {
pub default_signer: Option<Arc<dyn Signer>>,
pub rpc_client: Arc<RpcClient>,
Expand Down Expand Up @@ -97,9 +100,11 @@ impl<'a> Config<'a> {
.unwrap_or(&cli_config.json_rpc_url),
);
let websocket_url = solana_cli_config::Config::compute_websocket_url(&json_rpc_url);
let rpc_client = Arc::new(RpcClient::new_with_commitment(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the old behavior when these default timeouts are not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 seconds for rpc (which is what this PR uses), and none for the other one, which is why I thought it was the issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, does at none effectively mean we have a timeout of zero, i.e. we'll only check once and never check again for transaction confirmation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: Seems reasonable to me. Is there a way for the client to override this default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not with this PR. I wanted to keep it simple here, and only add a command-line arg if anyone ever needs it in the future

let rpc_client = Arc::new(RpcClient::new_with_timeouts_and_commitment(
json_rpc_url,
DEFAULT_RPC_TIMEOUT,
CommitmentConfig::confirmed(),
DEFAULT_CONFIRM_TX_TIMEOUT,
));
let sign_only = matches.is_present(SIGN_ONLY_ARG.name);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = if sign_only {
Expand Down
Loading