Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(starknet_gateway): create sync state reader infra with todos #2754

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
state_sync_client: SharedStateSyncClient,
}

impl SyncStateReader {
pub fn from_number(
state_sync_client: SharedStateSyncClient,
block_number: BlockNumber,
) -> Self {
Self { block_number, state_sync_client }
}
}

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.clone(), 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 StateSyncReader
// TODO: Add get_nonce_at for StateSyncReader
// TODO: Add get_compiled_class for StateSyncReader
// TODO: Add get_class_hash_at for StateSyncReader
// TODO: Add get_compiled_class_hash for StateSyncReader
// TODO: Add get_block_info for StateSyncReader
}

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