diff --git a/Cargo.lock b/Cargo.lock index b06cbc9dc4f..58c24c74fe0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8910,6 +8910,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 ee14a331749..743c1310690 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 00000000000..e7484e7c27a --- /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 00000000000..11f109bee10 --- /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 8b137891791..4af5e63cd8b 100644 --- a/crates/batcher/src/lib.rs +++ b/crates/batcher/src/lib.rs @@ -1 +1,2 @@ - +pub mod batcher; +pub mod communication;