diff --git a/eth2/utils/remote_beacon_node/src/lib.rs b/eth2/utils/remote_beacon_node/src/lib.rs index e42fbda27f..50dcff59f6 100644 --- a/eth2/utils/remote_beacon_node/src/lib.rs +++ b/eth2/utils/remote_beacon_node/src/lib.rs @@ -35,9 +35,14 @@ pub struct RemoteBeaconNode { } impl RemoteBeaconNode { + /// Uses the default HTTP timeout. pub fn new(http_endpoint: String) -> Result { + Self::new_with_timeout(http_endpoint, Duration::from_secs(REQUEST_TIMEOUT_SECONDS)) + } + + pub fn new_with_timeout(http_endpoint: String, timeout: Duration) -> Result { Ok(Self { - http: HttpClient::new(http_endpoint) + http: HttpClient::new(http_endpoint, timeout) .map_err(|e| format!("Unable to create http client: {:?}", e))?, }) } @@ -65,12 +70,10 @@ pub struct HttpClient { impl HttpClient { /// Creates a new instance (without connecting to the node). - /// - /// The `timeout` is set to 15 seconds. - pub fn new(server_url: String) -> Result { + pub fn new(server_url: String, timeout: Duration) -> Result { Ok(Self { client: ClientBuilder::new() - .timeout(Duration::from_secs(REQUEST_TIMEOUT_SECONDS)) + .timeout(timeout) .build() .expect("should build from static configuration"), url: Url::parse(&server_url)?, diff --git a/validator_client/src/lib.rs b/validator_client/src/lib.rs index 7c5b787d87..52f6360ac9 100644 --- a/validator_client/src/lib.rs +++ b/validator_client/src/lib.rs @@ -34,8 +34,12 @@ use tokio::timer::Delay; use types::EthSpec; use validator_store::ValidatorStore; +/// The interval between attempts to contact the beacon node during startup. const RETRY_DELAY: Duration = Duration::from_secs(2); +/// The global timeout for HTTP events. +const HTTP_TIMEOUT: Duration = Duration::from_secs(12); + #[derive(Clone)] pub struct ProductionValidatorClient { context: RuntimeContext, @@ -76,7 +80,7 @@ impl ProductionValidatorClient { "datadir" => format!("{:?}", config.data_dir), ); - RemoteBeaconNode::new(config.http_server.clone()) + RemoteBeaconNode::new_with_timeout(config.http_server.clone(), HTTP_TIMEOUT) .map_err(|e| format!("Unable to init beacon node http client: {}", e)) .into_future() .and_then(move |beacon_node| wait_for_node(beacon_node, log_2))