From 2473411a94c8b15d746938d9e139aa2c8ca457a7 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 | 50 +++++++++++++++++++++++++++++ crates/batcher/src/lib.rs | 3 +- 5 files changed, 66 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 dd96f0a8d8..74ce052f4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8912,6 +8912,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..11f109bee1 --- /dev/null +++ b/crates/batcher/src/communication.rs @@ -0,0 +1,50 @@ +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 BatcherServer = LocalComponentServer; + +pub type RemoteBatcherServer = RemoteComponentServer; + +pub fn create_batcher_server( + batcher: Batcher, + rx_batcher: Receiver, +) -> BatcherServer { + 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::PlaceholderBatcherRequest(_batcher_input) => { + // TODO(Tsabary/Yael/Dafna): Invoke a function that returns + // BatcherResult, and return + // the BatcherResponse::PlaceholderBatcherResponse 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;