Skip to content

Commit

Permalink
feat: add batcher and com prep
Browse files Browse the repository at this point in the history
commit-id:96eb0ab9
  • Loading branch information
Itay-Tsabary-Starkware committed Aug 4, 2024
1 parent 0674c70 commit 9105827
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion crates/batcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions crates/batcher/src/batcher.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO(Tsabary/Yael/Dafna): Replace with actual batcher code.
pub struct Batcher {}
50 changes: 50 additions & 0 deletions crates/batcher/src/communication.rs
Original file line number Diff line number Diff line change
@@ -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<Batcher, BatcherRequest, BatcherResponse>;

pub type RemoteBatcherServer = RemoteComponentServer<Batcher, BatcherRequest, BatcherResponse>;

pub fn create_batcher_server(
batcher: Batcher,
rx_batcher: Receiver<BatcherRequestAndResponseSender>,
) -> 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<BatcherRequest, BatcherResponse> 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<PlaceholderReturnType>, and return
// the BatcherResponse::PlaceholderBatcherResponse accordingly.
unimplemented!()
}
}
}
}

#[async_trait]
impl ComponentStarter for Batcher {}
3 changes: 2 additions & 1 deletion crates/batcher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

pub mod batcher;
pub mod communication;

0 comments on commit 9105827

Please sign in to comment.