From 7df124012c4be8182c7f33670ebf0480da0db040 Mon Sep 17 00:00:00 2001 From: davidrusu Date: Thu, 5 Feb 2026 13:57:51 +0400 Subject: [PATCH] feat(api): remove rate-limits from Node API (#2124) --- Cargo.lock | 2 -- nodes/api-common/Cargo.toml | 2 -- nodes/api-common/src/lib.rs | 1 - nodes/api-common/src/settings.rs | 19 ------------------ nodes/api-common/src/utils.rs | 21 -------------------- nodes/node/binary/src/api/backend.rs | 3 +-- nodes/node/binary/src/api/testing/backend.rs | 3 +-- nodes/node/config-one-node.yaml | 4 ---- tests/src/nodes/validator.rs | 4 ---- 9 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 nodes/api-common/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index ab7abcf61..3558f27fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4831,7 +4831,6 @@ name = "logos-blockchain-http-api-common" version = "0.1.0" dependencies = [ "axum 0.7.9", - "governor", "logos-blockchain-core 0.1.0", "logos-blockchain-key-management-system-keys 0.1.0", "pprof", @@ -4839,7 +4838,6 @@ dependencies = [ "serde_json", "serde_with", "tokio", - "tower_governor", "tracing", ] diff --git a/nodes/api-common/Cargo.toml b/nodes/api-common/Cargo.toml index f79d756b7..85fd09e22 100644 --- a/nodes/api-common/Cargo.toml +++ b/nodes/api-common/Cargo.toml @@ -14,14 +14,12 @@ workspace = true [dependencies] axum = { default-features = false, features = ["http1", "http2", "json", "query", "tokio"], version = "0.7.5" } -governor = { default-features = false, version = "0.6" } lb-core = { workspace = true } lb-key-management-system-keys = { workspace = true } serde = { features = ["alloc", "derive"], workspace = true } serde_json = { workspace = true } serde_with = { default-features = false, features = ["macros"], workspace = true } tokio = { default-features = false, features = ["time"], optional = true, version = "1" } -tower_governor = { default-features = false, features = ["axum"], version = "0.3" } tracing = { default-features = false, optional = true, workspace = true } [target.'cfg(not(windows))'.dependencies] diff --git a/nodes/api-common/src/lib.rs b/nodes/api-common/src/lib.rs index e4c766fc5..3a327a42d 100644 --- a/nodes/api-common/src/lib.rs +++ b/nodes/api-common/src/lib.rs @@ -3,7 +3,6 @@ pub mod paths; #[cfg(feature = "profiling")] pub mod pprof; pub mod settings; -pub mod utils; #[cfg(all(feature = "profiling", target_os = "windows"))] compile_error!( diff --git a/nodes/api-common/src/settings.rs b/nodes/api-common/src/settings.rs index e265618dd..bc7985c11 100644 --- a/nodes/api-common/src/settings.rs +++ b/nodes/api-common/src/settings.rs @@ -18,15 +18,6 @@ pub struct AxumBackendSettings { /// Maximum number of concurrent requests #[serde(default = "default_max_concurrent_requests")] pub max_concurrent_requests: usize, - /// Set the interval after which one element of the quota is replenished in - /// seconds. - #[serde(default = "default_rate_limit_per_second")] - pub rate_limit_per_second: u64, - /// Set quota size that defines how many requests can occur before the - /// governor middleware starts blocking requests from an IP address and - /// clients have to wait until the elements of the quota are replenished. - #[serde(default = "default_rate_limit_burst")] - pub rate_limit_burst: u32, } impl Default for AxumBackendSettings { @@ -37,8 +28,6 @@ impl Default for AxumBackendSettings { timeout: default_timeout(), max_body_size: default_max_body_size(), max_concurrent_requests: default_max_concurrent_requests(), - rate_limit_per_second: default_rate_limit_per_second(), - rate_limit_burst: default_rate_limit_burst(), } } } @@ -54,11 +43,3 @@ const fn default_max_body_size() -> usize { const fn default_max_concurrent_requests() -> usize { 500 } - -const fn default_rate_limit_per_second() -> u64 { - 100 -} - -const fn default_rate_limit_burst() -> u32 { - 20 -} diff --git a/nodes/api-common/src/utils.rs b/nodes/api-common/src/utils.rs deleted file mode 100644 index 6000e4431..000000000 --- a/nodes/api-common/src/utils.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::settings::AxumBackendSettings; - -type DefaultGovernorLayer = tower_governor::GovernorLayer< - 'static, - tower_governor::key_extractor::PeerIpKeyExtractor, - governor::middleware::NoOpMiddleware, ->; - -/// Create a `GovernorLayer` for rate limiting based on the settings -#[must_use] -pub fn create_rate_limit_layer(settings: &AxumBackendSettings) -> DefaultGovernorLayer { - tower_governor::GovernorLayer { - config: Box::leak(Box::new( - tower_governor::governor::GovernorConfigBuilder::default() - .per_second(settings.rate_limit_per_second) - .burst_size(settings.rate_limit_burst) - .finish() - .expect("Failed to create governor config"), - )), - } -} diff --git a/nodes/node/binary/src/api/backend.rs b/nodes/node/binary/src/api/backend.rs index 52a4189c4..d61cbc942 100644 --- a/nodes/node/binary/src/api/backend.rs +++ b/nodes/node/binary/src/api/backend.rs @@ -20,8 +20,8 @@ use lb_core::{ header::HeaderId, mantle::{SignedMantleTx, Transaction}, }; +use lb_http_api_common::paths; pub use lb_http_api_common::settings::AxumBackendSettings; -use lb_http_api_common::{paths, utils::create_rate_limit_layer}; use lb_sdp_service::{mempool::SdpMempoolAdapter, wallet::SdpWalletAdapter}; use lb_services_utils::wait_until_services_are_ready; use lb_storage_service::{StorageService, backends::rocksdb::RocksBackend}; @@ -260,7 +260,6 @@ where .layer(ConcurrencyLimitLayer::new( self.settings.max_concurrent_requests, )) - .layer(create_rate_limit_layer(&self.settings)) .layer(TraceLayer::new_for_http()); let cors_layer = builder diff --git a/nodes/node/binary/src/api/testing/backend.rs b/nodes/node/binary/src/api/testing/backend.rs index cdb8bae63..a55551ea6 100644 --- a/nodes/node/binary/src/api/testing/backend.rs +++ b/nodes/node/binary/src/api/testing/backend.rs @@ -9,7 +9,7 @@ use axum::{ routing::get, }; use lb_api_service::Backend; -use lb_http_api_common::{paths::MANTLE_SDP_DECLARATIONS, utils::create_rate_limit_layer}; +use lb_http_api_common::paths::MANTLE_SDP_DECLARATIONS; pub use lb_network_service::backends::libp2p::Libp2p as NetworkBackend; use overwatch::{DynError, overwatch::handle::OverwatchHandle, services::AsServiceId}; use tokio::net::TcpListener; @@ -93,7 +93,6 @@ where .layer(ConcurrencyLimitLayer::new( self.settings.max_concurrent_requests, )) - .layer(create_rate_limit_layer(&self.settings)) .layer(TraceLayer::new_for_http()) .layer( builder diff --git a/nodes/node/config-one-node.yaml b/nodes/node/config-one-node.yaml index 5ab9ee115..e875bcd45 100644 --- a/nodes/node/config-one-node.yaml +++ b/nodes/node/config-one-node.yaml @@ -518,8 +518,6 @@ http: nanos: 0 max_body_size: 10485760 max_concurrent_requests: 1000 - rate_limit_per_second: 10000 - rate_limit_burst: 10000 storage: db_path: ./db read_only: false @@ -545,5 +543,3 @@ testing_http: nanos: 0 max_body_size: 10485760 max_concurrent_requests: 1000 - rate_limit_per_second: 10000 - rate_limit_burst: 10000 diff --git a/tests/src/nodes/validator.rs b/tests/src/nodes/validator.rs index 62a41a0f2..d2174778f 100644 --- a/tests/src/nodes/validator.rs +++ b/tests/src/nodes/validator.rs @@ -340,8 +340,6 @@ pub fn create_validator_config(config: GeneralConfig) -> RunConfig { http: lb_api_service::ApiServiceSettings { backend_settings: AxumBackendSettings { address: config.api_config.address, - rate_limit_per_second: 10000, - rate_limit_burst: 10000, max_concurrent_requests: 1000, ..Default::default() }, @@ -378,8 +376,6 @@ pub fn create_validator_config(config: GeneralConfig) -> RunConfig { testing_http: lb_api_service::ApiServiceSettings { backend_settings: AxumBackendSettings { address: testing_http_address, - rate_limit_per_second: 10000, - rate_limit_burst: 10000, max_concurrent_requests: 1000, ..Default::default() },