-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_l1_provider_types): add client
- Loading branch information
Gilad Chase
committed
Dec 10, 2024
1 parent
241ef4a
commit f7f22e7
Showing
4 changed files
with
87 additions
and
1 deletion.
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
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!(); | ||
} | ||
} |