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

feat(starknet_gateway): implement sync state reader get block info #2942

Merged
merged 1 commit into from
Dec 30, 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
32 changes: 30 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,34 @@ 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: match block_header.l1_da_mode {
L1DataAvailabilityMode::Blob => true,
L1DataAvailabilityMode::Calldata => false,
},
};

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