-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sync): add StateSyncClient and SyncBlock (#2007)
- Loading branch information
1 parent
25eeca0
commit bcb6338
Showing
7 changed files
with
86 additions
and
0 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,16 @@ | ||
[package] | ||
name = "starknet_state_sync_types" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
async-trait.workspace = true | ||
serde = { workspace = true, features = ["derive"] } | ||
starknet_api.workspace = true | ||
starknet_sequencer_infra.workspace = true | ||
thiserror.workspace = true |
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,30 @@ | ||
use async_trait::async_trait; | ||
use starknet_api::block::BlockNumber; | ||
use starknet_sequencer_infra::component_client::ClientError; | ||
use thiserror::Error; | ||
|
||
use crate::errors::StateSyncError; | ||
use crate::state_sync_types::SyncBlock; | ||
|
||
#[async_trait] | ||
pub trait StateSyncClient: Send + Sync { | ||
/// Request for a block at a specific height. | ||
/// If the block doesn't exist, or if the sync didn't download it yet, returns None. | ||
async fn get_block( | ||
&self, | ||
block_number: BlockNumber, | ||
) -> StateSyncClientResult<Option<SyncBlock>>; | ||
|
||
// TODO: Add state reader methods for gateway. | ||
} | ||
|
||
#[derive(Clone, Debug, Error)] | ||
pub enum StateSyncClientError { | ||
#[error(transparent)] | ||
ClientError(#[from] ClientError), | ||
#[error(transparent)] | ||
StateSyncError(#[from] StateSyncError), | ||
} | ||
pub type StateSyncClientResult<T> = Result<T, StateSyncClientError>; | ||
|
||
// TODO: Add client types and request/response enums |
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,6 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
// This error is defined even though it's empty to be compatible with the other components. | ||
#[derive(Debug, Error, Serialize, Deserialize, Clone)] | ||
pub enum StateSyncError {} |
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,3 @@ | ||
pub mod communication; | ||
pub mod errors; | ||
pub mod state_sync_types; |
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,19 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use starknet_api::state::ThinStateDiff; | ||
use starknet_api::transaction::TransactionHash; | ||
|
||
use crate::errors::StateSyncError; | ||
|
||
pub type StateSyncResult<T> = Result<T, StateSyncError>; | ||
|
||
/// A block that came from the state sync. | ||
/// Contains all the data needed to update the state of the system about this block. | ||
/// | ||
/// Blocks that came from the state sync are trusted. Therefore, SyncBlock doesn't contain data | ||
/// needed for verifying the block | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct SyncBlock { | ||
pub state_diff: ThinStateDiff, | ||
// TODO: decide if we want block hash, parent block hash and full classes here. | ||
pub transaction_hashes: Vec<TransactionHash>, | ||
} |