From cd50bf12a513a8199e55122512c27fefc274aed0 Mon Sep 17 00:00:00 2001 From: nadin-Starkware Date: Thu, 7 Nov 2024 16:06:57 +0200 Subject: [PATCH] chore: move client functions to dedicated module commit-id:7ca0f454 --- crates/sequencer_node/src/clients.rs | 83 ++++++++++++++++++ crates/sequencer_node/src/communication.rs | 99 +--------------------- crates/sequencer_node/src/components.rs | 2 +- crates/sequencer_node/src/lib.rs | 1 + crates/sequencer_node/src/utils.rs | 3 +- 5 files changed, 91 insertions(+), 97 deletions(-) create mode 100644 crates/sequencer_node/src/clients.rs diff --git a/crates/sequencer_node/src/clients.rs b/crates/sequencer_node/src/clients.rs new file mode 100644 index 0000000000..00b069b3ae --- /dev/null +++ b/crates/sequencer_node/src/clients.rs @@ -0,0 +1,83 @@ +use std::sync::Arc; + +use starknet_batcher_types::communication::{LocalBatcherClient, SharedBatcherClient}; +use starknet_gateway_types::communication::{LocalGatewayClient, SharedGatewayClient}; +use starknet_mempool_p2p_types::communication::{ + LocalMempoolP2pPropagatorClient, + SharedMempoolP2pPropagatorClient, +}; +use starknet_mempool_types::communication::{LocalMempoolClient, SharedMempoolClient}; + +use crate::communication::SequencerNodeCommunication; +use crate::config::{ComponentExecutionMode, SequencerNodeConfig}; + +pub struct SequencerNodeClients { + batcher_client: Option, + mempool_client: Option, + gateway_client: Option, + // TODO (Lev): Change to Option>. + mempool_p2p_propagator_client: Option, +} + +impl SequencerNodeClients { + pub fn get_batcher_client(&self) -> Option { + self.batcher_client.clone() + } + + pub fn get_mempool_client(&self) -> Option { + self.mempool_client.clone() + } + + pub fn get_gateway_client(&self) -> Option { + self.gateway_client.clone() + } + + pub fn get_mempool_p2p_propagator_client(&self) -> Option { + self.mempool_p2p_propagator_client.clone() + } +} + +pub fn create_node_clients( + config: &SequencerNodeConfig, + channels: &mut SequencerNodeCommunication, +) -> SequencerNodeClients { + let batcher_client: Option = match config.components.batcher.execution_mode + { + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + Some(Arc::new(LocalBatcherClient::new(channels.take_batcher_tx()))) + } + ComponentExecutionMode::Disabled => None, + }; + let mempool_client: Option = match config.components.mempool.execution_mode + { + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + Some(Arc::new(LocalMempoolClient::new(channels.take_mempool_tx()))) + } + ComponentExecutionMode::Disabled => None, + }; + let gateway_client: Option = match config.components.gateway.execution_mode + { + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + Some(Arc::new(LocalGatewayClient::new(channels.take_gateway_tx()))) + } + ComponentExecutionMode::Disabled => None, + }; + + let mempool_p2p_propagator_client: Option = + match config.components.mempool.execution_mode { + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => Some(Arc::new( + LocalMempoolP2pPropagatorClient::new(channels.take_mempool_p2p_propagator_tx()), + )), + ComponentExecutionMode::Disabled => None, + }; + SequencerNodeClients { + batcher_client, + mempool_client, + gateway_client, + mempool_p2p_propagator_client, + } +} diff --git a/crates/sequencer_node/src/communication.rs b/crates/sequencer_node/src/communication.rs index 27e756d143..7bf9054ec1 100644 --- a/crates/sequencer_node/src/communication.rs +++ b/crates/sequencer_node/src/communication.rs @@ -1,30 +1,10 @@ -use std::sync::Arc; - -use starknet_batcher_types::communication::{ - BatcherRequestAndResponseSender, - LocalBatcherClient, - SharedBatcherClient, -}; -use starknet_gateway_types::communication::{ - GatewayRequestAndResponseSender, - LocalGatewayClient, - SharedGatewayClient, -}; -use starknet_mempool_p2p_types::communication::{ - LocalMempoolP2pPropagatorClient, - MempoolP2pPropagatorRequestAndResponseSender, - SharedMempoolP2pPropagatorClient, -}; -use starknet_mempool_types::communication::{ - LocalMempoolClient, - MempoolRequestAndResponseSender, - SharedMempoolClient, -}; +use starknet_batcher_types::communication::BatcherRequestAndResponseSender; +use starknet_gateway_types::communication::GatewayRequestAndResponseSender; +use starknet_mempool_p2p_types::communication::MempoolP2pPropagatorRequestAndResponseSender; +use starknet_mempool_types::communication::MempoolRequestAndResponseSender; use starknet_sequencer_infra::component_definitions::ComponentCommunication; use tokio::sync::mpsc::{channel, Receiver, Sender}; -use crate::config::{ComponentExecutionMode, SequencerNodeConfig}; - pub struct SequencerNodeCommunication { batcher_channel: ComponentCommunication, mempool_channel: ComponentCommunication, @@ -94,74 +74,3 @@ pub fn create_node_channels() -> SequencerNodeCommunication { ), } } - -pub struct SequencerNodeClients { - batcher_client: Option, - mempool_client: Option, - gateway_client: Option, - // TODO (Lev): Change to Option>. - mempool_p2p_propagator_client: Option, -} - -impl SequencerNodeClients { - pub fn get_batcher_client(&self) -> Option { - self.batcher_client.clone() - } - - pub fn get_mempool_client(&self) -> Option { - self.mempool_client.clone() - } - - pub fn get_gateway_client(&self) -> Option { - self.gateway_client.clone() - } - - pub fn get_mempool_p2p_propagator_client(&self) -> Option { - self.mempool_p2p_propagator_client.clone() - } -} - -pub fn create_node_clients( - config: &SequencerNodeConfig, - channels: &mut SequencerNodeCommunication, -) -> SequencerNodeClients { - let batcher_client: Option = match config.components.batcher.execution_mode - { - ComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { - Some(Arc::new(LocalBatcherClient::new(channels.take_batcher_tx()))) - } - ComponentExecutionMode::Disabled => None, - }; - let mempool_client: Option = match config.components.mempool.execution_mode - { - ComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { - Some(Arc::new(LocalMempoolClient::new(channels.take_mempool_tx()))) - } - ComponentExecutionMode::Disabled => None, - }; - let gateway_client: Option = match config.components.gateway.execution_mode - { - ComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { - Some(Arc::new(LocalGatewayClient::new(channels.take_gateway_tx()))) - } - ComponentExecutionMode::Disabled => None, - }; - - let mempool_p2p_propagator_client: Option = - match config.components.mempool.execution_mode { - ComponentExecutionMode::LocalExecutionWithRemoteDisabled - | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => Some(Arc::new( - LocalMempoolP2pPropagatorClient::new(channels.take_mempool_p2p_propagator_tx()), - )), - ComponentExecutionMode::Disabled => None, - }; - SequencerNodeClients { - batcher_client, - mempool_client, - gateway_client, - mempool_p2p_propagator_client, - } -} diff --git a/crates/sequencer_node/src/components.rs b/crates/sequencer_node/src/components.rs index e5bed7e8f6..3b18f97cfb 100644 --- a/crates/sequencer_node/src/components.rs +++ b/crates/sequencer_node/src/components.rs @@ -11,7 +11,7 @@ use starknet_monitoring_endpoint::monitoring_endpoint::{ MonitoringEndpoint, }; -use crate::communication::SequencerNodeClients; +use crate::clients::SequencerNodeClients; use crate::config::{ComponentExecutionMode, SequencerNodeConfig}; use crate::version::VERSION_FULL; diff --git a/crates/sequencer_node/src/lib.rs b/crates/sequencer_node/src/lib.rs index 4279dd18d6..bd19e00134 100644 --- a/crates/sequencer_node/src/lib.rs +++ b/crates/sequencer_node/src/lib.rs @@ -1,3 +1,4 @@ +pub mod clients; pub mod communication; pub mod components; pub mod config; diff --git a/crates/sequencer_node/src/utils.rs b/crates/sequencer_node/src/utils.rs index 3ddd16378b..033e76ddf8 100644 --- a/crates/sequencer_node/src/utils.rs +++ b/crates/sequencer_node/src/utils.rs @@ -1,7 +1,8 @@ use std::env; use std::path::PathBuf; -use crate::communication::{create_node_channels, create_node_clients, SequencerNodeClients}; +use crate::clients::{create_node_clients, SequencerNodeClients}; +use crate::communication::create_node_channels; use crate::components::create_node_components; use crate::config::SequencerNodeConfig; use crate::servers::{create_node_servers, SequencerNodeServers};