From 490bf565a02328dadd3e85d19df3bd1c4d2d7554 Mon Sep 17 00:00:00 2001 From: Uriel Korach Date: Sun, 11 Aug 2024 11:17:20 +0300 Subject: [PATCH] refactor: move node's main functionality into a public function --- crates/mempool_node/src/lib.rs | 1 + crates/mempool_node/src/main.rs | 10 +++------- crates/mempool_node/src/utils.rs | 15 +++++++++++++++ .../src/integration_test_setup.rs | 17 +++-------------- 4 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 crates/mempool_node/src/utils.rs diff --git a/crates/mempool_node/src/lib.rs b/crates/mempool_node/src/lib.rs index 1a31b0bf52..a87a5ea274 100644 --- a/crates/mempool_node/src/lib.rs +++ b/crates/mempool_node/src/lib.rs @@ -2,4 +2,5 @@ pub mod communication; pub mod components; pub mod config; pub mod servers; +pub mod utils; pub mod version; diff --git a/crates/mempool_node/src/main.rs b/crates/mempool_node/src/main.rs index f54e926bd6..7ab874fd80 100644 --- a/crates/mempool_node/src/main.rs +++ b/crates/mempool_node/src/main.rs @@ -4,10 +4,9 @@ use std::process::exit; use papyrus_config::validators::config_validate; use papyrus_config::ConfigError; use starknet_mempool_infra::trace_util::configure_tracing; -use starknet_mempool_node::communication::{create_node_channels, create_node_clients}; -use starknet_mempool_node::components::create_components; use starknet_mempool_node::config::MempoolNodeConfig; -use starknet_mempool_node::servers::{create_servers, run_component_servers}; +use starknet_mempool_node::servers::run_component_servers; +use starknet_mempool_node::utils::create_clients_servers_from_config; use tracing::{error, info}; #[tokio::main] @@ -25,10 +24,7 @@ async fn main() -> anyhow::Result<()> { exit(1); } - let mut channels = create_node_channels(); - let clients = create_node_clients(&config, &mut channels); - let components = create_components(&config, &clients); - let servers = create_servers(&config, &mut channels, components); + let (_, servers) = create_clients_servers_from_config(&config); info!("Starting components!"); run_component_servers(&config, servers).await?; diff --git a/crates/mempool_node/src/utils.rs b/crates/mempool_node/src/utils.rs new file mode 100644 index 0000000000..6cece8bae5 --- /dev/null +++ b/crates/mempool_node/src/utils.rs @@ -0,0 +1,15 @@ +use crate::communication::{create_node_channels, create_node_clients, MempoolNodeClients}; +use crate::components::create_components; +use crate::config::MempoolNodeConfig; +use crate::servers::{create_servers, Servers}; + +pub fn create_clients_servers_from_config( + config: &MempoolNodeConfig, +) -> (MempoolNodeClients, Servers) { + let mut channels = create_node_channels(); + let clients = create_node_clients(config, &mut channels); + let components = create_components(config, &clients); + let servers = create_servers(config, &mut channels, components); + + (clients, servers) +} diff --git a/crates/tests-integration/src/integration_test_setup.rs b/crates/tests-integration/src/integration_test_setup.rs index 85998f9fc7..fd66bf6a27 100644 --- a/crates/tests-integration/src/integration_test_setup.rs +++ b/crates/tests-integration/src/integration_test_setup.rs @@ -7,9 +7,8 @@ use starknet_api::transaction::TransactionHash; use starknet_gateway::config::GatewayNetworkConfig; use starknet_gateway::errors::GatewaySpecError; use starknet_mempool_infra::trace_util::configure_tracing; -use starknet_mempool_node::communication::{create_node_channels, create_node_clients}; -use starknet_mempool_node::components::create_components; -use starknet_mempool_node::servers::{create_servers, get_server_future}; +use starknet_mempool_node::servers::get_server_future; +use starknet_mempool_node::utils::create_clients_servers_from_config; use starknet_mempool_types::mempool_types::ThinTransaction; use starknet_task_executor::tokio_executor::TokioExecutor; use tokio::runtime::Handle; @@ -50,17 +49,7 @@ impl IntegrationTestSetup { // Derive the configuration for the mempool node. let config = create_config(rpc_server_addr).await; - // Create the communication network for the mempool node. - let mut channels = create_node_channels(); - - // Create the clients for the mempool node. - let clients = create_node_clients(&config, &mut channels); - - // Create the components for the mempool node. - let components = create_components(&config, &clients); - - // Create the servers for the mempool node. - let servers = create_servers(&config, &mut channels, components); + let (clients, servers) = create_clients_servers_from_config(&config); let GatewayNetworkConfig { ip, port } = config.gateway_config.network_config; let gateway_client = GatewayClient::new(SocketAddr::from((ip, port)));