Skip to content

Commit

Permalink
refactor(starknet_sequencer_node): rename component execution config
Browse files Browse the repository at this point in the history
commit-id:a39da7b8
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 9, 2024
1 parent 361dbf3 commit 3dedcb8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
19 changes: 10 additions & 9 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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::{
ComponentExecutionConfig,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
Expand Down Expand Up @@ -93,18 +93,19 @@ fn strip_config_prefix(input: &str) -> &str {
.unwrap_or(input)
}

// TODO(Nadin): Refactor the following functions to be static methods of ComponentExecutionConfig.
pub fn get_disabled_component_config() -> ComponentExecutionConfig {
ComponentExecutionConfig {
// 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) -> ComponentExecutionConfig {
ComponentExecutionConfig {
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() }),
Expand All @@ -114,8 +115,8 @@ pub fn get_remote_component_config(socket: SocketAddr) -> ComponentExecutionConf

pub fn get_local_with_remote_enabled_component_config(
socket: SocketAddr,
) -> ComponentExecutionConfig {
ComponentExecutionConfig {
) -> ReactiveComponentExecutionConfig {
ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
Expand All @@ -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 {
let monitoring_endpoint_socket = get_available_socket().await;
ComponentConfig {
http_server: ComponentExecutionConfig::http_server_default_config(),
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +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::{
ComponentExecutionConfig,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
Expand Down Expand Up @@ -58,12 +58,12 @@ 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: ComponentExecutionConfig {
consensus_manager: ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::Disabled,
local_server_config: None,
..Default::default()
},
batcher: ComponentExecutionConfig {
batcher: ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::Disabled,
local_server_config: None,
..Default::default()
Expand Down
35 changes: 18 additions & 17 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,41 @@ use papyrus_config::{ParamPath, SerializedParam};
use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::config::component_execution_config::ComponentExecutionConfig;
use crate::config::component_execution_config::ReactiveComponentExecutionConfig;

/// The components configuration.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct ComponentConfig {
#[validate]
pub batcher: ComponentExecutionConfig,
pub batcher: ReactiveComponentExecutionConfig,
#[validate]
pub consensus_manager: ComponentExecutionConfig,
pub consensus_manager: ReactiveComponentExecutionConfig,
#[validate]
pub gateway: ComponentExecutionConfig,
pub gateway: ReactiveComponentExecutionConfig,
#[validate]
pub http_server: ComponentExecutionConfig,
pub http_server: ReactiveComponentExecutionConfig,
#[validate]
pub mempool: ComponentExecutionConfig,
pub mempool: ReactiveComponentExecutionConfig,
#[validate]
pub mempool_p2p: ComponentExecutionConfig,
pub mempool_p2p: ReactiveComponentExecutionConfig,
#[validate]
pub monitoring_endpoint: ComponentExecutionConfig,
pub monitoring_endpoint: ReactiveComponentExecutionConfig,
#[validate]
pub state_sync: ComponentExecutionConfig,
pub state_sync: ReactiveComponentExecutionConfig,
}

impl Default for ComponentConfig {
fn default() -> Self {
Self {
batcher: ComponentExecutionConfig::batcher_default_config(),
consensus_manager: ComponentExecutionConfig::consensus_manager_default_config(),
gateway: ComponentExecutionConfig::gateway_default_config(),
http_server: ComponentExecutionConfig::http_server_default_config(),
mempool: ComponentExecutionConfig::mempool_default_config(),
mempool_p2p: ComponentExecutionConfig::mempool_p2p_default_config(),
monitoring_endpoint: ComponentExecutionConfig::monitoring_endpoint_default_config(),
state_sync: ComponentExecutionConfig::state_sync_default_config(),
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(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ pub enum ActiveComponentExecutionMode {
// TODO(Lev/Tsabary): When papyrus_config will support it, change to include communication config in
// the enum.

/// The single component configuration.
/// Reactive component configuration.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
#[validate(schema(function = "validate_single_component_config"))]
pub struct ComponentExecutionConfig {
#[validate(schema(function = "validate_reactive_component_execution_config"))]
pub struct ReactiveComponentExecutionConfig {
pub execution_mode: ReactiveComponentExecutionMode,
pub local_server_config: Option<LocalServerConfig>,
pub remote_client_config: Option<RemoteClientConfig>,
pub remote_server_config: Option<RemoteServerConfig>,
}

impl SerializeConfig for ComponentExecutionConfig {
impl SerializeConfig for ReactiveComponentExecutionConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let members = BTreeMap::from_iter([ser_param(
"execution_mode",
Expand All @@ -58,7 +58,7 @@ impl SerializeConfig for ComponentExecutionConfig {
}
}

impl Default for ComponentExecutionConfig {
impl Default for ReactiveComponentExecutionConfig {
fn default() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
Expand All @@ -70,7 +70,7 @@ impl Default for ComponentExecutionConfig {
}

/// Specific components default configurations.
impl ComponentExecutionConfig {
impl ReactiveComponentExecutionConfig {
pub fn gateway_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
Expand Down Expand Up @@ -150,8 +150,8 @@ impl ComponentExecutionConfig {
}
}

pub fn validate_single_component_config(
component_config: &ComponentExecutionConfig,
fn validate_reactive_component_execution_config(
component_config: &ReactiveComponentExecutionConfig,
) -> Result<(), ValidationError> {
match (
component_config.execution_mode.clone(),
Expand Down
6 changes: 3 additions & 3 deletions crates/starknet_sequencer_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use starknet_sequencer_infra::component_definitions::{
use validator::Validate;

use crate::config::component_execution_config::{
ComponentExecutionConfig,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use crate::config::node_config::{
Expand All @@ -34,7 +34,7 @@ const LOCAL_EXECUTION_MODE: ReactiveComponentExecutionMode =
const ENABLE_REMOTE_CONNECTION_MODE: ReactiveComponentExecutionMode =
ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled;

/// Test the validation of the struct ComponentExecutionConfig.
/// Test the validation of the struct ReactiveComponentExecutionConfig.
/// Validates that execution mode of the component and the local/remote config are at sync.
#[rstest]
#[case::local(ReactiveComponentExecutionMode::Disabled, None, None, None)]
Expand All @@ -57,7 +57,7 @@ fn test_valid_component_execution_config(
#[case] remote_client_config: Option<RemoteClientConfig>,
#[case] remote_server_config: Option<RemoteServerConfig>,
) {
let component_exe_config = ComponentExecutionConfig {
let component_exe_config = ReactiveComponentExecutionConfig {
execution_mode,
local_server_config,
remote_client_config,
Expand Down

0 comments on commit 3dedcb8

Please sign in to comment.