-
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
770e2ed
commit 0674c70
Showing
6 changed files
with
157 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,21 @@ | ||
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 BatcherFnOneInput {} | ||
|
||
// TODO(Tsabary/Yael/Dafna): Populate the data structure used to invoke the batcher. | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct BatcherFnTwoInput {} | ||
|
||
// TODO(Tsabary/Yael/Dafna): Replace with the actual return type of the batcher function. | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct BatcherFnOneReturnValue {} | ||
|
||
// TODO(Tsabary/Yael/Dafna): Replace with the actual return type of the batcher function. | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct BatcherFnTwoReturnValue {} | ||
|
||
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,108 @@ | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use mockall::predicate::*; | ||
use mockall::*; | ||
use papyrus_proc_macros::handle_response_variants; | ||
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::{ | ||
BatcherFnOneInput, | ||
BatcherFnOneReturnValue, | ||
BatcherFnTwoInput, | ||
BatcherFnTwoReturnValue, | ||
BatcherResult, | ||
}; | ||
use crate::errors::BatcherError; | ||
|
||
pub type LocalBatcherClientImpl = 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>; | ||
|
||
/// 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_fn_one( | ||
&self, | ||
batcher_fn_one_input: BatcherFnOneInput, | ||
) -> BatcherClientResult<BatcherFnOneReturnValue>; | ||
|
||
async fn batcher_fn_two( | ||
&self, | ||
batcher_fn_two_input: BatcherFnTwoInput, | ||
) -> BatcherClientResult<BatcherFnTwoReturnValue>; | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum BatcherRequest { | ||
BatcherFnOne(BatcherFnOneInput), | ||
BatcherFnTwo(BatcherFnTwoInput), | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum BatcherResponse { | ||
BatcherFnOne(BatcherResult<BatcherFnOneReturnValue>), | ||
BatcherFnTwo(BatcherResult<BatcherFnTwoReturnValue>), | ||
} | ||
|
||
#[derive(Clone, Debug, Error)] | ||
pub enum BatcherClientError { | ||
#[error(transparent)] | ||
ClientError(#[from] ClientError), | ||
#[error(transparent)] | ||
BatcherError(#[from] BatcherError), | ||
} | ||
|
||
#[async_trait] | ||
impl BatcherClient for LocalBatcherClientImpl { | ||
async fn batcher_fn_one( | ||
&self, | ||
batcher_fn_one_input: BatcherFnOneInput, | ||
) -> BatcherClientResult<BatcherFnOneReturnValue> { | ||
let request = BatcherRequest::BatcherFnOne(batcher_fn_one_input); | ||
let response = self.send(request).await; | ||
handle_response_variants!(BatcherResponse, BatcherFnOne, BatcherClientError, BatcherError) | ||
} | ||
|
||
async fn batcher_fn_two( | ||
&self, | ||
batcher_fn_two_input: BatcherFnTwoInput, | ||
) -> BatcherClientResult<BatcherFnTwoReturnValue> { | ||
let request = BatcherRequest::BatcherFnTwo(batcher_fn_two_input); | ||
let response = self.send(request).await; | ||
handle_response_variants!(BatcherResponse, BatcherFnTwo, BatcherClientError, BatcherError) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl BatcherClient for RemoteBatcherClientImpl { | ||
async fn batcher_fn_one( | ||
&self, | ||
batcher_fn_one_input: BatcherFnOneInput, | ||
) -> BatcherClientResult<BatcherFnOneReturnValue> { | ||
let request = BatcherRequest::BatcherFnOne(batcher_fn_one_input); | ||
let response = self.send(request).await?; | ||
handle_response_variants!(BatcherResponse, BatcherFnOne, BatcherClientError, BatcherError) | ||
} | ||
|
||
async fn batcher_fn_two( | ||
&self, | ||
batcher_fn_two_input: BatcherFnTwoInput, | ||
) -> BatcherClientResult<BatcherFnTwoReturnValue> { | ||
let request = BatcherRequest::BatcherFnTwo(batcher_fn_two_input); | ||
let response = self.send(request).await?; | ||
handle_response_variants!(BatcherResponse, BatcherFnTwo, BatcherClientError, 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,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; |