From 7f40a0313f9c0591b4f9b02874ef953b14185cf9 Mon Sep 17 00:00:00 2001 From: Lev Roitman Date: Thu, 20 Jun 2024 19:10:46 +0300 Subject: [PATCH] feat: add functionality to create all components commit-id:bb128e01 --- Cargo.lock | 3 +++ crates/gateway/src/gateway.rs | 10 ++++++++++ crates/mempool_node/Cargo.toml | 3 +++ crates/mempool_node/src/components.rs | 22 ++++++++++++++++++++++ crates/mempool_node/src/lib.rs | 3 +++ 5 files changed, 41 insertions(+) create mode 100644 crates/mempool_node/src/components.rs diff --git a/Cargo.lock b/Cargo.lock index 760fa984..2e88cee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5583,6 +5583,9 @@ dependencies = [ "serde", "serde_json", "starknet_gateway", + "starknet_mempool", + "starknet_mempool_infra", + "starknet_mempool_types", "test_utils", "tokio", "validator", diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index b95f5396..f931724f 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -124,3 +124,13 @@ fn process_tx( account: Account { sender_address: get_sender_address(&tx), ..Default::default() }, }) } + +pub fn create_gateway(config: GatewayConfig, client: Option) -> Gateway { + if client.is_none() { + panic!("SharedMempoolClient is required to create Gateway."); + } + + let state_reader_factory: Arc = + Arc::new(crate::state_reader_test_utils::local_test_state_reader_factory()); + Gateway::new(config, state_reader_factory, client.unwrap()) +} diff --git a/crates/mempool_node/Cargo.toml b/crates/mempool_node/Cargo.toml index b7980589..67ba89e4 100644 --- a/crates/mempool_node/Cargo.toml +++ b/crates/mempool_node/Cargo.toml @@ -12,6 +12,9 @@ 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 papyrus_config.workspace = true tokio.workspace = true diff --git a/crates/mempool_node/src/components.rs b/crates/mempool_node/src/components.rs new file mode 100644 index 00000000..91ca426a --- /dev/null +++ b/crates/mempool_node/src/components.rs @@ -0,0 +1,22 @@ +use starknet_gateway::gateway::{create_gateway, Gateway}; +use starknet_mempool::mempool::Mempool; + +use crate::com_clients::CommClients; +use crate::config::MempoolNodeConfig; + +pub struct Components { + pub gateway: Option, + pub mempool: Option, +} + +pub fn create_components(config: &MempoolNodeConfig, clients: &CommClients) -> Components { + let mut components = Components { gateway: None, mempool: None }; + if config.components.gateway_component.execute { + components.gateway = + Some(create_gateway(config.gateway_config.clone(), clients.mempool_client.clone())); + } + if config.components.mempool_component.execute { + components.mempool = Some(Mempool::empty()); + } + components +} diff --git a/crates/mempool_node/src/lib.rs b/crates/mempool_node/src/lib.rs index ee657688..62e189eb 100644 --- a/crates/mempool_node/src/lib.rs +++ b/crates/mempool_node/src/lib.rs @@ -1,2 +1,5 @@ +pub mod com_clients; +pub mod communication; +pub mod components; pub mod config; pub mod version;