Skip to content

Commit

Permalink
chore: move client functions to dedicated module
Browse files Browse the repository at this point in the history
commit-id:7ca0f454
  • Loading branch information
nadin-Starkware committed Nov 10, 2024
1 parent d627f52 commit cd50bf1
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 97 deletions.
83 changes: 83 additions & 0 deletions crates/sequencer_node/src/clients.rs
Original file line number Diff line number Diff line change
@@ -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<SharedBatcherClient>,
mempool_client: Option<SharedMempoolClient>,
gateway_client: Option<SharedGatewayClient>,
// TODO (Lev): Change to Option<Box<dyn MemPoolClient>>.
mempool_p2p_propagator_client: Option<SharedMempoolP2pPropagatorClient>,
}

impl SequencerNodeClients {
pub fn get_batcher_client(&self) -> Option<SharedBatcherClient> {
self.batcher_client.clone()
}

pub fn get_mempool_client(&self) -> Option<SharedMempoolClient> {
self.mempool_client.clone()
}

pub fn get_gateway_client(&self) -> Option<SharedGatewayClient> {
self.gateway_client.clone()
}

pub fn get_mempool_p2p_propagator_client(&self) -> Option<SharedMempoolP2pPropagatorClient> {
self.mempool_p2p_propagator_client.clone()
}
}

pub fn create_node_clients(
config: &SequencerNodeConfig,
channels: &mut SequencerNodeCommunication,
) -> SequencerNodeClients {
let batcher_client: Option<SharedBatcherClient> = 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<SharedMempoolClient> = 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<SharedGatewayClient> = 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<SharedMempoolP2pPropagatorClient> =
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,
}
}
99 changes: 4 additions & 95 deletions crates/sequencer_node/src/communication.rs
Original file line number Diff line number Diff line change
@@ -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<BatcherRequestAndResponseSender>,
mempool_channel: ComponentCommunication<MempoolRequestAndResponseSender>,
Expand Down Expand Up @@ -94,74 +74,3 @@ pub fn create_node_channels() -> SequencerNodeCommunication {
),
}
}

pub struct SequencerNodeClients {
batcher_client: Option<SharedBatcherClient>,
mempool_client: Option<SharedMempoolClient>,
gateway_client: Option<SharedGatewayClient>,
// TODO (Lev): Change to Option<Box<dyn MemPoolClient>>.
mempool_p2p_propagator_client: Option<SharedMempoolP2pPropagatorClient>,
}

impl SequencerNodeClients {
pub fn get_batcher_client(&self) -> Option<SharedBatcherClient> {
self.batcher_client.clone()
}

pub fn get_mempool_client(&self) -> Option<SharedMempoolClient> {
self.mempool_client.clone()
}

pub fn get_gateway_client(&self) -> Option<SharedGatewayClient> {
self.gateway_client.clone()
}

pub fn get_mempool_p2p_propagator_client(&self) -> Option<SharedMempoolP2pPropagatorClient> {
self.mempool_p2p_propagator_client.clone()
}
}

pub fn create_node_clients(
config: &SequencerNodeConfig,
channels: &mut SequencerNodeCommunication,
) -> SequencerNodeClients {
let batcher_client: Option<SharedBatcherClient> = 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<SharedMempoolClient> = 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<SharedGatewayClient> = 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<SharedMempoolP2pPropagatorClient> =
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,
}
}
2 changes: 1 addition & 1 deletion crates/sequencer_node/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions crates/sequencer_node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod clients;
pub mod communication;
pub mod components;
pub mod config;
Expand Down
3 changes: 2 additions & 1 deletion crates/sequencer_node/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit cd50bf1

Please sign in to comment.