Skip to content

Commit

Permalink
chore(starknet_sequencer_node): add validation function to active com…
Browse files Browse the repository at this point in the history
…ponent config

commit-id:5da251e4
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 10, 2024
1 parent bb11c9b commit f630f48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RemoteClientConfig>,
Expand Down Expand Up @@ -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(()),
}
}

0 comments on commit f630f48

Please sign in to comment.