From eaac21e17d888a0c927bbf51f85d81c9c8992cea 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 | 2 ++ crates/gateway/src/gateway.rs | 12 ++++++++++- crates/mempool_node/Cargo.toml | 2 ++ crates/mempool_node/src/components.rs | 30 +++++++++++++++++++++++++++ crates/mempool_node/src/lib.rs | 2 ++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 crates/mempool_node/src/components.rs diff --git a/Cargo.lock b/Cargo.lock index 5dfe409f4..710ccebac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5585,6 +5585,8 @@ dependencies = [ "serde", "serde_json", "starknet_gateway", + "starknet_mempool", + "starknet_mempool_types", "test_utils", "tokio", "validator", diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index fcf7c0a13..6efc97ba2 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -14,8 +14,9 @@ use starknet_mempool_types::mempool_types::{Account, MempoolInput}; use starknet_sierra_compile::compile::{compile_sierra_to_casm, CompilationUtilError}; use starknet_sierra_compile::utils::into_contract_class_for_compilation; -use crate::config::{GatewayConfig, GatewayNetworkConfig}; +use crate::config::{GatewayConfig, GatewayNetworkConfig, RpcStateReaderConfig}; use crate::errors::{GatewayError, GatewayRunError}; +use crate::rpc_state_reader::RpcStateReaderFactory; use crate::starknet_api_test_utils::get_sender_address; use crate::state_reader::StateReaderFactory; use crate::stateful_transaction_validator::StatefulTransactionValidator; @@ -167,3 +168,12 @@ fn compile_contract_class(declare_tx: &RPCDeclareTransaction) -> GatewayResult Gateway { + let state_reader_factory = Arc::new(RpcStateReaderFactory { config: rpc_state_reader_config }); + Gateway::new(config, state_reader_factory, client) +} diff --git a/crates/mempool_node/Cargo.toml b/crates/mempool_node/Cargo.toml index b7980589b..72b6f96aa 100644 --- a/crates/mempool_node/Cargo.toml +++ b/crates/mempool_node/Cargo.toml @@ -12,6 +12,8 @@ workspace = true clap.workspace = true const_format.workspace = true starknet_gateway = { path = "../gateway", 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 000000000..c2f3ac6db --- /dev/null +++ b/crates/mempool_node/src/components.rs @@ -0,0 +1,30 @@ +use starknet_gateway::gateway::{create_gateway, Gateway}; +use starknet_mempool::mempool::Mempool; + +use crate::communication::MempoolNodeClients; +use crate::config::MempoolNodeConfig; + +pub struct Components { + pub gateway: Option, + pub mempool: Option, +} + +pub fn create_components(config: &MempoolNodeConfig, clients: &MempoolNodeClients) -> Components { + let gateway_component = if config.components.gateway_component.execute { + let mempool_clent = + clients.get_mempool_client().expect("Mempool Client should be available"); + + Some(create_gateway( + config.gateway_config.clone(), + config.rpc_state_reader_config.clone(), + mempool_clent, + )) + } else { + None + }; + + let mempool_component = + if config.components.mempool_component.execute { Some(Mempool::empty()) } else { None }; + + Components { gateway: gateway_component, mempool: mempool_component } +} diff --git a/crates/mempool_node/src/lib.rs b/crates/mempool_node/src/lib.rs index ee6576882..c06908821 100644 --- a/crates/mempool_node/src/lib.rs +++ b/crates/mempool_node/src/lib.rs @@ -1,2 +1,4 @@ +pub mod communication; +pub mod components; pub mod config; pub mod version;