From 07653cc842bb8b68a2117b763f7da65fe6fb7ff6 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 4 Jun 2024 17:46:55 +0300 Subject: [PATCH] chore: separate component definitions from component server commit-id:56f63265 --- crates/mempool/src/mempool.rs | 3 ++- crates/mempool_infra/src/component_client.rs | 2 +- .../mempool_infra/src/component_definitions.rs | 16 ++++++++++++++++ crates/mempool_infra/src/component_server.rs | 17 ++--------------- .../src/component_server_client_test.rs | 5 ++--- crates/mempool_infra/src/lib.rs | 1 + crates/mempool_types/src/mempool_types.rs | 2 +- 7 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 crates/mempool_infra/src/component_definitions.rs diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index 4df3af430..0bf912bea 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -4,7 +4,8 @@ use std::collections::HashMap; use async_trait::async_trait; use starknet_api::core::ContractAddress; use starknet_api::transaction::TransactionHash; -use starknet_mempool_infra::component_server::{ComponentRequestHandler, ComponentServer}; +use starknet_mempool_infra::component_definitions::ComponentRequestHandler; +use starknet_mempool_infra::component_server::ComponentServer; use starknet_mempool_types::errors::MempoolError; use starknet_mempool_types::mempool_types::{ Account, AccountState, MempoolInput, MempoolRequest, MempoolRequestAndResponseSender, diff --git a/crates/mempool_infra/src/component_client.rs b/crates/mempool_infra/src/component_client.rs index b348e0872..0c97ba02b 100644 --- a/crates/mempool_infra/src/component_client.rs +++ b/crates/mempool_infra/src/component_client.rs @@ -1,6 +1,6 @@ use tokio::sync::mpsc::{channel, Sender}; -use crate::component_server::ComponentRequestAndResponseSender; +use crate::component_definitions::ComponentRequestAndResponseSender; #[cfg(test)] #[path = "component_server_client_test.rs"] diff --git a/crates/mempool_infra/src/component_definitions.rs b/crates/mempool_infra/src/component_definitions.rs new file mode 100644 index 000000000..dd12d59ff --- /dev/null +++ b/crates/mempool_infra/src/component_definitions.rs @@ -0,0 +1,16 @@ +use async_trait::async_trait; +use tokio::sync::mpsc::Sender; + +#[async_trait] +pub trait ComponentRequestHandler { + async fn handle_request(&mut self, request: Request) -> Response; +} + +pub struct ComponentRequestAndResponseSender +where + Request: Send + Sync, + Response: Send + Sync, +{ + pub request: Request, + pub tx: Sender, +} diff --git a/crates/mempool_infra/src/component_server.rs b/crates/mempool_infra/src/component_server.rs index fa7bc795f..0a726100e 100644 --- a/crates/mempool_infra/src/component_server.rs +++ b/crates/mempool_infra/src/component_server.rs @@ -1,19 +1,6 @@ -use async_trait::async_trait; -use tokio::sync::mpsc::{Receiver, Sender}; +use tokio::sync::mpsc::Receiver; -#[async_trait] -pub trait ComponentRequestHandler { - async fn handle_request(&mut self, request: Request) -> Response; -} - -pub struct ComponentRequestAndResponseSender -where - Request: Send + Sync, - Response: Send + Sync, -{ - pub request: Request, - pub tx: Sender, -} +use crate::component_definitions::{ComponentRequestAndResponseSender, ComponentRequestHandler}; pub struct ComponentServer where diff --git a/crates/mempool_infra/src/component_server_client_test.rs b/crates/mempool_infra/src/component_server_client_test.rs index c86978c05..85216c204 100644 --- a/crates/mempool_infra/src/component_server_client_test.rs +++ b/crates/mempool_infra/src/component_server_client_test.rs @@ -7,9 +7,8 @@ use crate::component_client::ComponentClient; type ValueA = u32; type ValueB = u8; -use crate::component_server::{ - ComponentRequestAndResponseSender, ComponentRequestHandler, ComponentServer, -}; +use crate::component_definitions::{ComponentRequestAndResponseSender, ComponentRequestHandler}; +use crate::component_server::ComponentServer; #[async_trait] trait ComponentATrait: Send + Sync { diff --git a/crates/mempool_infra/src/lib.rs b/crates/mempool_infra/src/lib.rs index 7beabba75..623526a1d 100644 --- a/crates/mempool_infra/src/lib.rs +++ b/crates/mempool_infra/src/lib.rs @@ -1,5 +1,6 @@ pub mod component_client; pub mod component_client_rpc; +pub mod component_definitions; pub mod component_runner; pub mod component_server; pub mod network_component; diff --git a/crates/mempool_types/src/mempool_types.rs b/crates/mempool_types/src/mempool_types.rs index 965bb78bc..dca78d31d 100644 --- a/crates/mempool_types/src/mempool_types.rs +++ b/crates/mempool_types/src/mempool_types.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use starknet_api::core::{ContractAddress, Nonce}; use starknet_api::transaction::{Tip, TransactionHash}; use starknet_mempool_infra::component_client::ComponentClient; -use starknet_mempool_infra::component_server::ComponentRequestAndResponseSender; +use starknet_mempool_infra::component_definitions::ComponentRequestAndResponseSender; use thiserror::Error; use crate::errors::MempoolError;