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): add active component execution config #2575

Merged
merged 4 commits into from
Dec 9, 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
27 changes: 14 additions & 13 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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,
ComponentExecutionMode,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_sequencer_node::config::test_utils::RequiredParams;
Expand Down Expand Up @@ -93,19 +93,20 @@ 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 {
execution_mode: ComponentExecutionMode::Disabled,
// 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 {
execution_mode: ComponentExecutionMode::Remote,
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,
Expand All @@ -114,9 +115,9 @@ pub fn get_remote_component_config(socket: SocketAddr) -> ComponentExecutionConf

pub fn get_local_with_remote_enabled_component_config(
socket: SocketAddr,
) -> ComponentExecutionConfig {
ComponentExecutionConfig {
execution_mode: ComponentExecutionMode::LocalExecutionWithRemoteEnabled,
) -> ReactiveComponentExecutionConfig {
ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: Some(RemoteServerConfig { socket }),
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
12 changes: 6 additions & 6 deletions crates/starknet_integration_tests/tests/mempool_p2p_flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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,
ComponentExecutionMode,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_sequencer_node::servers::run_component_servers;
Expand Down Expand Up @@ -58,13 +58,13 @@ 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 {
execution_mode: ComponentExecutionMode::Disabled,
consensus_manager: ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::Disabled,
local_server_config: None,
..Default::default()
},
batcher: ComponentExecutionConfig {
execution_mode: ComponentExecutionMode::Disabled,
batcher: ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::Disabled,
local_server_config: None,
..Default::default()
},
Expand Down
14 changes: 7 additions & 7 deletions crates/starknet_sequencer_node/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use starknet_state_sync_types::communication::{
};

use crate::communication::SequencerNodeCommunication;
use crate::config::component_execution_config::ComponentExecutionMode;
use crate::config::component_execution_config::ReactiveComponentExecutionMode;
use crate::config::node_config::SequencerNodeConfig;

pub struct SequencerNodeClients {
Expand Down Expand Up @@ -178,7 +178,7 @@ impl SequencerNodeClients {
/// # Arguments
///
/// * $execution_mode - A reference to the component's execution mode, i.e., type
/// &ComponentExecutionMode.
/// &ReactiveComponentExecutionMode.
/// * $local_client_type - The type for the local client to create, e.g., LocalBatcherClient. The
/// client type should have a function $local_client_type::new(tx: $channel_expr).
/// * $remote_client_type - The type for the remote client to create, e.g., RemoteBatcherClient. The
Expand All @@ -196,7 +196,7 @@ impl SequencerNodeClients {
/// # Example
///
/// ```rust,ignore
/// // Assuming ComponentExecutionMode, channels, and remote client configuration are defined, and
/// // Assuming ReactiveComponentExecutionMode, channels, and remote client configuration are defined, and
/// // LocalBatcherClient and RemoteBatcherClient have new methods that accept a channel and config,
/// // respectively.
/// let batcher_client: Option<Client<BatcherRequest, BatcherResponse>> = create_client!(
Expand All @@ -221,19 +221,19 @@ macro_rules! create_client {
$remote_client_config:expr
) => {
match *$execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let local_client = Some(<$local_client_type>::new($channel_expr));
Some(Client::new(local_client, None))
}
ComponentExecutionMode::Remote => match $remote_client_config {
ReactiveComponentExecutionMode::Remote => match $remote_client_config {
Some(ref config) => {
let remote_client = Some(<$remote_client_type>::new(config.clone()));
Some(Client::new(None, remote_client))
}
None => None,
},
ComponentExecutionMode::Disabled => None,
ReactiveComponentExecutionMode::Disabled => None,
}
};
}
Expand Down
46 changes: 24 additions & 22 deletions crates/starknet_sequencer_node/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starknet_monitoring_endpoint::monitoring_endpoint::{
};

use crate::clients::SequencerNodeClients;
use crate::config::component_execution_config::ComponentExecutionMode;
use crate::config::component_execution_config::ReactiveComponentExecutionMode;
use crate::config::node_config::SequencerNodeConfig;
use crate::version::VERSION_FULL;

Expand All @@ -32,26 +32,26 @@ pub fn create_node_components(
clients: &SequencerNodeClients,
) -> SequencerNodeComponents {
let batcher = match config.components.batcher.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let mempool_client =
clients.get_mempool_shared_client().expect("Mempool Client should be available");
Some(create_batcher(config.batcher_config.clone(), mempool_client))
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};
let consensus_manager = match config.components.consensus_manager.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let batcher_client =
clients.get_batcher_shared_client().expect("Batcher Client should be available");
Some(ConsensusManager::new(config.consensus_manager_config.clone(), batcher_client))
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};
let gateway = match config.components.gateway.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let mempool_client =
clients.get_mempool_shared_client().expect("Mempool Client should be available");

Expand All @@ -62,53 +62,55 @@ pub fn create_node_components(
mempool_client,
))
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};
let http_server = match config.components.http_server.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let gateway_client =
clients.get_gateway_shared_client().expect("Gateway Client should be available");

Some(create_http_server(config.http_server_config.clone(), gateway_client))
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};

let (mempool_p2p_propagator, mempool_p2p_runner) = match config
.components
.mempool_p2p
.execution_mode
{
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let gateway_client =
clients.get_gateway_shared_client().expect("Gateway Client should be available");
let (mempool_p2p_propagator, mempool_p2p_runner) =
create_p2p_propagator_and_runner(config.mempool_p2p_config.clone(), gateway_client);
(Some(mempool_p2p_propagator), Some(mempool_p2p_runner))
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => (None, None),
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => {
(None, None)
}
};

let mempool = match config.components.mempool.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => {
let mempool_p2p_propagator_client = clients
.get_mempool_p2p_propagator_shared_client()
.expect("Propagator Client should be available");
let mempool = create_mempool(mempool_p2p_propagator_client);
Some(mempool)
}
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};

let monitoring_endpoint = match config.components.monitoring_endpoint.execution_mode {
ComponentExecutionMode::LocalExecutionWithRemoteEnabled => Some(
ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled => Some(
create_monitoring_endpoint(config.monitoring_endpoint_config.clone(), VERSION_FULL),
),
ComponentExecutionMode::LocalExecutionWithRemoteDisabled => None,
ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None,
ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled => None,
ReactiveComponentExecutionMode::Disabled | ReactiveComponentExecutionMode::Remote => None,
};

SequencerNodeComponents {
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
Loading
Loading