From 717f56f72559a5e8cefb60fa73f481e031230fbc Mon Sep 17 00:00:00 2001 From: njgheorghita Date: Fri, 9 Feb 2024 15:56:25 -0500 Subject: [PATCH] fix(bridge): remove http request rate limiter --- Cargo.lock | 77 ---------------------- ethportal-peertest/src/scenarios/bridge.rs | 8 +-- portal-bridge/Cargo.toml | 1 - portal-bridge/src/api/consensus.rs | 12 +--- portal-bridge/src/api/execution.rs | 17 +---- portal-bridge/src/cli.rs | 15 ----- portal-bridge/src/constants.rs | 1 - portal-bridge/src/main.rs | 15 ++--- src/bin/test_providers.rs | 2 +- 9 files changed, 13 insertions(+), 135 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f1cd8b0f..d2b7c1917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3014,24 +3014,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "governor" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "821239e5672ff23e2a7060901fa622950bbd80b649cdaadd78d1c1767ed14eb4" -dependencies = [ - "cfg-if 1.0.0", - "dashmap", - "futures 0.3.30", - "futures-timer", - "no-std-compat", - "nonzero_ext", - "parking_lot 0.12.1", - "quanta", - "rand 0.8.5", - "smallvec 1.12.0", -] - [[package]] name = "group" version = "0.13.0" @@ -4033,15 +4015,6 @@ dependencies = [ "hashbrown 0.14.3", ] -[[package]] -name = "mach2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" -dependencies = [ - "libc", -] - [[package]] name = "matchers" version = "0.1.0" @@ -4256,12 +4229,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" -[[package]] -name = "no-std-compat" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" - [[package]] name = "nom" version = "5.1.3" @@ -4283,12 +4250,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nonzero_ext" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4863,7 +4824,6 @@ dependencies = [ "snap", "ssz_types", "surf", - "surf-governor", "test-log", "tokio", "tracing", @@ -5092,22 +5052,6 @@ dependencies = [ "unarray", ] -[[package]] -name = "quanta" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17e662a7a8291a865152364c20c7abc5e60486ab2001e8ec10b24862de0b9ab" -dependencies = [ - "crossbeam-utils 0.8.19", - "libc", - "mach2", - "once_cell", - "raw-cpuid", - "wasi 0.11.0+wasi-snapshot-preview1", - "web-sys", - "winapi 0.3.9", -] - [[package]] name = "quickcheck" version = "1.0.3" @@ -5352,15 +5296,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "raw-cpuid" -version = "10.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "rayon" version = "1.8.0" @@ -6877,18 +6812,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "surf-governor" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5072d041267e6b28a6a75a8737a03660ccc7fe8d9d70e8176388206a1e356fb8" -dependencies = [ - "governor", - "http-types", - "lazy_static", - "surf", -] - [[package]] name = "svm-rs" version = "0.3.3" diff --git a/ethportal-peertest/src/scenarios/bridge.rs b/ethportal-peertest/src/scenarios/bridge.rs index 05d236dea..1f5773426 100644 --- a/ethportal-peertest/src/scenarios/bridge.rs +++ b/ethportal-peertest/src/scenarios/bridge.rs @@ -10,7 +10,6 @@ use portal_bridge::{ api::{consensus::ConsensusApi, execution::ExecutionApi}, bridge::{beacon::BeaconBridge, history::HistoryBridge}, cli::Provider, - constants::PROVIDER_DAILY_REQUEST_LIMIT, types::mode::BridgeMode, }; use serde_json::Value; @@ -24,10 +23,9 @@ pub async fn test_history_bridge(peertest: &Peertest, target: &HttpClient) { let portal_clients = vec![target.clone()]; let epoch_acc_path = "validation_assets/epoch_acc.bin".into(); let mode = BridgeMode::Test("./test_assets/portalnet/bridge_data.json".into()); - let execution_api = - ExecutionApi::new(Provider::Test, mode.clone(), PROVIDER_DAILY_REQUEST_LIMIT) - .await - .unwrap(); + let execution_api = ExecutionApi::new(Provider::Test, mode.clone()) + .await + .unwrap(); // Wait for bootnode to start sleep(Duration::from_secs(1)).await; let bridge = HistoryBridge::new( diff --git a/portal-bridge/Cargo.toml b/portal-bridge/Cargo.toml index ad836ea97..ed7b882a7 100644 --- a/portal-bridge/Cargo.toml +++ b/portal-bridge/Cargo.toml @@ -39,7 +39,6 @@ serde_yaml = "0.9" snap = "1.1.1" ssz_types = "0.5.4" surf = { version = "2.3.2", default-features = false, features = ["h1-client-rustls", "middleware-logger", "encoding"] } # we use rustils because OpenSSL cause issues compiling on aarch64 -surf-governor = "0.2.0" tokio = { version = "1.14.0", features = ["full"] } tracing = "0.1.36" tracing-subscriber = "0.3.15" diff --git a/portal-bridge/src/api/consensus.rs b/portal-bridge/src/api/consensus.rs index 9a6924749..7b9617aed 100644 --- a/portal-bridge/src/api/consensus.rs +++ b/portal-bridge/src/api/consensus.rs @@ -1,8 +1,7 @@ -use std::{fmt::Display, num::NonZeroU32}; +use std::fmt::Display; use anyhow::anyhow; use surf::{Client, Config}; -use surf_governor::GovernorMiddleware; use tracing::debug; use url::Url; @@ -18,7 +17,7 @@ pub struct ConsensusApi { } impl ConsensusApi { - pub async fn new(provider: Provider, daily_request_limit: u64) -> Result { + pub async fn new(provider: Provider) -> Result { let client: Client = match provider { Provider::PandaOps => { let base_cl_endpoint = Url::parse(&BASE_CL_ENDPOINT) @@ -45,13 +44,6 @@ impl ConsensusApi { ))) } }; - // Limits the number of requests sent to the CL provider in a day - let hourly_request_limit = NonZeroU32::new(daily_request_limit as u32 / 24_u32).ok_or( - anyhow!("Invalid daily request limit, must be greater than 0"), - )?; - let rate_limit = GovernorMiddleware::per_hour(hourly_request_limit) - .expect("Expect GovernerMiddleware should have received a valid Duration"); - let client = client.with(rate_limit); debug!( "Starting ConsensusApi with provider at url: {:?}", client.config().base_url diff --git a/portal-bridge/src/api/execution.rs b/portal-bridge/src/api/execution.rs index 0b7b0a1ac..d67639866 100644 --- a/portal-bridge/src/api/execution.rs +++ b/portal-bridge/src/api/execution.rs @@ -1,4 +1,4 @@ -use std::{num::NonZeroU32, sync::Arc}; +use std::sync::Arc; use anyhow::{anyhow, bail}; use ethereum_types::H256; @@ -8,7 +8,6 @@ use surf::{ middleware::{Middleware, Next}, Body, Client, Config, Request, Response, }; -use surf_governor::GovernorMiddleware; use tokio::time::{sleep, Duration}; use tracing::{debug, warn}; use url::Url; @@ -50,11 +49,7 @@ pub struct ExecutionApi { } impl ExecutionApi { - pub async fn new( - provider: Provider, - mode: BridgeMode, - daily_request_limit: u64, - ) -> Result { + pub async fn new(provider: Provider, mode: BridgeMode) -> Result { let client: Client = match &provider { Provider::PandaOps => { let endpoint = match mode { @@ -81,13 +76,7 @@ impl ExecutionApi { .try_into()?, Provider::Test => Config::new().try_into()?, }; - // Limits the number of requests sent to the EL provider in a day - let hourly_request_limit = NonZeroU32::new(daily_request_limit as u32 / 24_u32).ok_or( - anyhow!("Invalid daily request limit, must be greater than 0"), - )?; - let rate_limit = GovernorMiddleware::per_hour(hourly_request_limit) - .expect("Expect GovernerMiddleware should have received a valid Duration"); - let client = client.with(rate_limit).with(Retry::default()); + let client = client.with(Retry::default()); // Only check that provider is connected & available if not using a test provider. debug!( "Starting ExecutionApi with provider at url: {:?}", diff --git a/portal-bridge/src/cli.rs b/portal-bridge/src/cli.rs index 2e3cdec8d..8d344ec92 100644 --- a/portal-bridge/src/cli.rs +++ b/portal-bridge/src/cli.rs @@ -8,7 +8,6 @@ use url::Url; use crate::{ client_handles::{fluffy_handle, trin_handle}, - constants::PROVIDER_DAILY_REQUEST_LIMIT, types::{mode::BridgeMode, network::NetworkKind}, }; @@ -93,20 +92,6 @@ pub struct BridgeConfig { help = "Data provider for consensus layer data. (\"pandaops\" / local node url)" )] pub cl_provider: Provider, - - #[arg( - long = "el-provider-daily-request-limit", - help = "Maximum number of requests execution layer sent to the provider in a day.", - default_value_t = PROVIDER_DAILY_REQUEST_LIMIT, - )] - pub el_provider_daily_request_limit: u64, - - #[arg( - long = "cl-provider-daily-request-limit", - help = "Maximum number of requests consensus layer sent to the provider in a day.", - default_value_t = PROVIDER_DAILY_REQUEST_LIMIT, - )] - pub cl_provider_daily_request_limit: u64, } fn check_node_count(val: &str) -> Result { diff --git a/portal-bridge/src/constants.rs b/portal-bridge/src/constants.rs index 3b5cff299..fe1639bc9 100644 --- a/portal-bridge/src/constants.rs +++ b/portal-bridge/src/constants.rs @@ -17,4 +17,3 @@ pub const BEACON_GENESIS_TIME: u64 = 1606824023; // 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); -pub const PROVIDER_DAILY_REQUEST_LIMIT: u64 = 1_000_000; diff --git a/portal-bridge/src/main.rs b/portal-bridge/src/main.rs index c54aac031..4fbbbdeef 100644 --- a/portal-bridge/src/main.rs +++ b/portal-bridge/src/main.rs @@ -62,11 +62,7 @@ async fn main() -> Result<(), Box> { let portal_clients = portal_clients .clone() .expect("Failed to create beacon JSON-RPC clients"); - let consensus_api = ConsensusApi::new( - bridge_config.cl_provider, - bridge_config.cl_provider_daily_request_limit, - ) - .await?; + let consensus_api = ConsensusApi::new(bridge_config.cl_provider).await?; let bridge_handle = tokio::spawn(async move { let beacon_bridge = BeaconBridge::new(consensus_api, bridge_mode, Arc::new(portal_clients)); @@ -102,12 +98,9 @@ async fn main() -> Result<(), Box> { bridge_tasks.push(bridge_handle); } _ => { - let execution_api = ExecutionApi::new( - bridge_config.el_provider, - bridge_config.mode.clone(), - bridge_config.el_provider_daily_request_limit, - ) - .await?; + let execution_api = + ExecutionApi::new(bridge_config.el_provider, bridge_config.mode.clone()) + .await?; let bridge_handle = tokio::spawn(async move { let master_acc = MasterAccumulator::default(); let header_oracle = HeaderOracle::new(master_acc); diff --git a/src/bin/test_providers.rs b/src/bin/test_providers.rs index 292b24fba..806db27c6 100644 --- a/src/bin/test_providers.rs +++ b/src/bin/test_providers.rs @@ -43,7 +43,7 @@ use trin_validation::{ pub async fn main() -> Result<()> { init_tracing_logger(); let config = ProviderConfig::parse(); - let api = ExecutionApi::new(Provider::PandaOps, BridgeMode::Latest, 100000) + let api = ExecutionApi::new(Provider::PandaOps, BridgeMode::Latest) .await .unwrap(); let latest_block = api.get_latest_block_number().await?;