From 4bd2b8031795b2bd56367a6a9c37c7985504db4e Mon Sep 17 00:00:00 2001 From: Lev Roitman Date: Wed, 26 Jun 2024 18:59:35 +0300 Subject: [PATCH] feat: add functionality to create all servers commit-id:0f64f96b --- Cargo.lock | 1 + crates/mempool_node/Cargo.toml | 1 + crates/mempool_node/src/lib.rs | 1 + crates/mempool_node/src/servers.rs | 41 ++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 crates/mempool_node/src/servers.rs diff --git a/Cargo.lock b/Cargo.lock index 61c0f2b15..caccd5567 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5589,6 +5589,7 @@ dependencies = [ "serde_json", "starknet_gateway", "starknet_mempool", + "starknet_mempool_infra", "starknet_mempool_types", "test_utils", "tokio", diff --git a/crates/mempool_node/Cargo.toml b/crates/mempool_node/Cargo.toml index 72b6f96aa..67ba89e46 100644 --- a/crates/mempool_node/Cargo.toml +++ b/crates/mempool_node/Cargo.toml @@ -12,6 +12,7 @@ workspace = true clap.workspace = true const_format.workspace = true starknet_gateway = { path = "../gateway", version = "0.0" } +starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" } starknet_mempool = { path = "../mempool", version = "0.0" } starknet_mempool_types = { path = "../mempool_types", version = "0.0" } serde.workspace = true diff --git a/crates/mempool_node/src/lib.rs b/crates/mempool_node/src/lib.rs index c06908821..1a31b0bf5 100644 --- a/crates/mempool_node/src/lib.rs +++ b/crates/mempool_node/src/lib.rs @@ -1,4 +1,5 @@ pub mod communication; pub mod components; pub mod config; +pub mod servers; pub mod version; diff --git a/crates/mempool_node/src/servers.rs b/crates/mempool_node/src/servers.rs new file mode 100644 index 000000000..59addebdf --- /dev/null +++ b/crates/mempool_node/src/servers.rs @@ -0,0 +1,41 @@ +// use std::future::pending; +// use std::pin::Pin; + +// use futures::{Future, FutureExt}; +use starknet_gateway::gateway::create_gateway_server; +use starknet_mempool::communication::create_mempool_server; +use starknet_mempool_infra::component_server::ComponentServerStarter; + +use crate::communication::MempoolNodeCommunication; +use crate::components::Components; +use crate::config::MempoolNodeConfig; + +pub struct Servers { + pub gateway: Option>, + pub mempool: Option>, +} + +pub fn create_servers( + config: &MempoolNodeConfig, + mut channels: MempoolNodeCommunication, + components: Components, +) -> Servers { + let mut servers = Servers { gateway: None, mempool: None }; + + if config.components.gateway_component.execute { + servers.gateway = Some(Box::new(create_gateway_server( + components.gateway.expect("Gateway component is not initialized."), + ))); + } + + if config.components.mempool_component.execute { + servers.mempool = Some(Box::new(create_mempool_server( + components.mempool.expect("Mempool component is not initialized."), + channels.take_mempool_rx(), + ))); + } + + servers +} + +// TODO (Lev): Implement the run server components function.