Skip to content

Commit

Permalink
feat(starknet_gateway): implement sync state reader get block info
Browse files Browse the repository at this point in the history
  • Loading branch information
noamsp-starkware committed Dec 26, 2024
1 parent 4a95470 commit 8c370b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
29 changes: 27 additions & 2 deletions crates/starknet_gateway/src/sync_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult};
use futures::executor::block_on;
use starknet_api::block::{BlockInfo, BlockNumber};
use starknet_api::block::{BlockInfo, BlockNumber, GasPriceVector, GasPrices};
use starknet_api::contract_class::ContractClass;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::data_availability::L1DataAvailabilityMode;
use starknet_api::state::StorageKey;
use starknet_state_sync_types::communication::SharedStateSyncClient;
use starknet_types_core::felt::Felt;
Expand All @@ -28,7 +29,31 @@ impl SyncStateReader {

impl MempoolStateReader for SyncStateReader {
fn get_block_info(&self) -> StateResult<BlockInfo> {
todo!()
let block = block_on(self.state_sync_client.get_block(self.block_number))
.map_err(|e| StateError::StateReadError(e.to_string()))?
.ok_or(StateError::StateReadError("Block not found".to_string()))?;

let block_header = block.block_header_without_hash;
let block_info = BlockInfo {
block_number: block_header.block_number,
block_timestamp: block_header.timestamp,
sequencer_address: block_header.sequencer.0,
gas_prices: GasPrices {
eth_gas_prices: GasPriceVector {
l1_gas_price: block_header.l1_gas_price.price_in_wei.try_into()?,
l1_data_gas_price: block_header.l1_data_gas_price.price_in_wei.try_into()?,
l2_gas_price: block_header.l2_gas_price.price_in_wei.try_into()?,
},
strk_gas_prices: GasPriceVector {
l1_gas_price: block_header.l1_gas_price.price_in_fri.try_into()?,
l1_data_gas_price: block_header.l1_data_gas_price.price_in_fri.try_into()?,
l2_gas_price: block_header.l2_gas_price.price_in_fri.try_into()?,
},
},
use_kzg_da: matches!(block_header.l1_da_mode, L1DataAvailabilityMode::Blob),
};

Ok(block_info)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/starknet_state_sync_types/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub trait StateSyncClient: Send + Sync {
) -> StateSyncClientResult<ContractClass>;

// TODO: Add get_compiled_class_hash for StateSyncReader
// TODO: Add get_block_info for StateSyncReader
}

#[derive(Clone, Debug, Error)]
Expand Down

0 comments on commit 8c370b3

Please sign in to comment.