Skip to content

Commit

Permalink
feat: add utility constructors for ReactiveComponentExecutionMode
Browse files Browse the repository at this point in the history
commit-id:fe5285a8
  • Loading branch information
nadin-Starkware committed Dec 22, 2024
1 parent 4ce51ee commit 210647f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 44 deletions.
51 changes: 7 additions & 44 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ use std::path::PathBuf;

use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig};
use serde_json::{json, Map, Value};
use starknet_sequencer_infra::component_definitions::{
LocalServerConfig,
RemoteClientConfig,
RemoteServerConfig,
};
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::{
ActiveComponentExecutionConfig,
ReactiveComponentExecutionConfig,
ReactiveComponentExecutionMode,
};
use starknet_sequencer_node::config::node_config::{
SequencerNodeConfig,
Expand Down Expand Up @@ -110,56 +104,25 @@ fn strip_config_prefix(input: &str) -> &str {
.unwrap_or(input)
}

// 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) -> ReactiveComponentExecutionConfig {
ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::Remote,
local_server_config: None,
remote_client_config: Some(RemoteClientConfig { socket, ..RemoteClientConfig::default() }),
remote_server_config: None,
}
}

pub fn get_local_with_remote_enabled_component_config(
socket: SocketAddr,
) -> ReactiveComponentExecutionConfig {
ReactiveComponentExecutionConfig {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: Some(RemoteServerConfig { socket }),
}
}

pub async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig {
ComponentConfig {
http_server: ActiveComponentExecutionConfig::default(),
gateway: get_remote_component_config(gateway_socket),
gateway: ReactiveComponentExecutionConfig::remote(gateway_socket),
monitoring_endpoint: Default::default(),
batcher: get_disabled_component_config(),
batcher: ReactiveComponentExecutionConfig::disabled(),
consensus_manager: ActiveComponentExecutionConfig::disabled(),
mempool: get_disabled_component_config(),
mempool_p2p: get_disabled_component_config(),
state_sync: get_disabled_component_config(),
l1_provider: get_disabled_component_config(),
mempool: ReactiveComponentExecutionConfig::disabled(),
mempool_p2p: ReactiveComponentExecutionConfig::disabled(),
state_sync: ReactiveComponentExecutionConfig::disabled(),
l1_provider: ReactiveComponentExecutionConfig::disabled(),
}
}

pub async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig {
ComponentConfig {
http_server: ActiveComponentExecutionConfig::disabled(),
monitoring_endpoint: Default::default(),
gateway: get_local_with_remote_enabled_component_config(gateway_socket),
gateway: ReactiveComponentExecutionConfig::local_with_remote_enabled(gateway_socket),
..ComponentConfig::default()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::BTreeMap;
#[cfg(test)]
use std::net::SocketAddr;

use papyrus_config::dumping::{ser_optional_sub_config, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
Expand Down Expand Up @@ -60,6 +62,45 @@ impl SerializeConfig for ReactiveComponentExecutionConfig {

impl Default for ReactiveComponentExecutionConfig {
fn default() -> Self {
Self::local_with_remote_disabled()
}
}

#[cfg(test)]
impl ReactiveComponentExecutionConfig {
pub fn disabled() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::Disabled,
local_server_config: None,
remote_client_config: None,
remote_server_config: None,
}
}

pub fn remote(socket: SocketAddr) -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::Remote,
local_server_config: None,
remote_client_config: Some(RemoteClientConfig {
socket,
..RemoteClientConfig::default()
}),
remote_server_config: None,
}
}

pub fn local_with_remote_enabled(socket: SocketAddr) -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled,
local_server_config: Some(LocalServerConfig::default()),
remote_client_config: None,
remote_server_config: Some(RemoteServerConfig { socket }),
}
}
}

impl ReactiveComponentExecutionConfig {
pub fn local_with_remote_disabled() -> Self {
Self {
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteDisabled,
local_server_config: Some(LocalServerConfig::default()),
Expand Down

0 comments on commit 210647f

Please sign in to comment.