From 537f2b4d0eccd7b319064ee7e7f9f5f429dbcdc3 Mon Sep 17 00:00:00 2001 From: Noam Spiegelstein Date: Wed, 27 Nov 2024 15:36:50 +0200 Subject: [PATCH] feat(sync): create state sync client --- crates/starknet_sequencer_node/src/clients.rs | 31 +++++++++++++++++++ .../src/config/component_config.rs | 3 ++ .../src/config/component_execution_config.rs | 9 ++++++ 3 files changed, 43 insertions(+) diff --git a/crates/starknet_sequencer_node/src/clients.rs b/crates/starknet_sequencer_node/src/clients.rs index 4ef7440f010..ba3745f3ce2 100644 --- a/crates/starknet_sequencer_node/src/clients.rs +++ b/crates/starknet_sequencer_node/src/clients.rs @@ -29,6 +29,13 @@ use starknet_mempool_types::communication::{ SharedMempoolClient, }; use starknet_sequencer_infra::component_client::{Client, LocalComponentClient}; +use starknet_state_sync_types::communication::{ + LocalStateSyncClient, + RemoteStateSyncClient, + SharedStateSyncClient, + StateSyncRequest, + StateSyncResponse, +}; use crate::communication::SequencerNodeCommunication; use crate::config::component_execution_config::ComponentExecutionMode; @@ -41,6 +48,7 @@ pub struct SequencerNodeClients { // TODO (Lev): Change to Option>. mempool_p2p_propagator_client: Option>, + state_sync_client: Option>, } /// A macro to retrieve a shared client (either local or remote) from a specified field in a struct, @@ -148,6 +156,19 @@ impl SequencerNodeClients { None => None, } } + + pub fn get_state_sync_shared_client(&self) -> Option { + get_shared_client!(self, state_sync_client) + } + + pub fn get_state_sync_local_client( + &self, + ) -> Option> { + match &self.state_sync_client { + Some(client) => client.get_local_client(), + None => None, + } + } } /// A macro for creating a component client, determined by the component's execution mode. Returns a @@ -250,10 +271,20 @@ pub fn create_node_clients( channels.take_mempool_p2p_propagator_tx(), config.components.mempool_p2p.remote_client_config ); + + let state_sync_client = create_client!( + &config.components.state_sync.execution_mode, + LocalStateSyncClient, + RemoteStateSyncClient, + channels.take_state_sync_tx(), + config.components.state_sync.remote_client_config + ); + SequencerNodeClients { batcher_client, mempool_client, gateway_client, mempool_p2p_propagator_client, + state_sync_client, } } diff --git a/crates/starknet_sequencer_node/src/config/component_config.rs b/crates/starknet_sequencer_node/src/config/component_config.rs index fa5d3fcfc6a..2519d06eebf 100644 --- a/crates/starknet_sequencer_node/src/config/component_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_config.rs @@ -24,6 +24,8 @@ pub struct ComponentConfig { pub mempool_p2p: ComponentExecutionConfig, #[validate] pub monitoring_endpoint: ComponentExecutionConfig, + #[validate] + pub state_sync: ComponentExecutionConfig, } impl Default for ComponentConfig { @@ -36,6 +38,7 @@ impl Default for ComponentConfig { mempool: ComponentExecutionConfig::mempool_default_config(), mempool_p2p: ComponentExecutionConfig::mempool_p2p_default_config(), monitoring_endpoint: ComponentExecutionConfig::monitoring_endpoint_default_config(), + state_sync: ComponentExecutionConfig::state_sync_default_config(), } } } diff --git a/crates/starknet_sequencer_node/src/config/component_execution_config.rs b/crates/starknet_sequencer_node/src/config/component_execution_config.rs index 61a8a1d0ee0..36307210bba 100644 --- a/crates/starknet_sequencer_node/src/config/component_execution_config.rs +++ b/crates/starknet_sequencer_node/src/config/component_execution_config.rs @@ -133,6 +133,15 @@ impl ComponentExecutionConfig { remote_server_config: None, } } + + pub fn state_sync_default_config() -> Self { + Self { + execution_mode: ComponentExecutionMode::LocalExecutionWithRemoteDisabled, + local_server_config: Some(LocalServerConfig::default()), + remote_client_config: None, + remote_server_config: None, + } + } } pub fn validate_single_component_config(