diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index c4e8f08875df..b858d998fafb 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -40,6 +40,14 @@ pub struct RpcOpts { /// "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc"]' #[arg(long, env = "ETH_RPC_JWT_SECRET")] pub jwt_secret: Option, + + /// 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, } impl_figment_convert_cast!(RpcOpts); @@ -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 } } diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index 8aa56aab8c41..2d8471e62685 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -106,6 +106,10 @@ pub fn get_provider_builder(config: &Config) -> Result { 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) } diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index d70a8dab401f..2a75f3b23c72 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -238,6 +238,8 @@ pub struct Config { pub eth_rpc_url: Option, /// JWT secret that should be used for any rpc calls pub eth_rpc_jwt: Option, + /// Timeout that should be used for any rpc calls + pub eth_rpc_timeout: Option, /// etherscan API key, or alias for an `EtherscanConfig` in `etherscan` table pub etherscan_api_key: Option, /// Multiple etherscan api configs and their aliases @@ -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![], diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index 491171cad165..f492de01d1f3 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -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,