From 354900e98734c92b969a4d5f6bc430ce1ab13244 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 94db88b7d..335b66e00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5327,6 +5327,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..895b403c9 --- /dev/null +++ b/crates/mempool_node/src/servers.rs @@ -0,0 +1,41 @@ +use starknet_gateway::communication::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 communication: MempoolNodeCommunication, + components: Components, +) -> Servers { + let gateway_server: Option> = + if config.components.gateway_component.execute { + Some(Box::new(create_gateway_server( + components.gateway.expect("Gateway is not initialized."), + ))) + } else { + None + }; + + let mempool_server: Option> = + if config.components.mempool_component.execute { + Some(Box::new(create_mempool_server( + components.mempool.expect("Mempool is not initialized."), + communication.take_mempool_rx(), + ))) + } else { + None + }; + + Servers { gateway: gateway_server, mempool: mempool_server } +} + +// TODO (Lev): Implement the run server components function.