diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index a18908b48a..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", @@ -357,17 +337,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 +364,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", @@ -507,17 +467,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 + "value": "Enabled" }, "components.monitoring_endpoint.remote_client_config.#is_none": { "description": "Flag for an optional field.", @@ -544,16 +494,6 @@ "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" - }, "components.state_sync.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 90b7471a67..18e23179c0 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, }; @@ -125,15 +126,12 @@ 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(), + http_server: ActiveComponentExecutionConfig::default(), 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(), + consensus_manager: ActiveComponentExecutionConfig::disabled(), mempool: get_disabled_component_config(), mempool_p2p: get_disabled_component_config(), state_sync: get_disabled_component_config(), @@ -141,12 +139,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, - ), + 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_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 1a3f76a870..8c06adff56 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; @@ -44,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. @@ -56,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 @@ -74,14 +76,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 @@ -115,11 +116,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..e1e7a198bc 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -5,41 +5,48 @@ 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] - pub consensus_manager: ReactiveComponentExecutionConfig, - #[validate] pub gateway: ReactiveComponentExecutionConfig, #[validate] - pub http_server: ReactiveComponentExecutionConfig, - #[validate] pub mempool: ReactiveComponentExecutionConfig, #[validate] pub mempool_p2p: ReactiveComponentExecutionConfig, #[validate] - pub monitoring_endpoint: ReactiveComponentExecutionConfig, - #[validate] pub state_sync: ReactiveComponentExecutionConfig, + + // Active component configs. + #[validate] + pub consensus_manager: ActiveComponentExecutionConfig, + #[validate] + pub http_server: ActiveComponentExecutionConfig, + #[validate] + 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(), - monitoring_endpoint: - ReactiveComponentExecutionConfig::monitoring_endpoint_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/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index 1757c8b1f6..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,24 +71,30 @@ 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, } 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 } + ActiveComponentExecutionConfig::enabled() } } @@ -115,18 +121,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, @@ -173,6 +167,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> { @@ -192,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(()), } } diff --git a/crates/starknet_sequencer_node/src/servers.rs b/crates/starknet_sequencer_node/src/servers.rs index b1eb61cfcd..e1749a658f 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, @@ -287,16 +304,16 @@ 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 ); - let http_server = create_wrapper_server!( + let http_server = create_wrapper_server_for_active_component!( &config.components.http_server.execution_mode, 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 );