From af74334f00a9239a56ed78cfca9ca642bf6ac9f2 Mon Sep 17 00:00:00 2001 From: nadin-Starkware Date: Sun, 22 Dec 2024 14:49:29 +0200 Subject: [PATCH] feat: add utility constructors for ReactiveComponentExecutionMode commit-id:fe5285a8 --- .../src/config_utils.rs | 75 ------------------- .../src/end_to_end_integration.rs | 39 ++++++++++ .../src/config/component_execution_config.rs | 40 ++++++++++ 3 files changed, 79 insertions(+), 75 deletions(-) diff --git a/crates/starknet_integration_tests/src/config_utils.rs b/crates/starknet_integration_tests/src/config_utils.rs index a068c99978..82dcd36700 100644 --- a/crates/starknet_integration_tests/src/config_utils.rs +++ b/crates/starknet_integration_tests/src/config_utils.rs @@ -1,22 +1,9 @@ use std::fs::File; use std::io::Write; -use std::net::SocketAddr; use std::path::PathBuf; use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig}; use serde_json::{json, Map, Value}; -use starknet_sequencer_infra::component_definitions::{ - LocalServerConfig, - RemoteClientConfig, - RemoteServerConfig, -}; -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, -}; use starknet_sequencer_node::config::node_config::{ SequencerNodeConfig, CONFIG_NON_POINTERS_WHITELIST, @@ -110,68 +97,6 @@ fn strip_config_prefix(input: &str) -> &str { .unwrap_or(input) } -// TODO(Nadin): Refactor the following functions to be static methods of -// ReactiveComponentExecutionConfig. -pub fn get_disabled_component_config() -> ReactiveComponentExecutionConfig { - ReactiveComponentExecutionConfig { - execution_mode: ReactiveComponentExecutionMode::Disabled, - local_server_config: None, - remote_client_config: None, - remote_server_config: None, - } -} - -pub fn get_remote_component_config(socket: SocketAddr) -> ReactiveComponentExecutionConfig { - ReactiveComponentExecutionConfig { - execution_mode: ReactiveComponentExecutionMode::Remote, - local_server_config: None, - remote_client_config: Some(RemoteClientConfig { socket, ..RemoteClientConfig::default() }), - remote_server_config: None, - } -} - -pub fn get_local_with_remote_enabled_component_config( - socket: SocketAddr, -) -> ReactiveComponentExecutionConfig { - ReactiveComponentExecutionConfig { - execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled, - local_server_config: Some(LocalServerConfig::default()), - remote_client_config: None, - remote_server_config: Some(RemoteServerConfig { socket }), - } -} - -pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig { - ComponentConfig { - http_server: ActiveComponentExecutionConfig::default(), - gateway: get_remote_component_config(gateway_socket), - monitoring_endpoint: Default::default(), - batcher: 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(), - l1_provider: get_disabled_component_config(), - } -} - -pub async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig { - ComponentConfig { - http_server: ActiveComponentExecutionConfig::disabled(), - monitoring_endpoint: Default::default(), - gateway: get_local_with_remote_enabled_component_config(gateway_socket), - ..ComponentConfig::default() - } -} - -pub async fn get_remote_flow_test_config() -> Vec { - let gateway_socket = get_available_socket().await; - vec![ - get_http_only_component_config(gateway_socket).await, - get_non_http_component_config(gateway_socket).await, - ] -} - /// Transforms a nested JSON dictionary object into a simplified JSON dictionary object by /// extracting specific values from the inner dictionaries. /// diff --git a/crates/starknet_integration_tests/src/end_to_end_integration.rs b/crates/starknet_integration_tests/src/end_to_end_integration.rs index 9b111e901a..7ef4efc2c2 100644 --- a/crates/starknet_integration_tests/src/end_to_end_integration.rs +++ b/crates/starknet_integration_tests/src/end_to_end_integration.rs @@ -1,3 +1,5 @@ +use std::net::SocketAddr; + use infra_utils::run_until::run_until; use infra_utils::tracing::{CustomLogger, TraceLevel}; use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator}; @@ -7,6 +9,12 @@ use papyrus_storage::StorageReader; use starknet_api::block::BlockNumber; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::state::StateNumber; +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, +}; use starknet_sequencer_node::test_utils::node_runner::get_node_executable_path; use starknet_types_core::felt::Felt; use tracing::info; @@ -104,3 +112,34 @@ pub async fn end_to_end_integration(mut tx_generator: MultiAccountTransactionGen let nonce = get_account_nonce(&batcher_storage_reader, sender_address); assert_eq!(nonce, expected_nonce); } + +pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig { + ComponentConfig { + http_server: ActiveComponentExecutionConfig::default(), + gateway: ReactiveComponentExecutionConfig::remote(gateway_socket), + monitoring_endpoint: Default::default(), + batcher: ReactiveComponentExecutionConfig::disabled(), + consensus_manager: ActiveComponentExecutionConfig::disabled(), + mempool: ReactiveComponentExecutionConfig::disabled(), + mempool_p2p: ReactiveComponentExecutionConfig::disabled(), + state_sync: ReactiveComponentExecutionConfig::disabled(), + l1_provider: ReactiveComponentExecutionConfig::disabled(), + } +} + +async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig { + ComponentConfig { + http_server: ActiveComponentExecutionConfig::disabled(), + monitoring_endpoint: Default::default(), + gateway: ReactiveComponentExecutionConfig::local_with_remote_enabled(gateway_socket), + ..ComponentConfig::default() + } +} + +pub async fn get_remote_flow_test_config() -> Vec { + let gateway_socket = get_available_socket().await; + vec![ + get_http_only_component_config(gateway_socket).await, + get_non_http_component_config(gateway_socket).await, + ] +} 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 03af9e5e78..b4e257c289 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::net::SocketAddr; use papyrus_config::dumping::{ser_optional_sub_config, ser_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; @@ -60,6 +61,45 @@ impl SerializeConfig for ReactiveComponentExecutionConfig { impl Default for ReactiveComponentExecutionConfig { fn default() -> Self { + Self::local_with_remote_disabled() + } +} + +#[cfg(any(feature = "testing", test))] +impl ReactiveComponentExecutionConfig { + pub fn disabled() -> Self { + Self { + execution_mode: ReactiveComponentExecutionMode::Disabled, + local_server_config: None, + remote_client_config: None, + remote_server_config: None, + } + } + + pub fn remote(socket: SocketAddr) -> Self { + Self { + execution_mode: ReactiveComponentExecutionMode::Remote, + local_server_config: None, + remote_client_config: Some(RemoteClientConfig { + socket, + ..RemoteClientConfig::default() + }), + remote_server_config: None, + } + } + + pub fn local_with_remote_enabled(socket: SocketAddr) -> Self { + Self { + execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled, + local_server_config: Some(LocalServerConfig::default()), + remote_client_config: None, + remote_server_config: Some(RemoteServerConfig { socket }), + } + } +} + +impl ReactiveComponentExecutionConfig { + pub fn local_with_remote_disabled() -> Self { Self { execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled, local_server_config: Some(LocalServerConfig::default()),