Skip to content

Commit

Permalink
refactor: move node's main functionality into a public function
Browse files Browse the repository at this point in the history
  • Loading branch information
uriel-starkware committed Aug 13, 2024
1 parent f8a57da commit 490bf56
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions crates/mempool_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod communication;
pub mod components;
pub mod config;
pub mod servers;
pub mod utils;
pub mod version;
10 changes: 3 additions & 7 deletions crates/mempool_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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?;
Expand Down
15 changes: 15 additions & 0 deletions crates/mempool_node/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 3 additions & 14 deletions crates/tests-integration/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 490bf56

Please sign in to comment.