From 3c7593dc2275423fb050e409c24f5a1225e820c4 Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Tue, 30 Jul 2024 14:33:10 +0300 Subject: [PATCH] feat: add batcher and com prep commit-id:96eb0ab9 --- Cargo.lock | 6 ++++ crates/batcher/Cargo.toml | 7 +++- crates/batcher/src/batcher.rs | 2 ++ crates/batcher/src/communication.rs | 55 +++++++++++++++++++++++++++++ crates/batcher/src/lib.rs | 3 +- 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 crates/batcher/src/batcher.rs create mode 100644 crates/batcher/src/communication.rs diff --git a/Cargo.lock b/Cargo.lock index cffef09204..ef29a14511 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8913,6 +8913,12 @@ dependencies = [ [[package]] name = "starknet_batcher" version = "0.0.0" +dependencies = [ + "async-trait", + "starknet_batcher_types", + "starknet_mempool_infra", + "tokio", +] [[package]] name = "starknet_batcher_types" diff --git a/crates/batcher/Cargo.toml b/crates/batcher/Cargo.toml index ee14a33174..743c131069 100644 --- a/crates/batcher/Cargo.toml +++ b/crates/batcher/Cargo.toml @@ -5,7 +5,12 @@ edition.workspace = true license.workspace = true repository.workspace = true -[dependencies] [lints] workspace = true + +[dependencies] +async-trait.workspace = true +starknet_batcher_types = { path = "../batcher_types", version = "0.0" } +starknet_mempool_infra = { path = "../mempool_infra", version = "0.0" } +tokio.workspace = true diff --git a/crates/batcher/src/batcher.rs b/crates/batcher/src/batcher.rs new file mode 100644 index 0000000000..e7484e7c27 --- /dev/null +++ b/crates/batcher/src/batcher.rs @@ -0,0 +1,2 @@ +// TODO(Tsabary/Yael/Dafna): Replace with actual batcher code. +pub struct Batcher {} diff --git a/crates/batcher/src/communication.rs b/crates/batcher/src/communication.rs new file mode 100644 index 0000000000..3ca9623513 --- /dev/null +++ b/crates/batcher/src/communication.rs @@ -0,0 +1,55 @@ +use std::net::IpAddr; + +use async_trait::async_trait; +use starknet_batcher_types::communication::{ + BatcherRequest, + BatcherRequestAndResponseSender, + BatcherResponse, +}; +use starknet_mempool_infra::component_definitions::ComponentRequestHandler; +use starknet_mempool_infra::component_runner::ComponentStarter; +use starknet_mempool_infra::component_server::{LocalComponentServer, RemoteComponentServer}; +use tokio::sync::mpsc::Receiver; + +use crate::batcher::Batcher; + +pub type LocalBatcherServer = LocalComponentServer; +pub type RemoteBatcherServer = RemoteComponentServer; + +pub fn create_local_batcher_server( + batcher: Batcher, + rx_batcher: Receiver, +) -> LocalBatcherServer { + LocalComponentServer::new(batcher, rx_batcher) +} + +pub fn create_remote_batcher_server( + batcher: Batcher, + ip_address: IpAddr, + port: u16, +) -> RemoteBatcherServer { + RemoteComponentServer::new(batcher, ip_address, port) +} + +#[async_trait] +impl ComponentRequestHandler for Batcher { + async fn handle_request(&mut self, request: BatcherRequest) -> BatcherResponse { + match request { + BatcherRequest::BatcherFnOne(_batcher_input) => { + // TODO(Tsabary/Yael/Dafna): Invoke a function that returns a + // BatcherResult, and return + // the BatcherResponse::BatcherFnOneInput accordingly. + unimplemented!() + } + BatcherRequest::BatcherFnTwo(_batcher_input) => { + // TODO(Tsabary/Yael/Dafna): Invoke a function that returns a + // BatcherResult, and return + // the BatcherResponse::BatcherFnTwoInput accordingly. + unimplemented!() + } + } + } +} + +#[async_trait] +impl ComponentStarter for Batcher {} diff --git a/crates/batcher/src/lib.rs b/crates/batcher/src/lib.rs index 8b13789179..4af5e63cd8 100644 --- a/crates/batcher/src/lib.rs +++ b/crates/batcher/src/lib.rs @@ -1 +1,2 @@ - +pub mod batcher; +pub mod communication;