From 8342984ad16287d494160519261cd22a3d742ec8 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 9 Dec 2024 10:21:54 +0200 Subject: [PATCH 1/5] chore(starknet_sequencer_node): set monitoring as active component commit-id:c30a0cee --- config/sequencer/default_config.json | 47 +------------------ .../src/config_utils.rs | 10 +--- .../starknet_sequencer_node/src/components.rs | 15 +++--- .../src/config/component_config.rs | 15 ++++-- .../src/config/component_execution_config.rs | 12 ----- crates/starknet_sequencer_node/src/servers.rs | 21 ++++++++- 6 files changed, 41 insertions(+), 79 deletions(-) diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index a18908b48a..697c7486db 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -507,52 +507,7 @@ "components.monitoring_endpoint.execution_mode": { "description": "The component execution mode.", "privacy": "Public", - "value": "LocalExecutionWithRemoteEnabled" - }, - "components.monitoring_endpoint.local_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": false - }, - "components.monitoring_endpoint.local_server_config.channel_buffer_size": { - "description": "The communication channel buffer size.", - "privacy": "Public", - "value": 32 - }, - "components.monitoring_endpoint.remote_client_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": true - }, - "components.monitoring_endpoint.remote_client_config.idle_connections": { - "description": "The maximum number of idle connections to keep alive.", - "privacy": "Public", - "value": 18446744073709551615 - }, - "components.monitoring_endpoint.remote_client_config.idle_timeout": { - "description": "The duration in seconds to keep an idle connection open before closing.", - "privacy": "Public", - "value": 90 - }, - "components.monitoring_endpoint.remote_client_config.retries": { - "description": "The max number of retries for sending a message.", - "privacy": "Public", - "value": 3 - }, - "components.monitoring_endpoint.remote_client_config.socket": { - "description": "The remote component server socket.", - "privacy": "Public", - "value": "0.0.0.0:8080" - }, - "components.monitoring_endpoint.remote_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": false - }, - "components.monitoring_endpoint.remote_server_config.socket": { - "description": "The remote component server socket.", - "privacy": "Public", - "value": "0.0.0.0:8080" + "value": "Enabled" }, "components.state_sync.execution_mode": { "description": "The component execution mode.", diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index 90b7471a67..27ebe9e3b7 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -125,13 +125,10 @@ pub fn get_local_with_remote_enabled_component_config( } pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig { - let monitoring_endpoint_socket = get_available_socket().await; ComponentConfig { http_server: ReactiveComponentExecutionConfig::http_server_default_config(), gateway: get_remote_component_config(gateway_socket), - monitoring_endpoint: get_local_with_remote_enabled_component_config( - monitoring_endpoint_socket, - ), + monitoring_endpoint: Default::default(), batcher: get_disabled_component_config(), consensus_manager: get_disabled_component_config(), mempool: get_disabled_component_config(), @@ -141,12 +138,9 @@ pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> Compo } pub async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig { - let monitoring_endpoint_socket = get_available_socket().await; ComponentConfig { http_server: get_disabled_component_config(), - monitoring_endpoint: get_local_with_remote_enabled_component_config( - monitoring_endpoint_socket, - ), + monitoring_endpoint: Default::default(), gateway: get_local_with_remote_enabled_component_config(gateway_socket), ..ComponentConfig::default() } diff --git a/crates/starknet_sequencer_node/src/components.rs b/crates/starknet_sequencer_node/src/components.rs index 1a3f76a870..165fa7df07 100644 --- a/crates/starknet_sequencer_node/src/components.rs +++ b/crates/starknet_sequencer_node/src/components.rs @@ -15,7 +15,10 @@ use starknet_monitoring_endpoint::monitoring_endpoint::{ use starknet_state_sync_types::communication::EmptyStateSyncClient; use crate::clients::SequencerNodeClients; -use crate::config::component_execution_config::ReactiveComponentExecutionMode; +use crate::config::component_execution_config::{ + ActiveComponentExecutionMode, + ReactiveComponentExecutionMode, +}; use crate::config::node_config::SequencerNodeConfig; use crate::version::VERSION_FULL; @@ -115,11 +118,11 @@ pub fn create_node_components( }; let monitoring_endpoint = match config.components.monitoring_endpoint.execution_mode { - ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => Some( - create_monitoring_endpoint(config.monitoring_endpoint_config.clone(), VERSION_FULL), - ), - ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled => None, - ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None, + ActiveComponentExecutionMode::Enabled => Some(create_monitoring_endpoint( + config.monitoring_endpoint_config.clone(), + VERSION_FULL, + )), + ActiveComponentExecutionMode::Disabled => None, }; SequencerNodeComponents { diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index 6373d07806..d3aaaf18bd 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -5,11 +5,15 @@ use papyrus_config::{ParamPath, SerializedParam}; use serde::{Deserialize, Serialize}; use validator::Validate; -use crate::config::component_execution_config::ReactiveComponentExecutionConfig; +use crate::config::component_execution_config::{ + ActiveComponentExecutionConfig, + ReactiveComponentExecutionConfig, +}; /// The components configuration. #[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct ComponentConfig { + // Reactive component configs. #[validate] pub batcher: ReactiveComponentExecutionConfig, #[validate] @@ -23,9 +27,10 @@ pub struct ComponentConfig { #[validate] pub mempool_p2p: ReactiveComponentExecutionConfig, #[validate] - pub monitoring_endpoint: ReactiveComponentExecutionConfig, - #[validate] pub state_sync: ReactiveComponentExecutionConfig, + + // Reactive component configs. + pub monitoring_endpoint: ActiveComponentExecutionConfig, } impl Default for ComponentConfig { @@ -37,9 +42,9 @@ impl Default for ComponentConfig { http_server: ReactiveComponentExecutionConfig::http_server_default_config(), mempool: ReactiveComponentExecutionConfig::mempool_default_config(), mempool_p2p: ReactiveComponentExecutionConfig::mempool_p2p_default_config(), - monitoring_endpoint: - ReactiveComponentExecutionConfig::monitoring_endpoint_default_config(), state_sync: ReactiveComponentExecutionConfig::state_sync_default_config(), + // Reactive component configs. + monitoring_endpoint: Default::default(), } } } diff --git a/crates/starknet_sequencer_node/src/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index 1757c8b1f6..6f6312987e 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -115,18 +115,6 @@ impl ReactiveComponentExecutionConfig { } } - // TODO(Tsabary/Lev): There's a bug here: the monitoring endpoint component does not - // need a local nor a remote config. However, the validation function requires that at least - // one of them is set. As a workaround I've set the local one, but this should be addressed. - pub fn monitoring_endpoint_default_config() -> Self { - Self { - execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled, - local_server_config: Some(LocalServerConfig::default()), - remote_client_config: None, - remote_server_config: Some(RemoteServerConfig::default()), - } - } - pub fn mempool_default_config() -> Self { Self { execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled, diff --git a/crates/starknet_sequencer_node/src/servers.rs b/crates/starknet_sequencer_node/src/servers.rs index b1eb61cfcd..b4e974c520 100644 --- a/crates/starknet_sequencer_node/src/servers.rs +++ b/crates/starknet_sequencer_node/src/servers.rs @@ -25,7 +25,10 @@ use tracing::error; use crate::clients::SequencerNodeClients; use crate::communication::SequencerNodeCommunication; use crate::components::SequencerNodeComponents; -use crate::config::component_execution_config::ReactiveComponentExecutionMode; +use crate::config::component_execution_config::{ + ActiveComponentExecutionMode, + ReactiveComponentExecutionMode, +}; use crate::config::node_config::SequencerNodeConfig; // Component servers that can run locally. @@ -211,6 +214,20 @@ macro_rules! create_wrapper_server { }; } +// TODO(Tsabary): the following macro is a copy-pasted version of `create_wrapper_server!` macro, +// with the execution mode types changed. Once all active components have been marked as such, unify +// these. +macro_rules! create_wrapper_server_for_active_component { + ($execution_mode:expr, $component:expr) => { + match *$execution_mode { + ActiveComponentExecutionMode::Enabled => Some(Box::new(WrapperServer::new( + $component.take().expect(concat!(stringify!($component), " is not initialized.")), + ))), + ActiveComponentExecutionMode::Disabled => None, + } + }; +} + fn create_local_servers( config: &SequencerNodeConfig, communication: &mut SequencerNodeCommunication, @@ -296,7 +313,7 @@ fn create_wrapper_servers( components.http_server ); - let monitoring_endpoint_server = create_wrapper_server!( + let monitoring_endpoint_server = create_wrapper_server_for_active_component!( &config.components.monitoring_endpoint.execution_mode, components.monitoring_endpoint ); From 7e6158bf1716aa19a4e80a43d94239b0c12c554b Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 9 Dec 2024 10:39:21 +0200 Subject: [PATCH 2/5] chore(starknet_sequencer_node): add remote client to active component config commit-id:4f409ba2 --- config/sequencer/default_config.json | 25 +++++++++++++++++++ .../src/config/component_execution_config.rs | 11 +++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index 697c7486db..a942df1c40 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -509,6 +509,31 @@ "privacy": "Public", "value": "Enabled" }, + "components.monitoring_endpoint.remote_client_config.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "components.monitoring_endpoint.remote_client_config.idle_connections": { + "description": "The maximum number of idle connections to keep alive.", + "privacy": "Public", + "value": 18446744073709551615 + }, + "components.monitoring_endpoint.remote_client_config.idle_timeout": { + "description": "The duration in seconds to keep an idle connection open before closing.", + "privacy": "Public", + "value": 90 + }, + "components.monitoring_endpoint.remote_client_config.retries": { + "description": "The max number of retries for sending a message.", + "privacy": "Public", + "value": 3 + }, + "components.monitoring_endpoint.remote_client_config.socket": { + "description": "The remote component server socket.", + "privacy": "Public", + "value": "0.0.0.0:8080" + }, "components.state_sync.execution_mode": { "description": "The component execution mode.", "privacy": "Public", diff --git a/crates/starknet_sequencer_node/src/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index 6f6312987e..2bbb54437c 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -73,22 +73,27 @@ impl Default for ReactiveComponentExecutionConfig { #[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct ActiveComponentExecutionConfig { pub execution_mode: ActiveComponentExecutionMode, + pub remote_client_config: Option, } impl SerializeConfig for ActiveComponentExecutionConfig { fn dump(&self) -> BTreeMap { - BTreeMap::from_iter([ser_param( + let members = BTreeMap::from_iter([ser_param( "execution_mode", &self.execution_mode, "The component execution mode.", ParamPrivacyInput::Public, - )]) + )]); + vec![members, ser_optional_sub_config(&self.remote_client_config, "remote_client_config")] + .into_iter() + .flatten() + .collect() } } impl Default for ActiveComponentExecutionConfig { fn default() -> Self { - Self { execution_mode: ActiveComponentExecutionMode::Enabled } + Self { execution_mode: ActiveComponentExecutionMode::Enabled, remote_client_config: None } } } From 4459c0e881d6553d4a082cd44125cb48144dffd5 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 9 Dec 2024 10:48:40 +0200 Subject: [PATCH 3/5] chore(starknet_sequencer_node): set http server as active component commit-id:5bc74104 --- config/sequencer/default_config.json | 22 +------------------ .../src/config_utils.rs | 5 +++-- .../starknet_sequencer_node/src/components.rs | 5 ++--- .../src/config/component_config.rs | 10 ++++----- .../src/config/component_execution_config.rs | 12 +++++++++- crates/starknet_sequencer_node/src/servers.rs | 2 +- 6 files changed, 23 insertions(+), 33 deletions(-) diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index a942df1c40..504a066836 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -357,17 +357,7 @@ "components.http_server.execution_mode": { "description": "The component execution mode.", "privacy": "Public", - "value": "LocalExecutionWithRemoteEnabled" - }, - "components.http_server.local_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": false - }, - "components.http_server.local_server_config.channel_buffer_size": { - "description": "The communication channel buffer size.", - "privacy": "Public", - "value": 32 + "value": "Enabled" }, "components.http_server.remote_client_config.#is_none": { "description": "Flag for an optional field.", @@ -394,16 +384,6 @@ "privacy": "Public", "value": "0.0.0.0:8080" }, - "components.http_server.remote_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": false - }, - "components.http_server.remote_server_config.socket": { - "description": "The remote component server socket.", - "privacy": "Public", - "value": "0.0.0.0:8080" - }, "components.mempool.execution_mode": { "description": "The component execution mode.", "privacy": "Public", diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index 27ebe9e3b7..a95b5c1cd5 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -12,6 +12,7 @@ use starknet_sequencer_infra::component_definitions::{ use starknet_sequencer_infra::test_utils::get_available_socket; use starknet_sequencer_node::config::component_config::ComponentConfig; use starknet_sequencer_node::config::component_execution_config::{ + ActiveComponentExecutionConfig, ReactiveComponentExecutionConfig, ReactiveComponentExecutionMode, }; @@ -126,7 +127,7 @@ pub fn get_local_with_remote_enabled_component_config( pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig { ComponentConfig { - http_server: ReactiveComponentExecutionConfig::http_server_default_config(), + http_server: ActiveComponentExecutionConfig::default(), gateway: get_remote_component_config(gateway_socket), monitoring_endpoint: Default::default(), batcher: get_disabled_component_config(), @@ -139,7 +140,7 @@ pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> Compo pub async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig { ComponentConfig { - http_server: get_disabled_component_config(), + http_server: ActiveComponentExecutionConfig::disabled(), monitoring_endpoint: Default::default(), gateway: get_local_with_remote_enabled_component_config(gateway_socket), ..ComponentConfig::default() diff --git a/crates/starknet_sequencer_node/src/components.rs b/crates/starknet_sequencer_node/src/components.rs index 165fa7df07..f3ddcda5e7 100644 --- a/crates/starknet_sequencer_node/src/components.rs +++ b/crates/starknet_sequencer_node/src/components.rs @@ -77,14 +77,13 @@ pub fn create_node_components( ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None, }; let http_server = match config.components.http_server.execution_mode { - ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + ActiveComponentExecutionMode::Enabled => { let gateway_client = clients.get_gateway_shared_client().expect("Gateway Client should be available"); Some(create_http_server(config.http_server_config.clone(), gateway_client)) } - ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None, + ActiveComponentExecutionMode::Disabled => None, }; let (mempool_p2p_propagator, mempool_p2p_runner) = match config diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index d3aaaf18bd..432cb17681 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -21,29 +21,29 @@ pub struct ComponentConfig { #[validate] pub gateway: ReactiveComponentExecutionConfig, #[validate] - pub http_server: ReactiveComponentExecutionConfig, - #[validate] pub mempool: ReactiveComponentExecutionConfig, #[validate] pub mempool_p2p: ReactiveComponentExecutionConfig, #[validate] pub state_sync: ReactiveComponentExecutionConfig, - // Reactive component configs. + // Active component configs. + pub http_server: ActiveComponentExecutionConfig, pub monitoring_endpoint: ActiveComponentExecutionConfig, } impl Default for ComponentConfig { fn default() -> Self { Self { + // Reactive component configs. batcher: ReactiveComponentExecutionConfig::batcher_default_config(), consensus_manager: ReactiveComponentExecutionConfig::consensus_manager_default_config(), gateway: ReactiveComponentExecutionConfig::gateway_default_config(), - http_server: ReactiveComponentExecutionConfig::http_server_default_config(), mempool: ReactiveComponentExecutionConfig::mempool_default_config(), mempool_p2p: ReactiveComponentExecutionConfig::mempool_p2p_default_config(), state_sync: ReactiveComponentExecutionConfig::state_sync_default_config(), - // Reactive component configs. + // Active component configs. + http_server: Default::default(), monitoring_endpoint: Default::default(), } } diff --git a/crates/starknet_sequencer_node/src/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index 2bbb54437c..d317b60c0d 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -93,7 +93,7 @@ impl SerializeConfig for ActiveComponentExecutionConfig { impl Default for ActiveComponentExecutionConfig { fn default() -> Self { - Self { execution_mode: ActiveComponentExecutionMode::Enabled, remote_client_config: None } + ActiveComponentExecutionConfig::enabled() } } @@ -166,6 +166,16 @@ impl ReactiveComponentExecutionConfig { } } +impl ActiveComponentExecutionConfig { + pub fn disabled() -> Self { + Self { execution_mode: ActiveComponentExecutionMode::Disabled, remote_client_config: None } + } + + pub fn enabled() -> Self { + Self { execution_mode: ActiveComponentExecutionMode::Enabled, remote_client_config: None } + } +} + fn validate_reactive_component_execution_config( component_config: &ReactiveComponentExecutionConfig, ) -> Result<(), ValidationError> { diff --git a/crates/starknet_sequencer_node/src/servers.rs b/crates/starknet_sequencer_node/src/servers.rs index b4e974c520..c40eb3f04e 100644 --- a/crates/starknet_sequencer_node/src/servers.rs +++ b/crates/starknet_sequencer_node/src/servers.rs @@ -308,7 +308,7 @@ fn create_wrapper_servers( &config.components.consensus_manager.execution_mode, components.consensus_manager ); - let http_server = create_wrapper_server!( + let http_server = create_wrapper_server_for_active_component!( &config.components.http_server.execution_mode, components.http_server ); From 7291039bec5a871dc791de42f12f92a8bdc80c6d Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 9 Dec 2024 17:29:52 +0200 Subject: [PATCH 4/5] chore(starknet_sequencer_node): set consensus manager as active component commit-id:80cc5c87 --- config/sequencer/default_config.json | 22 +------------------ .../src/config_utils.rs | 2 +- .../tests/mempool_p2p_flow_test.rs | 7 ++---- .../starknet_sequencer_node/src/components.rs | 5 ++--- .../src/config/component_config.rs | 5 ++--- crates/starknet_sequencer_node/src/servers.rs | 2 +- 6 files changed, 9 insertions(+), 34 deletions(-) diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index 504a066836..e343a40676 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -257,17 +257,7 @@ "components.consensus_manager.execution_mode": { "description": "The component execution mode.", "privacy": "Public", - "value": "LocalExecutionWithRemoteDisabled" - }, - "components.consensus_manager.local_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": false - }, - "components.consensus_manager.local_server_config.channel_buffer_size": { - "description": "The communication channel buffer size.", - "privacy": "Public", - "value": 32 + "value": "Enabled" }, "components.consensus_manager.remote_client_config.#is_none": { "description": "Flag for an optional field.", @@ -294,16 +284,6 @@ "privacy": "Public", "value": "0.0.0.0:8080" }, - "components.consensus_manager.remote_server_config.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": true - }, - "components.consensus_manager.remote_server_config.socket": { - "description": "The remote component server socket.", - "privacy": "Public", - "value": "0.0.0.0:8080" - }, "components.gateway.execution_mode": { "description": "The component execution mode.", "privacy": "Public", diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index a95b5c1cd5..18e23179c0 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -131,7 +131,7 @@ pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> Compo gateway: get_remote_component_config(gateway_socket), monitoring_endpoint: Default::default(), batcher: get_disabled_component_config(), - consensus_manager: get_disabled_component_config(), + consensus_manager: ActiveComponentExecutionConfig::disabled(), mempool: get_disabled_component_config(), mempool_p2p: get_disabled_component_config(), state_sync: get_disabled_component_config(), diff --git a/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs b/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs index cd60ca05b8..372e34c670 100644 --- a/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs +++ b/crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs @@ -24,6 +24,7 @@ use starknet_mempool_p2p::config::MempoolP2pConfig; use starknet_mempool_p2p::MEMPOOL_TOPIC; use starknet_sequencer_node::config::component_config::ComponentConfig; use starknet_sequencer_node::config::component_execution_config::{ + ActiveComponentExecutionConfig, ReactiveComponentExecutionConfig, ReactiveComponentExecutionMode, }; @@ -58,11 +59,7 @@ async fn test_mempool_sends_tx_to_other_peer(mut tx_generator: MultiAccountTrans // Derive the configuration for the mempool node. let components = ComponentConfig { - consensus_manager: ReactiveComponentExecutionConfig { - execution_mode: ReactiveComponentExecutionMode::Disabled, - local_server_config: None, - ..Default::default() - }, + consensus_manager: ActiveComponentExecutionConfig::disabled(), batcher: ReactiveComponentExecutionConfig { execution_mode: ReactiveComponentExecutionMode::Disabled, local_server_config: None, diff --git a/crates/starknet_sequencer_node/src/components.rs b/crates/starknet_sequencer_node/src/components.rs index f3ddcda5e7..8c06adff56 100644 --- a/crates/starknet_sequencer_node/src/components.rs +++ b/crates/starknet_sequencer_node/src/components.rs @@ -47,8 +47,7 @@ pub fn create_node_components( ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None, }; let consensus_manager = match config.components.consensus_manager.execution_mode { - ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + ActiveComponentExecutionMode::Enabled => { let batcher_client = clients.get_batcher_shared_client().expect("Batcher Client should be available"); // TODO(shahak): Use the real client once we connect state sync to the node. @@ -59,7 +58,7 @@ pub fn create_node_components( state_sync_client, )) } - ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None, + ActiveComponentExecutionMode::Disabled => None, }; let gateway = match config.components.gateway.execution_mode { ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index 432cb17681..2095da8e74 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -17,8 +17,6 @@ pub struct ComponentConfig { #[validate] pub batcher: ReactiveComponentExecutionConfig, #[validate] - pub consensus_manager: ReactiveComponentExecutionConfig, - #[validate] pub gateway: ReactiveComponentExecutionConfig, #[validate] pub mempool: ReactiveComponentExecutionConfig, @@ -28,6 +26,7 @@ pub struct ComponentConfig { pub state_sync: ReactiveComponentExecutionConfig, // Active component configs. + pub consensus_manager: ActiveComponentExecutionConfig, pub http_server: ActiveComponentExecutionConfig, pub monitoring_endpoint: ActiveComponentExecutionConfig, } @@ -37,12 +36,12 @@ impl Default for ComponentConfig { Self { // Reactive component configs. batcher: ReactiveComponentExecutionConfig::batcher_default_config(), - consensus_manager: ReactiveComponentExecutionConfig::consensus_manager_default_config(), gateway: ReactiveComponentExecutionConfig::gateway_default_config(), mempool: ReactiveComponentExecutionConfig::mempool_default_config(), mempool_p2p: ReactiveComponentExecutionConfig::mempool_p2p_default_config(), state_sync: ReactiveComponentExecutionConfig::state_sync_default_config(), // Active component configs. + consensus_manager: Default::default(), http_server: Default::default(), monitoring_endpoint: Default::default(), } diff --git a/crates/starknet_sequencer_node/src/servers.rs b/crates/starknet_sequencer_node/src/servers.rs index c40eb3f04e..e1749a658f 100644 --- a/crates/starknet_sequencer_node/src/servers.rs +++ b/crates/starknet_sequencer_node/src/servers.rs @@ -304,7 +304,7 @@ fn create_wrapper_servers( config: &SequencerNodeConfig, components: &mut SequencerNodeComponents, ) -> WrapperServers { - let consensus_manager_server = create_wrapper_server!( + let consensus_manager_server = create_wrapper_server_for_active_component!( &config.components.consensus_manager.execution_mode, components.consensus_manager ); From 31c5ee8ef6fe9a1a1f7575d1f6322c0c9a41c677 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Mon, 9 Dec 2024 17:41:44 +0200 Subject: [PATCH 5/5] chore(starknet_sequencer_node): add validation function to active component config commit-id:5da251e4 --- .../src/config/component_config.rs | 3 ++ .../src/config/component_execution_config.rs | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index 2095da8e74..e1e7a198bc 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -26,8 +26,11 @@ pub struct ComponentConfig { pub state_sync: ReactiveComponentExecutionConfig, // Active component configs. + #[validate] pub consensus_manager: ActiveComponentExecutionConfig, + #[validate] pub http_server: ActiveComponentExecutionConfig, + #[validate] pub monitoring_endpoint: ActiveComponentExecutionConfig, } diff --git a/crates/starknet_sequencer_node/src/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index d317b60c0d..dbe10a55e0 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -71,6 +71,7 @@ impl Default for ReactiveComponentExecutionConfig { /// Active component configuration. #[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] +#[validate(schema(function = "validate_active_component_execution_config"))] pub struct ActiveComponentExecutionConfig { pub execution_mode: ActiveComponentExecutionMode, pub remote_client_config: Option, @@ -195,13 +196,34 @@ fn validate_reactive_component_execution_config( } (mode, local_server_config, remote_client_config, remote_server_config) => { error!( - "Invalid component execution configuration: mode: {:?}, local_server_config: \ - {:?}, remote_client_config: {:?}, remote_server_config: {:?}", + "Invalid reactive component execution configuration: mode: {:?}, \ + local_server_config: {:?}, remote_client_config: {:?}, remote_server_config: {:?}", mode, local_server_config, remote_client_config, remote_server_config ); - let mut error = ValidationError::new("Invalid component execution configuration."); + let mut error = + ValidationError::new("Invalid reactive component execution configuration."); error.message = Some("Ensure settings align with the chosen execution mode.".into()); Err(error) } } } + +fn validate_active_component_execution_config( + component_config: &ActiveComponentExecutionConfig, +) -> Result<(), ValidationError> { + match (component_config.execution_mode.clone(), component_config.remote_client_config.is_some()) + { + (ActiveComponentExecutionMode::Disabled, true) => { + error!( + "Invalid active component execution configuration: Disabled mode with \ + remote_client_config: {:?}", + component_config.remote_client_config + ); + let mut error = + ValidationError::new("Invalid active component execution configuration."); + error.message = Some("Ensure settings align with the chosen execution mode.".into()); + Err(error) + } + _ => Ok(()), + } +}