Skip to content

Commit

Permalink
feat(sync): create state sync client
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Nov 27, 2024
1 parent e5576a4 commit 537f2b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/starknet_sequencer_node/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +48,7 @@ pub struct SequencerNodeClients {
// TODO (Lev): Change to Option<Box<dyn MemPoolClient>>.
mempool_p2p_propagator_client:
Option<Client<MempoolP2pPropagatorRequest, MempoolP2pPropagatorResponse>>,
state_sync_client: Option<Client<StateSyncRequest, StateSyncResponse>>,
}

/// A macro to retrieve a shared client (either local or remote) from a specified field in a struct,
Expand Down Expand Up @@ -148,6 +156,19 @@ impl SequencerNodeClients {
None => None,
}
}

pub fn get_state_sync_shared_client(&self) -> Option<SharedStateSyncClient> {
get_shared_client!(self, state_sync_client)
}

pub fn get_state_sync_local_client(
&self,
) -> Option<LocalComponentClient<StateSyncRequest, StateSyncResponse>> {
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
Expand Down Expand Up @@ -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,
}
}
3 changes: 3 additions & 0 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 537f2b4

Please sign in to comment.