-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add batcher_types communication
commit-id:aa33dbd8
- Loading branch information
1 parent
84bf732
commit ad45c95
Showing
6 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::errors::BatcherError; | ||
|
||
// TODO(Tsabary/Yael/Dafna): Populate the data structure used to invoke the batcher. | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct BatcherInput {} | ||
|
||
pub type BatcherResult<T> = Result<T, BatcherError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use mockall::predicate::*; | ||
use mockall::*; | ||
use serde::{Deserialize, Serialize}; | ||
use starknet_mempool_infra::component_client::{ | ||
ClientError, | ||
LocalComponentClient, | ||
RemoteComponentClient, | ||
}; | ||
use starknet_mempool_infra::component_definitions::ComponentRequestAndResponseSender; | ||
use thiserror::Error; | ||
|
||
use crate::batcher_types::{BatcherInput, BatcherResult}; | ||
use crate::errors::BatcherError; | ||
pub type BatcherClientImpl = LocalComponentClient<BatcherRequest, BatcherResponse>; | ||
pub type RemoteBatcherClientImpl = RemoteComponentClient<BatcherRequest, BatcherResponse>; | ||
pub type BatcherClientResult<T> = Result<T, BatcherClientError>; | ||
pub type BatcherRequestAndResponseSender = | ||
ComponentRequestAndResponseSender<BatcherRequest, BatcherResponse>; | ||
pub type SharedBatcherClient = Arc<dyn BatcherClient>; | ||
|
||
// TODO(Tsabary/Yael/Dafna): Replace with the actual return type of the batcher function. | ||
pub type PlaceholderReturnType = (); | ||
|
||
/// Serves as the batcher's shared interface. Requires `Send + Sync` to allow transferring and | ||
/// sharing resources (inputs, futures) across threads. | ||
#[automock] | ||
#[async_trait] | ||
pub trait BatcherClient: Send + Sync { | ||
async fn batcher_placeholder_fn_name( | ||
&self, | ||
batcher_input: BatcherInput, | ||
) -> BatcherClientResult<PlaceholderReturnType>; | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum BatcherRequest { | ||
PlaceholderBatcherRequest(BatcherInput), | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum BatcherResponse { | ||
PlaceholderBatcherResponse(BatcherResult<PlaceholderReturnType>), | ||
} | ||
|
||
#[derive(Clone, Debug, Error)] | ||
pub enum BatcherClientError { | ||
#[error(transparent)] | ||
ClientError(#[from] ClientError), | ||
#[error(transparent)] | ||
BatcherError(#[from] BatcherError), | ||
} | ||
|
||
#[async_trait] | ||
impl BatcherClient for BatcherClientImpl { | ||
async fn batcher_placeholder_fn_name( | ||
&self, | ||
batcher_input: BatcherInput, | ||
) -> BatcherClientResult<PlaceholderReturnType> { | ||
let request = BatcherRequest::PlaceholderBatcherRequest(batcher_input); | ||
let response = self.send(request).await; | ||
match response { | ||
BatcherResponse::PlaceholderBatcherResponse(Ok(response)) => Ok(response), | ||
BatcherResponse::PlaceholderBatcherResponse(Err(response)) => { | ||
Err(BatcherClientError::BatcherError(response)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl BatcherClient for RemoteBatcherClientImpl { | ||
async fn batcher_placeholder_fn_name( | ||
&self, | ||
batcher_input: BatcherInput, | ||
) -> BatcherClientResult<PlaceholderReturnType> { | ||
let request = BatcherRequest::PlaceholderBatcherRequest(batcher_input); | ||
let response = self.send(request).await?; | ||
match response { | ||
BatcherResponse::PlaceholderBatcherResponse(Ok(response)) => Ok(response), | ||
BatcherResponse::PlaceholderBatcherResponse(Err(response)) => { | ||
Err(BatcherClientError::BatcherError(response)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
// TODO(Tsabary/Yael/Dafna): Populate with actual errors. | ||
#[derive(Clone, Debug, Error, PartialEq, Eq, Serialize, Deserialize)] | ||
pub enum BatcherError { | ||
#[error("Placeholder error message")] | ||
Placeholder, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
|
||
pub mod batcher_types; | ||
pub mod communication; | ||
pub mod errors; |