Skip to content

Commit

Permalink
chore(starknet_sequencer_node): set monitoring as active component
Browse files Browse the repository at this point in the history
commit-id:c30a0cee
  • Loading branch information
Itay-Tsabary-Starkware committed Dec 9, 2024
1 parent b1056aa commit 0bc3de8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
10 changes: 2 additions & 8 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,10 @@ 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(),
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(),
mempool: get_disabled_component_config(),
Expand All @@ -141,12 +138,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,
),
monitoring_endpoint: Default::default(),
gateway: get_local_with_remote_enabled_component_config(gateway_socket),
..ComponentConfig::default()
}
Expand Down
15 changes: 9 additions & 6 deletions crates/starknet_sequencer_node/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use starknet_monitoring_endpoint::monitoring_endpoint::{
};

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;

Expand Down Expand Up @@ -106,11 +109,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 {
Expand Down
15 changes: 10 additions & 5 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ 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]
Expand All @@ -23,9 +27,10 @@ pub struct ComponentConfig {
#[validate]
pub mempool_p2p: ReactiveComponentExecutionConfig,
#[validate]
pub monitoring_endpoint: ReactiveComponentExecutionConfig,
#[validate]
pub state_sync: ReactiveComponentExecutionConfig,

// Reactive component configs.
pub monitoring_endpoint: ActiveComponentExecutionConfig,
}

impl Default for ComponentConfig {
Expand All @@ -37,9 +42,9 @@ impl Default for ComponentConfig {
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(),
// Reactive component configs.
monitoring_endpoint: Default::default(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,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,
Expand Down
21 changes: 19 additions & 2 deletions crates/starknet_sequencer_node/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -296,7 +313,7 @@ fn create_wrapper_servers(
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
);
Expand Down

0 comments on commit 0bc3de8

Please sign in to comment.