Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cast): add --rpc-timeout option #9044

Merged
merged 14 commits into from
Oct 24, 2024
Merged
10 changes: 10 additions & 0 deletions crates/cli/src/opts/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub struct RpcOpts {
/// "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc"]'
#[arg(long, env = "ETH_RPC_JWT_SECRET")]
pub jwt_secret: Option<String>,

/// Timeout for the rpc request
///
/// The rpc-timeout will be used to override the default timeout for RPC.
/// Default value is 45s
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long, env = "ETH_RPC_TIMEOUT")]
pub rpc_timeout: Option<u64>,
}

impl_figment_convert_cast!(RpcOpts);
Expand Down Expand Up @@ -84,6 +91,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>,
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
/// 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
Loading