From 83a63c6e1b8171cb0eee4b42ee5fe3f87cf39532 Mon Sep 17 00:00:00 2001 From: nadin-Starkware Date: Wed, 13 Nov 2024 18:19:49 +0200 Subject: [PATCH] chore: add create_remote_server macro commit-id:6442e09a --- crates/starknet_sequencer_node/src/servers.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/starknet_sequencer_node/src/servers.rs b/crates/starknet_sequencer_node/src/servers.rs index 2e98acd0b44..ad91144866b 100644 --- a/crates/starknet_sequencer_node/src/servers.rs +++ b/crates/starknet_sequencer_node/src/servers.rs @@ -44,6 +44,62 @@ pub struct SequencerNodeServers { wrapper_servers: WrapperServers, } +/// A macro for creating a remote component server based on the component's execution mode. +/// Returns a remote server if the component is configured with Remote execution mode; otherwise, +/// returns None. +/// +/// # Arguments +/// +/// * `$execution_mode` - A reference to the component's execution mode, of type +/// `&ComponentExecutionMode`. +/// * `$client` - The client to be used for the remote server initialization if the execution mode +/// is `Remote`. +/// * `$config` - The configuration for the remote server. +/// +/// # Returns +/// +/// An `Option>>` containing +/// the server if the execution mode is `Remote`, or `None` if the execution mode is `Disabled` or +/// `LocalExecution`. +/// +/// # Example +/// +/// ```rust,ignore +/// let batcher_remote_server = create_remote_server!( +/// &config.components.batcher.execution_mode, +/// client, +/// config.remote_server_config +/// ); +/// match batcher_remote_server { +/// Some(server) => println!("Remote server created: {:?}", server), +/// None => println!("Remote server not created because the execution mode is not remote."), +/// } +/// ``` +#[macro_export] +macro_rules! create_remote_server { + ($execution_mode:expr, $client:expr, $config:expr) => { + match *$execution_mode { + ComponentExecutionMode::Remote => { + let client = $client + .as_ref() + .expect("Error: client must be initialized in Remote execution mode."); + let config = $config + .as_ref() + .expect("Error: config must be initialized in Remote execution mode."); + + if let Some(local_client) = client.get_local_client() { + Some(Box::new(RemoteComponentServer::new(local_client, config.clone()))) + } else { + None + } + } + ComponentExecutionMode::LocalExecutionWithRemoteDisabled + | ComponentExecutionMode::LocalExecutionWithRemoteEnabled + | ComponentExecutionMode::Disabled => None, + } + }; +} + /// A macro for creating a component server, determined by the component's execution mode. Returns a /// local server if the component is run locally, otherwise None. ///