Skip to content
Merged
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
38 changes: 10 additions & 28 deletions crates/blockifier_reexecution/src/state_reader/rpc_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ use blockifier::state::state_reader_and_contract_manager::{
};
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
use serde::Serialize;
use serde_json::{json, to_value, Value};
use starknet_api::block::{
BlockHash,
BlockHashAndNumber,
BlockInfo,
BlockNumber,
GasPricePerToken,
StarknetVersion,
};
use serde_json::{json, Value};
use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockInfo, BlockNumber, StarknetVersion};
use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::{SierraContractClass, StorageKey};
use starknet_api::transaction::{Transaction, TransactionHash};
Expand Down Expand Up @@ -231,32 +224,21 @@ impl RpcStateReader {
RpcStateReader::new(&get_rpc_state_reader_config(), ChainId::Mainnet, block_number, false)
}

/// Get the block info of the current block.
/// If l2_gas_price is not present in the block header, it will be set to 1.
pub fn get_block_info(&self) -> ReexecutionResult<BlockInfo> {
let mut json = retry_request!(self.retry_config, || {
/// Get the block header of the current block.
pub fn get_block_header(&self) -> ReexecutionResult<BlockHeader> {
let json = retry_request!(self.retry_config, || {
self.rpc_state_reader.send_rpc_request(
"starknet_getBlockWithTxHashes",
GetBlockWithTxHashesParams { block_id: self.rpc_state_reader.block_id },
)
})?;

let block_header_map = json.as_object_mut().ok_or(StateError::StateReadError(
"starknet_getBlockWithTxHashes should return JSON value of type Object".to_string(),
))?;

if block_header_map.get("l2_gas_price").is_none() {
// In old blocks, the l2_gas_price field is not present.
block_header_map.insert(
"l2_gas_price".to_string(),
to_value(GasPricePerToken {
price_in_wei: 1_u8.into(),
price_in_fri: 1_u8.into(),
})?,
);
}
Ok(serde_json::from_value::<BlockHeader>(json)?)
}

Ok(serde_json::from_value::<BlockHeader>(json)?.try_into()?)
/// Get the block info of the current block.
pub fn get_block_info(&self) -> ReexecutionResult<BlockInfo> {
Ok(self.get_block_header()?.try_into()?)
}

pub fn get_starknet_version(&self) -> ReexecutionResult<StarknetVersion> {
Expand Down