-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(starknet_l1_provider): Getting things ready for the client
Adding provider-side boilerplate for provider-batcher communication
- Loading branch information
Gilad Chase
committed
Dec 12, 2024
1 parent
203fb99
commit 235c792
Showing
7 changed files
with
150 additions
and
12 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,31 @@ | ||
use async_trait::async_trait; | ||
use starknet_l1_provider_types::{L1ProviderRequest, L1ProviderResponse}; | ||
use starknet_sequencer_infra::component_client::{LocalComponentClient, RemoteComponentClient}; | ||
use starknet_sequencer_infra::component_definitions::{ | ||
ComponentRequestAndResponseSender, | ||
ComponentRequestHandler, | ||
}; | ||
use starknet_sequencer_infra::component_server::{LocalComponentServer, RemoteComponentServer}; | ||
use tracing::instrument; | ||
|
||
use crate::L1Provider; | ||
|
||
pub type LocalL1ProviderServer = | ||
LocalComponentServer<L1Provider, L1ProviderRequest, L1ProviderResponse>; | ||
pub type RemoteL1ProviderServer = RemoteComponentServer<L1ProviderRequest, L1ProviderResponse>; | ||
pub type L1ProviderRequestAndResponseSender = | ||
ComponentRequestAndResponseSender<L1ProviderRequest, L1ProviderResponse>; | ||
pub type LocalL1ProviderClient = LocalComponentClient<L1ProviderRequest, L1ProviderResponse>; | ||
pub type RemoteL1ProviderClient = RemoteComponentClient<L1ProviderRequest, L1ProviderResponse>; | ||
|
||
#[async_trait] | ||
impl ComponentRequestHandler<L1ProviderRequest, L1ProviderResponse> for L1Provider { | ||
#[instrument(skip(self))] | ||
async fn handle_request(&mut self, request: L1ProviderRequest) -> L1ProviderResponse { | ||
match request { | ||
L1ProviderRequest::GetTransactions(n_txs) => { | ||
L1ProviderResponse::GetTransactions(self.get_txs(n_txs)) | ||
} | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,71 @@ | ||
pub mod errors; | ||
|
||
use crate::errors::L1ProviderError; | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
#[cfg(any(feature = "testing", test))] | ||
use mockall::automock; | ||
use papyrus_proc_macros::handle_response_variants; | ||
use serde::{Deserialize, Serialize}; | ||
use starknet_api::executable_transaction::L1HandlerTransaction; | ||
use starknet_api::transaction::TransactionHash; | ||
use starknet_sequencer_infra::component_client::ClientError; | ||
use starknet_sequencer_infra::component_definitions::ComponentClient; | ||
use tracing::instrument; | ||
|
||
use crate::errors::{L1ProviderClientError, L1ProviderError}; | ||
|
||
pub type L1ProviderResult<T> = Result<T, L1ProviderError>; | ||
pub type L1ProviderClientResult<T> = Result<T, L1ProviderClientError>; | ||
pub type SharedL1ProviderClient = Arc<dyn L1ProviderClient>; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub enum ValidationStatus { | ||
Validated, | ||
AlreadyIncludedOnL2, | ||
ConsumedOnL1OrUnknown, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub enum L1ProviderRequest { | ||
GetTransactions(usize), | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub enum L1ProviderResponse { | ||
GetTransactions(L1ProviderResult<Vec<L1HandlerTransaction>>), | ||
} | ||
|
||
/// Serves as the mempool's shared interface. Requires `Send + Sync` to allow transferring and | ||
/// sharing resources (inputs, futures) across threads. | ||
#[cfg_attr(any(feature = "testing", test), automock)] | ||
#[async_trait] | ||
pub trait L1ProviderClient: Send + Sync { | ||
async fn get_txs(&self, n_txs: usize) -> L1ProviderClientResult<Vec<L1HandlerTransaction>>; | ||
async fn validate(&self, _tx_hash: TransactionHash) | ||
-> L1ProviderClientResult<ValidationStatus>; | ||
} | ||
|
||
#[async_trait] | ||
impl<ComponentClientType> L1ProviderClient for ComponentClientType | ||
where | ||
ComponentClientType: Send + Sync + ComponentClient<L1ProviderRequest, L1ProviderResponse>, | ||
{ | ||
#[instrument(skip(self))] | ||
async fn get_txs(&self, n_txs: usize) -> L1ProviderClientResult<Vec<L1HandlerTransaction>> { | ||
let request = L1ProviderRequest::GetTransactions(n_txs); | ||
let response = self.send(request).await; | ||
handle_response_variants!( | ||
L1ProviderResponse, | ||
GetTransactions, | ||
L1ProviderClientError, | ||
L1ProviderError | ||
) | ||
} | ||
async fn validate( | ||
&self, | ||
_tx_hash: TransactionHash, | ||
) -> L1ProviderClientResult<ValidationStatus> { | ||
todo!(); | ||
} | ||
} |