Skip to content

Commit

Permalink
feat(starknet_state_sync): create state sync servers
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Dec 8, 2024
1 parent 8ca4162 commit 1bcede2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions crates/starknet_sequencer_node/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use starknet_sequencer_infra::component_server::{
WrapperServer,
};
use starknet_sequencer_infra::errors::ComponentServerError;
use starknet_state_sync::runner::StateSyncRunnerServer;
use starknet_state_sync::{LocalStateSyncServer, RemoteStateSyncServer};
use tracing::error;

use crate::clients::SequencerNodeClients;
Expand All @@ -34,6 +36,7 @@ struct LocalServers {
pub(crate) gateway: Option<Box<LocalGatewayServer>>,
pub(crate) mempool: Option<Box<LocalMempoolServer>>,
pub(crate) mempool_p2p_propagator: Option<Box<LocalMempoolP2pPropagatorServer>>,
pub(crate) state_sync: Option<Box<LocalStateSyncServer>>,
}

// Component servers that wrap a component without a server.
Expand All @@ -42,6 +45,7 @@ struct WrapperServers {
pub(crate) http_server: Option<Box<HttpServer>>,
pub(crate) monitoring_endpoint: Option<Box<MonitoringEndpointServer>>,
pub(crate) mempool_p2p_runner: Option<Box<MempoolP2pRunnerServer>>,
pub(crate) state_sync_runner: Option<Box<StateSyncRunnerServer>>,
}

// Component servers that can run remotely.
Expand All @@ -51,6 +55,7 @@ pub struct RemoteServers {
pub gateway: Option<Box<RemoteGatewayServer>>,
pub mempool: Option<Box<RemoteMempoolServer>>,
pub mempool_p2p_propagator: Option<Box<RemoteMempoolP2pPropagatorServer>>,
pub state_sync: Option<Box<RemoteStateSyncServer>>,
}

pub struct SequencerNodeServers {
Expand Down Expand Up @@ -232,11 +237,18 @@ fn create_local_servers(
components.mempool_p2p_propagator,
communication.take_mempool_p2p_propagator_rx()
);
let state_sync_server = create_local_server!(
&config.components.state_sync.execution_mode,
components.state_sync,
communication.take_state_sync_rx()
);

LocalServers {
batcher: batcher_server,
gateway: gateway_server,
mempool: mempool_server,
mempool_p2p_propagator: mempool_p2p_propagator_server,
state_sync: state_sync_server,
}
}

Expand Down Expand Up @@ -271,11 +283,20 @@ pub fn create_remote_servers(
mempool_p2p_propagator_client,
config.components.mempool_p2p.remote_server_config
);

let state_sync_client = clients.get_state_sync_local_client();
let state_sync_server = create_remote_server!(
&config.components.state_sync.execution_mode,
state_sync_client,
config.components.state_sync.remote_server_config
);

RemoteServers {
batcher: batcher_server,
gateway: gateway_server,
mempool: mempool_server,
mempool_p2p_propagator: mempool_p2p_propagator_server,
state_sync: state_sync_server,
}
}

Expand All @@ -301,11 +322,18 @@ fn create_wrapper_servers(
&config.components.mempool_p2p.execution_mode,
components.mempool_p2p_runner
);

let state_sync_runner_server = create_wrapper_server!(
&config.components.state_sync.execution_mode,
components.state_sync_runner
);

WrapperServers {
consensus_manager: consensus_manager_server,
http_server,
monitoring_endpoint: monitoring_endpoint_server,
mempool_p2p_runner: mempool_p2p_runner_server,
state_sync_runner: state_sync_runner_server,
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/starknet_state_sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use async_trait::async_trait;
use futures::channel::{mpsc, oneshot};
use futures::SinkExt;
use starknet_sequencer_infra::component_definitions::ComponentRequestHandler;
use starknet_sequencer_infra::component_server::{LocalComponentServer, RemoteComponentServer};
use starknet_state_sync_types::communication::{StateSyncRequest, StateSyncResponse};
use starknet_state_sync_types::errors::StateSyncError;

Expand Down Expand Up @@ -37,3 +38,7 @@ impl ComponentRequestHandler<StateSyncRequest, StateSyncResponse> for StateSync
})
}
}

pub type LocalStateSyncServer =
LocalComponentServer<StateSync, StateSyncRequest, StateSyncResponse>;
pub type RemoteStateSyncServer = RemoteComponentServer<StateSyncRequest, StateSyncResponse>;
2 changes: 2 additions & 0 deletions crates/starknet_state_sync/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use papyrus_storage::state::StateStorageReader;
use papyrus_storage::{open_storage, StorageReader};
use starknet_api::block::BlockNumber;
use starknet_sequencer_infra::component_definitions::ComponentStarter;
use starknet_sequencer_infra::component_server::WrapperServer;
use starknet_sequencer_infra::errors::ComponentError;
use starknet_state_sync_types::communication::{
StateSyncRequest,
Expand Down Expand Up @@ -143,5 +144,6 @@ impl StateSyncRunner {
}
}

pub type StateSyncRunnerServer = WrapperServer<StateSyncRunner>;
// TODO(shahak): fill with a proper version, or allow not specifying the node version.
const VERSION_FULL: &str = "";

0 comments on commit 1bcede2

Please sign in to comment.