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 23, 2024
1 parent 1af62a9 commit 6c22bb5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 75 deletions.
3 changes: 3 additions & 0 deletions crates/starknet_integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition.workspace = true
repository.workspace = true
license.workspace = true

[features]
testing = []

[lints]
workspace = true

Expand Down
75 changes: 0 additions & 75 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
use std::fs::File;
use std::io::Write;
use std::net::SocketAddr;
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,
CONFIG_NON_POINTERS_WHITELIST,
Expand Down Expand Up @@ -110,68 +97,6 @@ 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),
monitoring_endpoint: Default::default(),
batcher: get_disabled_component_config(),
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(),
}
}

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),
..ComponentConfig::default()
}
}

pub async fn get_remote_flow_test_config() -> Vec<ComponentConfig> {
let gateway_socket = get_available_socket().await;
vec![
get_http_only_component_config(gateway_socket).await,
get_non_http_component_config(gateway_socket).await,
]
}

/// Transforms a nested JSON dictionary object into a simplified JSON dictionary object by
/// extracting specific values from the inner dictionaries.
///
Expand Down
46 changes: 46 additions & 0 deletions crates/starknet_integration_tests/src/end_to_end_integration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(any(feature = "testing", test))]
use std::net::SocketAddr;

use infra_utils::run_until::run_until;
use infra_utils::tracing::{CustomLogger, TraceLevel};
use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator};
Expand All @@ -7,6 +10,15 @@ use papyrus_storage::StorageReader;
use starknet_api::block::BlockNumber;
use starknet_api::core::{ContractAddress, Nonce};
use starknet_api::state::StateNumber;
#[cfg(any(feature = "testing", test))]
use starknet_sequencer_infra::test_utils::get_available_socket;
#[cfg(any(feature = "testing", test))]
use starknet_sequencer_node::config::component_config::ComponentConfig;
#[cfg(any(feature = "testing", test))]
use starknet_sequencer_node::config::component_execution_config::{
ActiveComponentExecutionConfig,
ReactiveComponentExecutionConfig,
};
use starknet_sequencer_node::test_utils::node_runner::{get_node_executable_path, spawn_run_node};
use starknet_types_core::felt::Felt;
use tokio::join;
Expand Down Expand Up @@ -124,3 +136,37 @@ pub async fn end_to_end_integration(mut tx_generator: MultiAccountTransactionGen
let nonce = get_account_nonce(&batcher_storage_reader, sender_address);
assert_eq!(nonce, expected_nonce);
}

#[cfg(any(feature = "testing", test))]
async fn get_http_only_component_config(gateway_socket: SocketAddr) -> ComponentConfig {
ComponentConfig {
http_server: ActiveComponentExecutionConfig::default(),
gateway: ReactiveComponentExecutionConfig::remote(gateway_socket),
monitoring_endpoint: Default::default(),
batcher: ReactiveComponentExecutionConfig::disabled(),
consensus_manager: ActiveComponentExecutionConfig::disabled(),
mempool: ReactiveComponentExecutionConfig::disabled(),
mempool_p2p: ReactiveComponentExecutionConfig::disabled(),
state_sync: ReactiveComponentExecutionConfig::disabled(),
l1_provider: ReactiveComponentExecutionConfig::disabled(),
}
}

#[cfg(any(feature = "testing", test))]
async fn get_non_http_component_config(gateway_socket: SocketAddr) -> ComponentConfig {
ComponentConfig {
http_server: ActiveComponentExecutionConfig::disabled(),
monitoring_endpoint: Default::default(),
gateway: ReactiveComponentExecutionConfig::local_with_remote_enabled(gateway_socket),
..ComponentConfig::default()
}
}

#[cfg(any(feature = "testing", test))]
async fn get_remote_flow_test_config() -> Vec<ComponentConfig> {
let gateway_socket = get_available_socket().await;
vec![
get_http_only_component_config(gateway_socket).await,
get_non_http_component_config(gateway_socket).await,
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
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 +61,45 @@ impl SerializeConfig for ReactiveComponentExecutionConfig {

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

#[cfg(any(feature = "testing", 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 6c22bb5

Please sign in to comment.