From f08ecd8765ac052c7c4344ea316b835965ecc9d2 Mon Sep 17 00:00:00 2001 From: Noam Spiegelstein Date: Wed, 27 Nov 2024 16:48:29 +0200 Subject: [PATCH] feat(sync): create state sync components --- Cargo.lock | 1 + crates/starknet_sequencer_node/Cargo.toml | 1 + crates/starknet_sequencer_node/src/components.rs | 16 ++++++++++++++++ .../src/config/node_config.rs | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3fddafbc6bc..02aff1541d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10644,6 +10644,7 @@ dependencies = [ "starknet_sequencer_infra", "starknet_sequencer_node", "starknet_sierra_compile", + "starknet_state_sync", "starknet_state_sync_types", "thiserror", "tokio", diff --git a/crates/starknet_sequencer_node/Cargo.toml b/crates/starknet_sequencer_node/Cargo.toml index 29aa72a10ae..b85f1df9755 100644 --- a/crates/starknet_sequencer_node/Cargo.toml +++ b/crates/starknet_sequencer_node/Cargo.toml @@ -35,6 +35,7 @@ starknet_mempool_types.workspace = true starknet_monitoring_endpoint.workspace = true starknet_sequencer_infra.workspace = true starknet_sierra_compile.workspace = true +starknet_state_sync.workspace = true starknet_state_sync_types.workspace = true thiserror = { workspace = true, optional = true } tokio.workspace = true diff --git a/crates/starknet_sequencer_node/src/components.rs b/crates/starknet_sequencer_node/src/components.rs index 266f37f15ed..6a78a507c47 100644 --- a/crates/starknet_sequencer_node/src/components.rs +++ b/crates/starknet_sequencer_node/src/components.rs @@ -10,6 +10,8 @@ use starknet_monitoring_endpoint::monitoring_endpoint::{ create_monitoring_endpoint, MonitoringEndpoint, }; +use starknet_state_sync::runner::StateSyncRunner; +use starknet_state_sync::{create_state_sync_and_runner, StateSync}; use crate::clients::SequencerNodeClients; use crate::config::component_execution_config::ComponentExecutionMode; @@ -25,6 +27,8 @@ pub struct SequencerNodeComponents { pub monitoring_endpoint: Option, pub mempool_p2p_propagator: Option, pub mempool_p2p_runner: Option, + pub state_sync: Option, + pub state_sync_runner: Option, } pub fn create_node_components( @@ -111,6 +115,16 @@ pub fn create_node_components( ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => None, }; + let (state_sync, state_sync_runner) = match config.components.state_sync.execution_mode { + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled => { + let (state_sync, state_sync_runner) = + create_state_sync_and_runner(config.state_sync_config.clone()); + (Some(state_sync), Some(state_sync_runner)) + } + ComponentExecutionMode::Disabled | ComponentExecutionMode::Remote => (None, None), + }; + SequencerNodeComponents { batcher, consensus_manager, @@ -120,5 +134,7 @@ pub fn create_node_components( monitoring_endpoint, mempool_p2p_propagator, mempool_p2p_runner, + state_sync, + state_sync_runner, } } diff --git a/crates/starknet_sequencer_node/src/config/node_config.rs b/crates/starknet_sequencer_node/src/config/node_config.rs index 2679e234e7e..28c6084d457 100644 --- a/crates/starknet_sequencer_node/src/config/node_config.rs +++ b/crates/starknet_sequencer_node/src/config/node_config.rs @@ -26,6 +26,7 @@ use starknet_http_server::config::HttpServerConfig; use starknet_mempool_p2p::config::MempoolP2pConfig; use starknet_monitoring_endpoint::config::MonitoringEndpointConfig; use starknet_sierra_compile::config::SierraToCasmCompilationConfig; +use starknet_state_sync::config::StateSyncConfig; use validator::Validate; use crate::config::component_config::ComponentConfig; @@ -122,6 +123,8 @@ pub struct SequencerNodeConfig { pub mempool_p2p_config: MempoolP2pConfig, #[validate] pub monitoring_endpoint_config: MonitoringEndpointConfig, + #[validate] + pub state_sync_config: StateSyncConfig, } impl SerializeConfig for SequencerNodeConfig { @@ -142,6 +145,7 @@ impl SerializeConfig for SequencerNodeConfig { self.monitoring_endpoint_config.dump(), "monitoring_endpoint_config", ), + append_sub_config_name(self.state_sync_config.dump(), "state_sync_config"), ]; sub_configs.into_iter().flatten().collect()