Skip to content

Commit

Permalink
feat(sync): add StateSyncClient and SyncBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama committed Nov 13, 2024
1 parent 87b728f commit 76a1e57
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ members = [
"crates/starknet_sequencer_infra",
"crates/starknet_sequencer_node",
"crates/starknet_sierra_compile",
"crates/starknet_state_sync_types",
"crates/starknet_task_executor",
"workspace_tests",
]
Expand Down
16 changes: 16 additions & 0 deletions crates/starknet_state_sync_types/Cargo.toml
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
28 changes: 28 additions & 0 deletions crates/starknet_state_sync_types/src/communication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 {
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
6 changes: 6 additions & 0 deletions crates/starknet_state_sync_types/src/errors.rs
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 {}
3 changes: 3 additions & 0 deletions crates/starknet_state_sync_types/src/lib.rs
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;
21 changes: 21 additions & 0 deletions crates/starknet_state_sync_types/src/state_sync_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::collections::HashMap;

use starknet_api::block::BlockHash;
use starknet_api::core::ClassHash;
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_api::state::{ContractClass, ThinStateDiff};
use starknet_api::transaction::TransactionHash;

use crate::errors::StateSyncError;

pub type StateSyncResult<T> = Result<T, StateSyncError>;

pub struct SyncBlock {
pub block_hash: BlockHash,
pub parent_block_hash: BlockHash,
pub state_diff: ThinStateDiff,
pub classes: HashMap<ClassHash, ContractClass>,
// TODO: Consider removing deprecated classes.
pub deprecated_classes: HashMap<ClassHash, DeprecatedContractClass>,
pub transaction_hashes: Vec<TransactionHash>,
}

0 comments on commit 76a1e57

Please sign in to comment.