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(bridge): add http request timeout to prevent requests over 6 minutes #1147

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions portal-bridge/src/api/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use surf_governor::GovernorMiddleware;
use url::Url;

use crate::{
cli::Provider, constants::SECONDS_IN_A_DAY, BASE_CL_ENDPOINT, PANDAOPS_CLIENT_ID,
PANDAOPS_CLIENT_SECRET,
cli::Provider,
constants::{HTTP_REQUEST_TIMEOUT, SECONDS_IN_A_DAY},
BASE_CL_ENDPOINT, PANDAOPS_CLIENT_ID, PANDAOPS_CLIENT_SECRET,
};

/// Implements endpoints from the Beacon API to access data from the consensus layer.
Expand All @@ -30,11 +31,13 @@ impl ConsensusApi {
)?
.add_header("Content-Type", "application/json")?
.set_base_url(base_cl_endpoint)
.set_timeout(Some(HTTP_REQUEST_TIMEOUT))
.try_into()?
}
Provider::Url(url) => Config::new()
.add_header("Content-Type", "application/json")?
.set_base_url(url)
.set_timeout(Some(HTTP_REQUEST_TIMEOUT))
.try_into()?,
Provider::Test => {
return Err(surf::Error::from(anyhow!(
Expand Down
4 changes: 3 additions & 1 deletion portal-bridge/src/api/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use url::Url;

use crate::{
cli::Provider,
constants::SECONDS_IN_A_DAY,
constants::{HTTP_REQUEST_TIMEOUT, SECONDS_IN_A_DAY},
types::{full_header::FullHeader, mode::BridgeMode},
BASE_EL_ARCHIVE_ENDPOINT, BASE_EL_ENDPOINT, PANDAOPS_CLIENT_ID, PANDAOPS_CLIENT_SECRET,
};
Expand Down Expand Up @@ -71,11 +71,13 @@ impl ExecutionApi {
PANDAOPS_CLIENT_SECRET.to_string(),
)?
.set_base_url(base_el_endpoint)
.set_timeout(Some(HTTP_REQUEST_TIMEOUT))
.try_into()?
}
Provider::Url(url) => Config::new()
.add_header("Content-Type", "application/json")?
.set_base_url(url.clone())
.set_timeout(Some(HTTP_REQUEST_TIMEOUT))
.try_into()?,
Provider::Test => Config::new().try_into()?,
};
Expand Down
6 changes: 6 additions & 0 deletions portal-bridge/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tokio::time::Duration;

// This number was chosen after some experimentation with different batch sizes.
// It was found that a batch size of 128 was the best compromise between speed and
// successful response rate. This number may change in the future.
Expand All @@ -14,3 +16,7 @@ pub const BEACON_GENESIS_TIME: u64 = 1606824023;

pub const PROVIDER_DAILY_REQUEST_LIMIT: f64 = 1_000_000.0;
pub const SECONDS_IN_A_DAY: f64 = 86400.0;

// This is a very conservative timeout if a provider takes longer than even 1 second it is probably
// overloaded and not performing well
pub const HTTP_REQUEST_TIMEOUT: Duration = Duration::from_secs(20);
Loading