Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(starknet_sequencer_node): cleanup explicit default config fns #2605

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::config::component_execution_config::{
};

/// The components configuration.
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
pub struct ComponentConfig {
// Reactive component configs.
#[validate]
Expand All @@ -34,23 +34,6 @@ pub struct ComponentConfig {
pub monitoring_endpoint: ActiveComponentExecutionConfig,
}

impl Default for ComponentConfig {
fn default() -> Self {
Self {
// Reactive component configs.
batcher: ReactiveComponentExecutionConfig::batcher_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(),
}
}
}

impl SerializeConfig for ComponentConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let sub_configs = vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,75 +98,6 @@ impl Default for ActiveComponentExecutionConfig {
}
}

/// Specific components default configurations.
impl ReactiveComponentExecutionConfig {
pub fn gateway_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}

// TODO(Tsabary/Lev): There's a bug here: the http server 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 http_server_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,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}

pub fn batcher_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}

pub fn consensus_manager_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}

pub fn mempool_p2p_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}

pub fn state_sync_default_config() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: None,
}
}
}

impl ActiveComponentExecutionConfig {
pub fn disabled() -> Self {
Self { execution_mode: ActiveComponentExecutionMode::Disabled, remote_client_config: None }
Expand Down Expand Up @@ -227,3 +158,21 @@ fn validate_active_component_execution_config(
_ => Ok(()),
}
}

// There are components that are described with a reactive mode setting, however, result in the
// creation of two components: one reactive and one active. The defined behavior is such that
// the active component is active if and only if the local component is running locally. The
// following function applies this logic.
impl From<ReactiveComponentExecutionMode> for ActiveComponentExecutionMode {
fn from(mode: ReactiveComponentExecutionMode) -> Self {
match mode {
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => {
ActiveComponentExecutionMode::Disabled
}
ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled => {
ActiveComponentExecutionMode::Enabled
}
}
}
}
29 changes: 4 additions & 25 deletions crates/starknet_sequencer_node/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,6 @@ macro_rules! create_local_server {
/// }
/// ```
macro_rules! create_wrapper_server {
($execution_mode:expr, $component:expr) => {
match *$execution_mode {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
Some(Box::new(WrapperServer::new(
$component
.take()
.expect(concat!(stringify!($component), " is not initialized.")),
)))
}
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => {
None
}
}
};
}

// 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(
Expand Down Expand Up @@ -304,22 +283,22 @@ fn create_wrapper_servers(
config: &SequencerNodeConfig,
components: &mut SequencerNodeComponents,
) -> WrapperServers {
let consensus_manager_server = create_wrapper_server_for_active_component!(
let consensus_manager_server = create_wrapper_server!(
&config.components.consensus_manager.execution_mode,
components.consensus_manager
);
let http_server = create_wrapper_server_for_active_component!(
let http_server = create_wrapper_server!(
&config.components.http_server.execution_mode,
components.http_server
);

let monitoring_endpoint_server = create_wrapper_server_for_active_component!(
let monitoring_endpoint_server = create_wrapper_server!(
&config.components.monitoring_endpoint.execution_mode,
components.monitoring_endpoint
);

let mempool_p2p_runner_server = create_wrapper_server!(
&config.components.mempool_p2p.execution_mode,
&config.components.mempool_p2p.execution_mode.clone().into(),
components.mempool_p2p_runner
);
WrapperServers {
Expand Down
Loading