Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: separate component definitions from component server #213

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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;
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
Loading