Skip to content

Commit

Permalink
chore(starknet_gateway): create sync state reader infra with todos
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Dec 18, 2024
1 parent 32e130d commit 0f4bcbd
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 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 crates/starknet_gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ starknet_gateway_types.workspace = true
starknet_mempool_types.workspace = true
starknet_sequencer_infra.workspace = true
starknet_sierra_compile.workspace = true
starknet_state_sync_types.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod state_reader;
mod state_reader_test_utils;
mod stateful_transaction_validator;
mod stateless_transaction_validator;
mod sync_state_reader;
#[cfg(test)]
mod test_utils;
mod utils;
71 changes: 71 additions & 0 deletions crates/starknet_gateway/src/sync_state_reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult};
use starknet_api::block::{BlockInfo, BlockNumber};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_state_sync_types::communication::SharedStateSyncClient;
use starknet_types_core::felt::Felt;

use crate::state_reader::{MempoolStateReader, StateReaderFactory};

#[allow(dead_code)]
struct SyncStateReader {
block_number: BlockNumber,
shared_state_sync_client: SharedStateSyncClient,
}

impl SyncStateReader {
pub fn from_number(
shared_state_sync_client: &SharedStateSyncClient,
block_number: BlockNumber,
) -> Self {
Self { shared_state_sync_client: shared_state_sync_client.clone(), block_number }
}
}

impl MempoolStateReader for SyncStateReader {
fn get_block_info(&self) -> StateResult<BlockInfo> {
todo!()
}
}

impl BlockifierStateReader for SyncStateReader {
fn get_storage_at(
&self,
_contract_address: ContractAddress,
_key: StorageKey,
) -> StateResult<Felt> {
todo!()
}

fn get_nonce_at(&self, _contract_address: ContractAddress) -> StateResult<Nonce> {
todo!()
}

fn get_compiled_class(&self, _class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
todo!()
}

fn get_class_hash_at(&self, _contract_address: ContractAddress) -> StateResult<ClassHash> {
todo!()
}

fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult<CompiledClassHash> {
todo!()
}
}

pub struct SyncStateReaderFactory {
pub shared_state_sync_client: SharedStateSyncClient,
}

impl StateReaderFactory for SyncStateReaderFactory {
// TODO(noamsp): Decide if we need this
fn get_state_reader_from_latest_block(&self) -> Box<dyn MempoolStateReader> {
todo!()
}

fn get_state_reader(&self, block_number: BlockNumber) -> Box<dyn MempoolStateReader> {
Box::new(SyncStateReader::from_number(&self.shared_state_sync_client, block_number))
}
}
7 changes: 6 additions & 1 deletion crates/starknet_state_sync_types/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ pub trait StateSyncClient: Send + Sync {
sync_block: SyncBlock,
) -> StateSyncClientResult<()>;

// TODO: Add state reader methods for gateway.
// TODO: add get_storage_at for BlockifierStateReader trait
// TODO: add get_nonce_at for BlockifierStateReader trait
// TODO: add get_compiled_class for BlockifierStateReader trait
// TODO: add get_class_hash_at for BlockifierStateReader trait
// TODO: add get_compiled_class_hash for BlockifierStateReader trait
// TODO: add get_block_info for MempoolStateReader trait
}

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

0 comments on commit 0f4bcbd

Please sign in to comment.