Skip to content

Commit

Permalink
refactor(starknet_integration_tests): move node component configs to …
Browse files Browse the repository at this point in the history
…seperate mod (#4090)

commit-id:505b2210
  • Loading branch information
nadin-Starkware authored Feb 20, 2025
1 parent 02b030e commit 176ec00
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 183 deletions.
1 change: 1 addition & 0 deletions crates/starknet_integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod flow_test_setup;
pub mod integration_test_setup;
pub mod integration_test_utils;
pub mod monitoring_utils;
pub mod node_component_configs;
pub mod sequencer_manager;
pub mod sequencer_simulator_utils;
pub mod state_reader;
Expand Down
185 changes: 185 additions & 0 deletions crates/starknet_integration_tests/src/node_component_configs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
use std::net::SocketAddr;

use starknet_infra_utils::test_utils::AvailablePorts;
use starknet_sequencer_node::config::component_config::ComponentConfig;
use starknet_sequencer_node::config::component_execution_config::{
ActiveComponentExecutionConfig,
ReactiveComponentExecutionConfig,
};

/// Holds the component configs for a set of sequencers, composing a single sequencer node.
pub struct NodeComponentConfigs {
component_configs: Vec<ComponentConfig>,
batcher_index: usize,
http_server_index: usize,
}

impl NodeComponentConfigs {
fn new(
component_configs: Vec<ComponentConfig>,
batcher_index: usize,
http_server_index: usize,
) -> Self {
Self { component_configs, batcher_index, http_server_index }
}

// pub fn into_iter(self) -> impl Iterator<Item = ComponentConfig> {
// self.component_configs.into_iter()
// }

pub fn len(&self) -> usize {
self.component_configs.len()
}

pub fn is_empty(&self) -> bool {
self.component_configs.is_empty()
}

pub fn get_batcher_index(&self) -> usize {
self.batcher_index
}

pub fn get_http_server_index(&self) -> usize {
self.http_server_index
}
}

impl IntoIterator for NodeComponentConfigs {
type Item = ComponentConfig;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.component_configs.into_iter()
}
}

/// Generates configurations for a specified number of distributed sequencer nodes,
/// each consisting of an HTTP component configuration and a non-HTTP component configuration.
/// returns a vector of vectors, where each inner vector contains the two configurations.
pub fn create_distributed_node_configs(
available_ports: &mut AvailablePorts,
distributed_sequencers_num: usize,
) -> Vec<NodeComponentConfigs> {
std::iter::repeat_with(|| {
let gateway_socket = available_ports.get_next_local_host_socket();
let mempool_socket = available_ports.get_next_local_host_socket();
let mempool_p2p_socket = available_ports.get_next_local_host_socket();
let state_sync_socket = available_ports.get_next_local_host_socket();
let class_manager_socket = available_ports.get_next_local_host_socket();

NodeComponentConfigs::new(
vec![
get_http_container_config(
gateway_socket,
mempool_socket,
mempool_p2p_socket,
state_sync_socket,
class_manager_socket,
),
get_non_http_container_config(
gateway_socket,
mempool_socket,
mempool_p2p_socket,
state_sync_socket,
class_manager_socket,
),
],
// batcher is in executable index 1.
1,
// http server is in executable index 0.
0,
)
})
.take(distributed_sequencers_num)
.collect()
}

pub fn create_consolidated_sequencer_configs(
num_of_consolidated_nodes: usize,
) -> Vec<NodeComponentConfigs> {
// Both batcher and http server are in executable index 0.
std::iter::repeat_with(|| NodeComponentConfigs::new(vec![ComponentConfig::default()], 0, 0))
.take(num_of_consolidated_nodes)
.collect()
}

// TODO(Nadin/Tsabary): find a better name for this function.
fn get_http_container_config(
gateway_socket: SocketAddr,
mempool_socket: SocketAddr,
mempool_p2p_socket: SocketAddr,
state_sync_socket: SocketAddr,
class_manager_socket: SocketAddr,
) -> ComponentConfig {
let mut config = ComponentConfig::disabled();
config.http_server = ActiveComponentExecutionConfig::default();
let local_url = "127.0.0.1".to_string();
config.gateway = ReactiveComponentExecutionConfig::local_with_remote_enabled(
local_url.clone(),
gateway_socket.ip(),
gateway_socket.port(),
);
config.mempool = ReactiveComponentExecutionConfig::local_with_remote_enabled(
local_url.clone(),
mempool_socket.ip(),
mempool_socket.port(),
);
config.mempool_p2p = ReactiveComponentExecutionConfig::local_with_remote_enabled(
local_url.clone(),
mempool_p2p_socket.ip(),
mempool_p2p_socket.port(),
);
config.state_sync = ReactiveComponentExecutionConfig::remote(
local_url.clone(),
state_sync_socket.ip(),
state_sync_socket.port(),
);
config.class_manager = ReactiveComponentExecutionConfig::local_with_remote_enabled(
local_url.clone(),
class_manager_socket.ip(),
class_manager_socket.port(),
);
config.sierra_compiler = ReactiveComponentExecutionConfig::local_with_remote_disabled();
config.monitoring_endpoint = ActiveComponentExecutionConfig::default();
config
}

fn get_non_http_container_config(
gateway_socket: SocketAddr,
mempool_socket: SocketAddr,
mempool_p2p_socket: SocketAddr,
state_sync_socket: SocketAddr,
class_manager_socket: SocketAddr,
) -> ComponentConfig {
let local_url = "127.0.0.1".to_string();
ComponentConfig {
http_server: ActiveComponentExecutionConfig::disabled(),
monitoring_endpoint: Default::default(),
gateway: ReactiveComponentExecutionConfig::remote(
local_url.clone(),
gateway_socket.ip(),
gateway_socket.port(),
),
mempool: ReactiveComponentExecutionConfig::remote(
local_url.clone(),
mempool_socket.ip(),
mempool_socket.port(),
),
mempool_p2p: ReactiveComponentExecutionConfig::remote(
local_url.clone(),
mempool_p2p_socket.ip(),
mempool_p2p_socket.port(),
),
state_sync: ReactiveComponentExecutionConfig::local_with_remote_enabled(
local_url.clone(),
state_sync_socket.ip(),
state_sync_socket.port(),
),
class_manager: ReactiveComponentExecutionConfig::remote(
local_url.clone(),
class_manager_socket.ip(),
class_manager_socket.port(),
),
..ComponentConfig::default()
}
}
Loading

0 comments on commit 176ec00

Please sign in to comment.