Skip to content

Commit

Permalink
feat(starknet_sequencer_node): creating communication clients for cla…
Browse files Browse the repository at this point in the history
…ss manager and serra compiler

commit-id:a12ae4a1
  • Loading branch information
lev-starkware committed Jan 16, 2025
1 parent 1e9cbaf commit 8950f16
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,36 @@
"privacy": "Public",
"value": "0.0.0.0:0"
},
"components.class_manager.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
"value": "LocalExecutionWithRemoteDisabled"
},
"components.class_manager.local_server_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.class_manager.remote_client_config.idle_connections": {
"description": "The maximum number of idle connections to keep alive.",
"privacy": "Public",
"value": 18446744073709551615
},
"components.class_manager.remote_client_config.idle_timeout": {
"description": "The duration in seconds to keep an idle connection open before closing.",
"privacy": "Public",
"value": 90
},
"components.class_manager.remote_client_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.class_manager.socket": {
"description": "The remote component socket.",
"privacy": "Public",
"value": "0.0.0.0:0"
},
"components.consensus_manager.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
Expand Down Expand Up @@ -479,6 +509,36 @@
"privacy": "Public",
"value": "Enabled"
},
"components.sierra_compiler.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
"value": "LocalExecutionWithRemoteDisabled"
},
"components.sierra_compiler.local_server_config.channel_buffer_size": {
"description": "The communication channel buffer size.",
"privacy": "Public",
"value": 32
},
"components.sierra_compiler.remote_client_config.idle_connections": {
"description": "The maximum number of idle connections to keep alive.",
"privacy": "Public",
"value": 18446744073709551615
},
"components.sierra_compiler.remote_client_config.idle_timeout": {
"description": "The duration in seconds to keep an idle connection open before closing.",
"privacy": "Public",
"value": 90
},
"components.sierra_compiler.remote_client_config.retries": {
"description": "The max number of retries for sending a message.",
"privacy": "Public",
"value": 3
},
"components.sierra_compiler.socket": {
"description": "The remote component socket.",
"privacy": "Public",
"value": "0.0.0.0:0"
},
"components.state_sync.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
Expand Down
17 changes: 15 additions & 2 deletions crates/starknet_class_manager_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ use starknet_api::contract_class::ContractClass;
use starknet_api::core::{ClassHash, CompiledClassHash};
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedClass;
use starknet_api::state::SierraContractClass;
use starknet_sequencer_infra::component_client::ClientError;
use starknet_sequencer_infra::component_definitions::ComponentClient;
use starknet_sequencer_infra::component_client::{
ClientError,
LocalComponentClient,
RemoteComponentClient,
};
use starknet_sequencer_infra::component_definitions::{
ComponentClient,
ComponentRequestAndResponseSender,
};
use thiserror::Error;

pub type ClassManagerResult<T> = Result<T, ClassManagerError>;
pub type ClassManagerClientResult<T> = Result<T, ClassManagerClientError>;

pub type LocalClassManagerClient = LocalComponentClient<ClassManagerRequest, ClassManagerResponse>;
pub type RemoteClassManagerClient =
RemoteComponentClient<ClassManagerRequest, ClassManagerResponse>;

pub type SharedClassManagerClient = Arc<dyn ClassManagerClient>;
pub type ClassManagerRequestAndResponseSender =
ComponentRequestAndResponseSender<ClassManagerRequest, ClassManagerResponse>;

// TODO: export.
pub type ClassId = ClassHash;
Expand Down
2 changes: 2 additions & 0 deletions crates/starknet_sequencer_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde_json.workspace = true
starknet_api.workspace = true
starknet_batcher.workspace = true
starknet_batcher_types.workspace = true
starknet_class_manager_types.workspace = true
starknet_consensus_manager.workspace = true
starknet_gateway.workspace = true
starknet_gateway_types.workspace = true
Expand All @@ -39,6 +40,7 @@ starknet_mempool_types.workspace = true
starknet_monitoring_endpoint.workspace = true
starknet_sequencer_infra.workspace = true
starknet_sierra_compile.workspace = true
starknet_sierra_compile_types.workspace = true
starknet_state_sync.workspace = true
starknet_state_sync_types.workspace = true
tokio.workspace = true
Expand Down
55 changes: 55 additions & 0 deletions crates/starknet_sequencer_node/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use starknet_batcher_types::communication::{
RemoteBatcherClient,
SharedBatcherClient,
};
use starknet_class_manager_types::{
ClassManagerRequest,
ClassManagerResponse,
LocalClassManagerClient,
RemoteClassManagerClient,
SharedClassManagerClient,
};
use starknet_gateway_types::communication::{
GatewayRequest,
GatewayResponse,
Expand All @@ -31,6 +38,13 @@ use starknet_mempool_types::communication::{
SharedMempoolClient,
};
use starknet_sequencer_infra::component_client::{Client, LocalComponentClient};
use starknet_sierra_compile_types::{
LocalSierraCompilerClient,
RemoteSierraCompilerClient,
SharedSierraCompilerClient,
SierraCompilerRequest,
SierraCompilerResponse,
};
use starknet_state_sync_types::communication::{
LocalStateSyncClient,
RemoteStateSyncClient,
Expand All @@ -45,10 +59,12 @@ use crate::config::node_config::SequencerNodeConfig;

pub struct SequencerNodeClients {
batcher_client: Client<BatcherRequest, BatcherResponse>,
class_manager_client: Client<ClassManagerRequest, ClassManagerResponse>,
mempool_client: Client<MempoolRequest, MempoolResponse>,
gateway_client: Client<GatewayRequest, GatewayResponse>,
mempool_p2p_propagator_client:
Client<MempoolP2pPropagatorRequest, MempoolP2pPropagatorResponse>,
sierra_compiler_client: Client<SierraCompilerRequest, SierraCompilerResponse>,
state_sync_client: Client<StateSyncRequest, StateSyncResponse>,
l1_provider_client: Client<L1ProviderRequest, L1ProviderResponse>,
}
Expand Down Expand Up @@ -106,6 +122,16 @@ impl SequencerNodeClients {
self.batcher_client.get_local_client()
}

pub fn get_class_manager_shared_client(&self) -> Option<SharedClassManagerClient> {
get_shared_client!(self, class_manager_client)
}

pub fn get_class_manager_local_client(
&self,
) -> Option<LocalComponentClient<ClassManagerRequest, ClassManagerResponse>> {
self.class_manager_client.get_local_client()
}

pub fn get_mempool_shared_client(&self) -> Option<SharedMempoolClient> {
get_shared_client!(self, mempool_client)
}
Expand Down Expand Up @@ -149,6 +175,16 @@ impl SequencerNodeClients {
self.mempool_p2p_propagator_client.get_local_client()
}

pub fn get_sierra_compiler_shared_client(&self) -> Option<SharedSierraCompilerClient> {
get_shared_client!(self, sierra_compiler_client)
}

pub fn get_sierra_compiler_local_client(
&self,
) -> Option<LocalComponentClient<SierraCompilerRequest, SierraCompilerResponse>> {
self.sierra_compiler_client.get_local_client()
}

pub fn get_state_sync_shared_client(&self) -> Option<SharedStateSyncClient> {
get_shared_client!(self, state_sync_client)
}
Expand Down Expand Up @@ -226,6 +262,14 @@ pub fn create_node_clients(
&config.components.batcher.remote_client_config,
config.components.batcher.socket
);
let class_manager_client = create_client!(
&config.components.class_manager.execution_mode,
LocalClassManagerClient,
RemoteClassManagerClient,
channels.take_class_manager_tx(),
&config.components.class_manager.remote_client_config,
config.components.class_manager.socket
);
let mempool_client = create_client!(
&config.components.mempool.execution_mode,
LocalMempoolClient,
Expand All @@ -252,6 +296,15 @@ pub fn create_node_clients(
config.components.mempool_p2p.socket
);

let sierra_compiler_client = create_client!(
&config.components.sierra_compiler.execution_mode,
LocalSierraCompilerClient,
RemoteSierraCompilerClient,
channels.take_sierra_compiler_tx(),
&config.components.sierra_compiler.remote_client_config,
config.components.sierra_compiler.socket
);

let state_sync_client = create_client!(
&config.components.state_sync.execution_mode,
LocalStateSyncClient,
Expand All @@ -272,9 +325,11 @@ pub fn create_node_clients(

SequencerNodeClients {
batcher_client,
class_manager_client,
mempool_client,
gateway_client,
mempool_p2p_propagator_client,
sierra_compiler_client,
state_sync_client,
l1_provider_client,
}
Expand Down
36 changes: 36 additions & 0 deletions crates/starknet_sequencer_node/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use starknet_batcher_types::communication::BatcherRequestAndResponseSender;
use starknet_class_manager_types::ClassManagerRequestAndResponseSender;
use starknet_gateway_types::communication::GatewayRequestAndResponseSender;
use starknet_l1_provider::communication::L1ProviderRequestAndResponseSender;
use starknet_mempool_p2p_types::communication::MempoolP2pPropagatorRequestAndResponseSender;
use starknet_mempool_types::communication::MempoolRequestAndResponseSender;
use starknet_sequencer_infra::component_definitions::ComponentCommunication;
use starknet_sierra_compile_types::SierraCompilerRequestAndResponseSender;
use starknet_state_sync_types::communication::StateSyncRequestAndResponseSender;
use tokio::sync::mpsc::{channel, Receiver, Sender};

pub struct SequencerNodeCommunication {
batcher_channel: ComponentCommunication<BatcherRequestAndResponseSender>,
class_manager_channel: ComponentCommunication<ClassManagerRequestAndResponseSender>,
gateway_channel: ComponentCommunication<GatewayRequestAndResponseSender>,
l1_provider_channel: ComponentCommunication<L1ProviderRequestAndResponseSender>,
mempool_channel: ComponentCommunication<MempoolRequestAndResponseSender>,
mempool_p2p_propagator_channel:
ComponentCommunication<MempoolP2pPropagatorRequestAndResponseSender>,
sierra_compiler_channel: ComponentCommunication<SierraCompilerRequestAndResponseSender>,
state_sync_channel: ComponentCommunication<StateSyncRequestAndResponseSender>,
}

Expand All @@ -26,6 +30,14 @@ impl SequencerNodeCommunication {
self.batcher_channel.take_rx()
}

pub fn take_class_manager_tx(&mut self) -> Sender<ClassManagerRequestAndResponseSender> {
self.class_manager_channel.take_tx()
}

pub fn take_class_manager_rx(&mut self) -> Receiver<ClassManagerRequestAndResponseSender> {
self.class_manager_channel.take_rx()
}

pub fn take_gateway_tx(&mut self) -> Sender<GatewayRequestAndResponseSender> {
self.gateway_channel.take_tx()
}
Expand Down Expand Up @@ -61,6 +73,16 @@ impl SequencerNodeCommunication {
self.mempool_channel.take_rx()
}

pub fn take_sierra_compiler_tx(
&mut self,
) -> Sender<SierraCompilerRequestAndResponseSender> {
self.sierra_compiler_channel.take_tx()
}

pub fn take_sierra_compiler_rx(&mut self) -> Receiver<SierraCompilerRequestAndResponseSender> {
self.sierra_compiler_channel.take_rx()
}

pub fn take_state_sync_tx(&mut self) -> Sender<StateSyncRequestAndResponseSender> {
self.state_sync_channel.take_tx()
}
Expand All @@ -75,6 +97,9 @@ pub fn create_node_channels() -> SequencerNodeCommunication {
let (tx_batcher, rx_batcher) =
channel::<BatcherRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

let (tx_class_manager, rx_class_manager) =
channel::<ClassManagerRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

let (tx_gateway, rx_gateway) =
channel::<GatewayRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

Expand All @@ -87,11 +112,18 @@ pub fn create_node_channels() -> SequencerNodeCommunication {
let (tx_mempool_p2p_propagator, rx_mempool_p2p_propagator) =
channel::<MempoolP2pPropagatorRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

let (tx_sierra_compiler, rx_sierra_compiler) =
channel::<SierraCompilerRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

let (tx_state_sync, rx_state_sync) =
channel::<StateSyncRequestAndResponseSender>(DEFAULT_INVOCATIONS_QUEUE_SIZE);

SequencerNodeCommunication {
batcher_channel: ComponentCommunication::new(Some(tx_batcher), Some(rx_batcher)),
class_manager_channel: ComponentCommunication::new(
Some(tx_class_manager),
Some(rx_class_manager),
),
gateway_channel: ComponentCommunication::new(Some(tx_gateway), Some(rx_gateway)),
l1_provider_channel: ComponentCommunication::new(
Some(tx_l1_provider),
Expand All @@ -102,6 +134,10 @@ pub fn create_node_channels() -> SequencerNodeCommunication {
Some(tx_mempool_p2p_propagator),
Some(rx_mempool_p2p_propagator),
),
sierra_compiler_channel: ComponentCommunication::new(
Some(tx_sierra_compiler),
Some(rx_sierra_compiler),
),
state_sync_channel: ComponentCommunication::new(Some(tx_state_sync), Some(rx_state_sync)),
}
}
8 changes: 8 additions & 0 deletions crates/starknet_sequencer_node/src/config/component_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ pub struct ComponentConfig {
#[validate]
pub batcher: ReactiveComponentExecutionConfig,
#[validate]
pub class_manager: ReactiveComponentExecutionConfig,
#[validate]
pub gateway: ReactiveComponentExecutionConfig,
#[validate]
pub mempool: ReactiveComponentExecutionConfig,
#[validate]
pub mempool_p2p: ReactiveComponentExecutionConfig,
#[validate]
pub sierra_compiler: ReactiveComponentExecutionConfig,
#[validate]
pub state_sync: ReactiveComponentExecutionConfig,
#[validate]
pub l1_provider: ReactiveComponentExecutionConfig,
Expand All @@ -42,6 +46,7 @@ impl SerializeConfig for ComponentConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let sub_configs = vec![
append_sub_config_name(self.batcher.dump(), "batcher"),
append_sub_config_name(self.class_manager.dump(), "class_manager"),
append_sub_config_name(self.consensus_manager.dump(), "consensus_manager"),
append_sub_config_name(self.gateway.dump(), "gateway"),
append_sub_config_name(self.http_server.dump(), "http_server"),
Expand All @@ -50,6 +55,7 @@ impl SerializeConfig for ComponentConfig {
append_sub_config_name(self.l1_scraper.dump(), "l1_scraper"),
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.sierra_compiler.dump(), "sierra_compiler"),
append_sub_config_name(self.state_sync.dump(), "state_sync"),
];

Expand All @@ -62,9 +68,11 @@ impl ComponentConfig {
pub fn disabled() -> ComponentConfig {
ComponentConfig {
batcher: ReactiveComponentExecutionConfig::disabled(),
class_manager: ReactiveComponentExecutionConfig::disabled(),
gateway: ReactiveComponentExecutionConfig::disabled(),
mempool: ReactiveComponentExecutionConfig::disabled(),
mempool_p2p: ReactiveComponentExecutionConfig::disabled(),
sierra_compiler: ReactiveComponentExecutionConfig::disabled(),
state_sync: ReactiveComponentExecutionConfig::disabled(),
l1_provider: ReactiveComponentExecutionConfig::disabled(),
l1_scraper: ActiveComponentExecutionConfig::disabled(),
Expand Down
Loading

0 comments on commit 8950f16

Please sign in to comment.