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

feat: add batcher and com prep #204

Merged
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
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 {}
55 changes: 55 additions & 0 deletions crates/batcher/src/communication.rs
Original file line number Diff line number Diff line change
@@ -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<Batcher, BatcherRequest, BatcherResponse>;
pub type RemoteBatcherServer = RemoteComponentServer<Batcher, BatcherRequest, BatcherResponse>;

pub fn create_local_batcher_server(
batcher: Batcher,
rx_batcher: Receiver<BatcherRequestAndResponseSender>,
) -> 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<BatcherRequest, BatcherResponse> 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<BatcherFnOneReturnValue>, and return
// the BatcherResponse::BatcherFnOneInput accordingly.
unimplemented!()
}
BatcherRequest::BatcherFnTwo(_batcher_input) => {
// TODO(Tsabary/Yael/Dafna): Invoke a function that returns a
// BatcherResult<BatcherFnTwoReturnValue>, and return
// the BatcherResponse::BatcherFnTwoInput 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;
Loading