From b912ed4af118dc3df01a1389bb8fc86612d64e17 Mon Sep 17 00:00:00 2001 From: Itay-Tsabary-Starkware <106665835+Itay-Tsabary-Starkware@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:57:38 +0300 Subject: [PATCH] fix(mempool_infra): change idle_timeout type from duarion to u64 (#1211) commit-id:6121cd39 --- config/mempool/default_config.json | 35 ++++++------------- .../remote_component_client.rs | 7 ++-- .../src/component_definitions.rs | 7 ++-- .../remote_component_client_server_test.rs | 3 +- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index f53d189b73..e97eeb25c2 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -90,12 +90,9 @@ "value": 18446744073709551615 }, "components.batcher.remote_config.idle_timeout": { - "description": "The duration to keep an idle connection open before closing.", + "description": "The duration in seconds to keep an idle connection open before closing.", "privacy": "Public", - "value": { - "nanos": 0, - "secs": 90 - } + "value": 90 }, "components.batcher.remote_config.retries": { "description": "The max number of retries for sending a message.", @@ -138,12 +135,9 @@ "value": 18446744073709551615 }, "components.consensus_manager.remote_config.idle_timeout": { - "description": "The duration to keep an idle connection open before closing.", + "description": "The duration in seconds to keep an idle connection open before closing.", "privacy": "Public", - "value": { - "nanos": 0, - "secs": 90 - } + "value": 90 }, "components.consensus_manager.remote_config.retries": { "description": "The max number of retries for sending a message.", @@ -186,12 +180,9 @@ "value": 18446744073709551615 }, "components.gateway.remote_config.idle_timeout": { - "description": "The duration to keep an idle connection open before closing.", + "description": "The duration in seconds to keep an idle connection open before closing.", "privacy": "Public", - "value": { - "nanos": 0, - "secs": 90 - } + "value": 90 }, "components.gateway.remote_config.retries": { "description": "The max number of retries for sending a message.", @@ -234,12 +225,9 @@ "value": 18446744073709551615 }, "components.http_server.remote_config.idle_timeout": { - "description": "The duration to keep an idle connection open before closing.", + "description": "The duration in seconds to keep an idle connection open before closing.", "privacy": "Public", - "value": { - "nanos": 0, - "secs": 90 - } + "value": 90 }, "components.http_server.remote_config.retries": { "description": "The max number of retries for sending a message.", @@ -282,12 +270,9 @@ "value": 18446744073709551615 }, "components.mempool.remote_config.idle_timeout": { - "description": "The duration to keep an idle connection open before closing.", + "description": "The duration in seconds to keep an idle connection open before closing.", "privacy": "Public", - "value": { - "nanos": 0, - "secs": 90 - } + "value": 90 }, "components.mempool.remote_config.retries": { "description": "The max number of retries for sending a message.", diff --git a/crates/mempool_infra/src/component_client/remote_component_client.rs b/crates/mempool_infra/src/component_client/remote_component_client.rs index 020a965a62..2537170871 100644 --- a/crates/mempool_infra/src/component_client/remote_component_client.rs +++ b/crates/mempool_infra/src/component_client/remote_component_client.rs @@ -2,6 +2,7 @@ use std::fmt::Debug; use std::marker::PhantomData; use std::net::IpAddr; use std::sync::Arc; +use std::time::Duration; use hyper::body::to_bytes; use hyper::header::CONTENT_TYPE; @@ -30,8 +31,6 @@ use crate::serde_utils::BincodeSerdeWrapper; /// ```rust /// // Example usage of the RemoteComponentClient /// -/// use std::time::Duration; -/// /// use serde::{Deserialize, Serialize}; /// /// use crate::starknet_mempool_infra::component_client::RemoteComponentClient; @@ -59,7 +58,7 @@ use crate::serde_utils::BincodeSerdeWrapper; /// socket, /// retries: 3, /// idle_connections: usize::MAX, -/// idle_timeout: Duration::from_secs(90), +/// idle_timeout: 90, /// }; /// let client = RemoteComponentClient::::new(config); /// @@ -104,7 +103,7 @@ where let client = Client::builder() .http2_only(true) .pool_max_idle_per_host(config.idle_connections) - .pool_idle_timeout(config.idle_timeout) + .pool_idle_timeout(Duration::from_secs(config.idle_timeout)) .build_http(); Self { uri, client, config, _req: PhantomData, _res: PhantomData } } diff --git a/crates/mempool_infra/src/component_definitions.rs b/crates/mempool_infra/src/component_definitions.rs index be052024ad..aa50cb1b96 100644 --- a/crates/mempool_infra/src/component_definitions.rs +++ b/crates/mempool_infra/src/component_definitions.rs @@ -2,7 +2,6 @@ use std::any::type_name; use std::collections::BTreeMap; use std::fmt::Debug; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use std::time::Duration; use async_trait::async_trait; use papyrus_config::dumping::{ser_param, SerializeConfig}; @@ -19,7 +18,7 @@ pub const APPLICATION_OCTET_STREAM: &str = "application/octet-stream"; const DEFAULT_CHANNEL_BUFFER_SIZE: usize = 32; const DEFAULT_RETRIES: usize = 3; const DEFAULT_IDLE_CONNECTIONS: usize = usize::MAX; -const DEFAULT_IDLE_TIMEOUT: Duration = Duration::from_secs(90); +const DEFAULT_IDLE_TIMEOUT: u64 = 90; #[async_trait] pub trait ComponentRequestHandler { @@ -97,7 +96,7 @@ pub struct RemoteComponentCommunicationConfig { pub socket: SocketAddr, pub retries: usize, pub idle_connections: usize, - pub idle_timeout: Duration, + pub idle_timeout: u64, } impl SerializeConfig for RemoteComponentCommunicationConfig { @@ -124,7 +123,7 @@ impl SerializeConfig for RemoteComponentCommunicationConfig { ser_param( "idle_timeout", &self.idle_timeout, - "The duration to keep an idle connection open before closing.", + "The duration in seconds to keep an idle connection open before closing.", ParamPrivacyInput::Public, ), ]) diff --git a/crates/mempool_infra/src/tests/remote_component_client_server_test.rs b/crates/mempool_infra/src/tests/remote_component_client_server_test.rs index 19951291ec..f7b58c8a5d 100644 --- a/crates/mempool_infra/src/tests/remote_component_client_server_test.rs +++ b/crates/mempool_infra/src/tests/remote_component_client_server_test.rs @@ -1,7 +1,6 @@ use std::fmt::Debug; use std::net::SocketAddr; use std::sync::Arc; -use std::time::Duration; use async_trait::async_trait; use hyper::body::to_bytes; @@ -55,7 +54,7 @@ type ComponentAClient = RemoteComponentClient; const MAX_IDLE_CONNECTION: usize = usize::MAX; -const IDLE_TIMEOUT: Duration = Duration::from_secs(90); +const IDLE_TIMEOUT: u64 = 90; const MOCK_SERVER_ERROR: &str = "mock server error"; const ARBITRARY_DATA: &str = "arbitrary data"; // ServerError::RequestDeserializationFailure error message.