From aa9f5d7119c1a02cb96cd8b2d80a5eb20f51382a Mon Sep 17 00:00:00 2001 From: Itay-Tsabary-Starkware <106665835+Itay-Tsabary-Starkware@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:19:18 +0300 Subject: [PATCH] chore(mempool_node): sort p2p client initialization (#1505) commit-id:3b194704 --- Cargo.lock | 1 - crates/mempool/src/communication.rs | 13 ++++++++----- crates/mempool_node/Cargo.toml | 1 - crates/mempool_node/src/components.rs | 17 ++++++++++++++--- crates/mempool_node/src/servers.rs | 3 --- crates/mempool_node/src/utils.rs | 11 +---------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84975f016a..7bda23630e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10432,7 +10432,6 @@ dependencies = [ "starknet_mempool", "starknet_mempool_infra", "starknet_mempool_p2p", - "starknet_mempool_p2p_types", "starknet_mempool_types", "starknet_monitoring_endpoint", "starknet_sierra_compile", diff --git a/crates/mempool/src/communication.rs b/crates/mempool/src/communication.rs index 6130cd07d2..a80d3bc10b 100644 --- a/crates/mempool/src/communication.rs +++ b/crates/mempool/src/communication.rs @@ -20,13 +20,16 @@ pub type LocalMempoolServer = LocalComponentServer; pub fn create_mempool_server( - mempool: Mempool, + mempool: MempoolCommunicationWrapper, rx_mempool: Receiver, - mempool_p2p_propagator_client: SharedMempoolP2pPropagatorClient, ) -> LocalMempoolServer { - let communication_wrapper = - MempoolCommunicationWrapper::new(mempool, mempool_p2p_propagator_client); - LocalComponentServer::new(communication_wrapper, rx_mempool) + LocalComponentServer::new(mempool, rx_mempool) +} + +pub fn create_mempool( + mempool_p2p_propagator_client: SharedMempoolP2pPropagatorClient, +) -> MempoolCommunicationWrapper { + MempoolCommunicationWrapper::new(Mempool::empty(), mempool_p2p_propagator_client) } /// Wraps the mempool to enable inbound async communication from other components. diff --git a/crates/mempool_node/Cargo.toml b/crates/mempool_node/Cargo.toml index dc26b2ee89..8a2101eddc 100644 --- a/crates/mempool_node/Cargo.toml +++ b/crates/mempool_node/Cargo.toml @@ -26,7 +26,6 @@ starknet_http_server.workspace = true starknet_mempool.workspace = true starknet_mempool_infra.workspace = true starknet_mempool_p2p.workspace = true -starknet_mempool_p2p_types.workspace = true starknet_mempool_types.workspace = true starknet_monitoring_endpoint.workspace = true starknet_sierra_compile.workspace = true diff --git a/crates/mempool_node/src/components.rs b/crates/mempool_node/src/components.rs index 734a968a4a..19efab468a 100644 --- a/crates/mempool_node/src/components.rs +++ b/crates/mempool_node/src/components.rs @@ -1,8 +1,11 @@ +use std::sync::Arc; + use starknet_batcher::batcher::{create_batcher, Batcher}; use starknet_consensus_manager::consensus_manager::ConsensusManager; use starknet_gateway::gateway::{create_gateway, Gateway}; use starknet_http_server::http_server::{create_http_server, HttpServer}; -use starknet_mempool::mempool::Mempool; +use starknet_mempool::communication::{create_mempool, MempoolCommunicationWrapper}; +use starknet_mempool_p2p::sender::EmptyMempoolP2pPropagatorClient; use starknet_monitoring_endpoint::monitoring_endpoint::{ create_monitoring_endpoint, MonitoringEndpoint, @@ -17,7 +20,7 @@ pub struct SequencerNodeComponents { pub consensus_manager: Option, pub gateway: Option, pub http_server: Option, - pub mempool: Option, + pub mempool: Option, pub monitoring_endpoint: Option, } @@ -64,7 +67,15 @@ pub fn create_node_components( None }; - let mempool = if config.components.mempool.execute { Some(Mempool::empty()) } else { None }; + let mempool = if config.components.mempool.execute { + // TODO(Lukach): obtain the mempool_p2p_propagator_client from 'clients', pass it as an + // argument to create_mempool. + let mempool_p2p_propagator_client = Arc::new(EmptyMempoolP2pPropagatorClient); + let mempool = create_mempool(mempool_p2p_propagator_client); + Some(mempool) + } else { + None + }; let monitoring_endpoint = if config.components.monitoring_endpoint.execute { Some(create_monitoring_endpoint(config.monitoring_endpoint_config.clone(), VERSION_FULL)) diff --git a/crates/mempool_node/src/servers.rs b/crates/mempool_node/src/servers.rs index d31530a088..4fc226363e 100644 --- a/crates/mempool_node/src/servers.rs +++ b/crates/mempool_node/src/servers.rs @@ -12,7 +12,6 @@ use starknet_http_server::communication::{create_http_server, HttpServer}; use starknet_mempool::communication::{create_mempool_server, LocalMempoolServer}; use starknet_mempool_infra::component_server::ComponentServerStarter; use starknet_mempool_infra::errors::ComponentServerError; -use starknet_mempool_p2p_types::communication::SharedMempoolP2pPropagatorClient; use starknet_monitoring_endpoint::communication::{ create_monitoring_endpoint_server, MonitoringEndpointServer, @@ -46,7 +45,6 @@ pub fn create_node_servers( config: &SequencerNodeConfig, communication: &mut SequencerNodeCommunication, components: SequencerNodeComponents, - mempool_p2p_propagator_client: SharedMempoolP2pPropagatorClient, ) -> SequencerNodeServers { let batcher_server = if config.components.batcher.execute { Some(Box::new(create_local_batcher_server( @@ -82,7 +80,6 @@ pub fn create_node_servers( Some(Box::new(create_mempool_server( components.mempool.expect("Mempool is not initialized."), communication.take_mempool_rx(), - mempool_p2p_propagator_client, ))) } else { None diff --git a/crates/mempool_node/src/utils.rs b/crates/mempool_node/src/utils.rs index 9a106918b5..91dc13e122 100644 --- a/crates/mempool_node/src/utils.rs +++ b/crates/mempool_node/src/utils.rs @@ -1,7 +1,3 @@ -use std::sync::Arc; - -use starknet_mempool_p2p::sender::EmptyMempoolP2pPropagatorClient; - use crate::communication::{create_node_channels, create_node_clients, SequencerNodeClients}; use crate::components::create_node_components; use crate::config::SequencerNodeConfig; @@ -13,12 +9,7 @@ pub fn create_node_modules( let mut channels = create_node_channels(); let clients = create_node_clients(config, &mut channels); let components = create_node_components(config, &clients); - let servers = create_node_servers( - config, - &mut channels, - components, - Arc::new(EmptyMempoolP2pPropagatorClient), - ); + let servers = create_node_servers(config, &mut channels, components); (clients, servers) }