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 28, 2024
1 parent e68acb3 commit 6f268c8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
50 changes: 50 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,56 @@
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"components.state_sync.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
"value": "LocalExecutionWithRemoteDisabled"
},
"components.state_sync.local_server_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": false
},
"components.state_sync.local_server_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.state_sync.remote_client_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.state_sync.remote_client_config.idle_connections": {
"description": "The maximum number of idle connections to keep alive.",
"privacy": "Public",
"value": 18446744073709551615
},
"components.state_sync.remote_client_config.idle_timeout": {
"description": "The duration in seconds to keep an idle connection open before closing.",
"privacy": "Public",
"value": 90
},
"components.state_sync.remote_client_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.state_sync.remote_client_config.socket": {
"description": "The remote component server socket.",
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"components.state_sync.remote_server_config.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.state_sync.remote_server_config.socket": {
"description": "The remote component server socket.",
"privacy": "Public",
"value": "0.0.0.0:8080"
},
"consensus_manager_config.consensus_config.consensus_delay": {
"description": "Delay (seconds) before starting consensus to give time for network peering.",
"privacy": "Public",
Expand Down
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,
}
}
4 changes: 4 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 All @@ -50,6 +53,7 @@ impl SerializeConfig for ComponentConfig {
append_sub_config_name(self.mempool.dump(), "mempool"),
append_sub_config_name(self.mempool_p2p.dump(), "mempool_p2p"),
append_sub_config_name(self.monitoring_endpoint.dump(), "monitoring_endpoint"),
append_sub_config_name(self.state_sync.dump(), "state_sync"),
];

sub_configs.into_iter().flatten().collect()
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 6f268c8

Please sign in to comment.