Skip to content

Commit

Permalink
feat(cast): add --rpc-timeout option (#9044)
Browse files Browse the repository at this point in the history
* feat: add timeout flag and override default rpc timeout value

* fix clippy

* fix: move timeout to rpc args

* refactor: move rpc timeout to RpcOpts

* clippy

* refactor unecessary code

* Apply suggestions from code review

Minor documentation nits

---------

Co-authored-by: zerosnacks <[email protected]>
  • Loading branch information
PanGan21 and zerosnacks authored Oct 24, 2024
1 parent bcef905 commit 2559899
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/cli/src/opts/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ pub struct RpcOpts {
/// "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc"]'
#[arg(long, env = "ETH_RPC_JWT_SECRET")]
pub jwt_secret: Option<String>,

/// Timeout for the RPC request in seconds.
///
/// The specified timeout will be used to override the default timeout for RPC requests.
///
/// Default value: 45
#[arg(long, env = "ETH_RPC_TIMEOUT")]
pub rpc_timeout: Option<u64>,
}

impl_figment_convert_cast!(RpcOpts);
Expand Down Expand Up @@ -84,6 +92,9 @@ impl RpcOpts {
if let Ok(Some(jwt)) = self.jwt(None) {
dict.insert("eth_rpc_jwt".into(), jwt.into_owned().into());
}
if let Some(rpc_timeout) = self.rpc_timeout {
dict.insert("eth_rpc_timeout".into(), rpc_timeout.into());
}
dict
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub fn get_provider_builder(config: &Config) -> Result<ProviderBuilder> {
builder = builder.jwt(jwt.as_ref());
}

if let Some(rpc_timeout) = config.eth_rpc_timeout {
builder = builder.timeout(Duration::from_secs(rpc_timeout));
}

Ok(builder)
}

Expand Down
3 changes: 3 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ pub struct Config {
pub eth_rpc_url: Option<String>,
/// JWT secret that should be used for any rpc calls
pub eth_rpc_jwt: Option<String>,
/// Timeout that should be used for any rpc calls
pub eth_rpc_timeout: Option<u64>,
/// etherscan API key, or alias for an `EtherscanConfig` in `etherscan` table
pub etherscan_api_key: Option<String>,
/// Multiple etherscan api configs and their aliases
Expand Down Expand Up @@ -2208,6 +2210,7 @@ impl Default for Config {
memory_limit: 1 << 27, // 2**27 = 128MiB = 134_217_728 bytes
eth_rpc_url: None,
eth_rpc_jwt: None,
eth_rpc_timeout: None,
etherscan_api_key: None,
verbosity: 0,
remappings: vec![],
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ forgetest!(can_extract_config_values, |prj, cmd| {
memory_limit: 1 << 27,
eth_rpc_url: Some("localhost".to_string()),
eth_rpc_jwt: None,
eth_rpc_timeout: None,
etherscan_api_key: None,
etherscan: Default::default(),
verbosity: 4,
Expand Down

0 comments on commit 2559899

Please sign in to comment.