Skip to content

Commit

Permalink
chore: separate component definitions from component server
Browse files Browse the repository at this point in the history
commit-id:56f63265
  • Loading branch information
Itay-Tsabary-Starkware committed Jun 6, 2024
1 parent 2e2c58d commit fc51e8c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/mempool_infra/src/component_client.rs
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
16 changes: 16 additions & 0 deletions crates/mempool_infra/src/component_definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use async_trait::async_trait;
use tokio::sync::mpsc::Sender;

#[async_trait]
pub trait ComponentRequestHandler<Request, Response> {
async fn handle_request(&mut self, request: Request) -> Response;
}

pub struct ComponentRequestAndResponseSender<Request, Response>
where
Request: Send + Sync,
Response: Send + Sync,
{
pub request: Request,
pub tx: Sender<Response>,
}
17 changes: 2 additions & 15 deletions crates/mempool_infra/src/component_server.rs
Original file line number Diff line number Diff line change
@@ -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<Request, Response> {
async fn handle_request(&mut self, request: Request) -> Response;
}

pub struct ComponentRequestAndResponseSender<Request, Response>
where
Request: Send + Sync,
Response: Send + Sync,
{
pub request: Request,
pub tx: Sender<Response>,
}
use crate::component_definitions::{ComponentRequestAndResponseSender, ComponentRequestHandler};

pub struct ComponentServer<Component, Request, Response>
where
Expand Down
5 changes: 2 additions & 3 deletions crates/mempool_infra/src/component_server_client_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions crates/mempool_infra/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod component_client;
pub mod component_client_rpc;
pub mod component_definitions;
pub mod component_runner;
pub mod component_server;
2 changes: 1 addition & 1 deletion crates/mempool_types/src/mempool_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc51e8c

Please sign in to comment.