diff --git a/crates/blockifier_reexecution/src/main.rs b/crates/blockifier_reexecution/src/main.rs index 4830d4bd94..fa55a680db 100644 --- a/crates/blockifier_reexecution/src/main.rs +++ b/crates/blockifier_reexecution/src/main.rs @@ -6,7 +6,6 @@ use blockifier_reexecution::state_reader::test_state_reader::{ use blockifier_reexecution::state_reader::utils::JSON_RPC_VERSION; use clap::{Args, Parser, Subcommand}; use starknet_api::block::BlockNumber; -use starknet_api::core::ContractAddress; use starknet_gateway::config::RpcStateReaderConfig; /// BlockifierReexecution CLI. @@ -77,7 +76,7 @@ fn main() { let all_txs_in_next_block = test_state_readers_last_and_current_block.get_next_block_txs().unwrap(); - let mut expected_state_diff = + let expected_state_diff = test_state_readers_last_and_current_block.get_next_block_state_diff().unwrap(); let mut transaction_executor = @@ -87,8 +86,6 @@ fn main() { // Finalize block and read actual statediff. let (actual_state_diff, _, _) = transaction_executor.finalize().expect("Couldn't finalize block"); - // TODO(Aner): compute correct block hash at storage slot 0x1 instead of removing it. - expected_state_diff.storage_updates.shift_remove(&ContractAddress(1_u128.into())); // Compare the expected and actual state differences // by avoiding discrepancies caused by insertion order diff --git a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs index 649c9499ab..2a4aa61909 100644 --- a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs @@ -3,6 +3,7 @@ use blockifier::state::state_api::StateResult; use blockifier::test_utils::MAX_FEE; use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction; use papyrus_execution::DEPRECATED_CONTRACT_SIERRA_SIZE; +use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::core::ClassHash; use starknet_api::transaction::{Transaction, TransactionHash}; use starknet_core::types::ContractClass as StarknetContractClass; @@ -72,4 +73,6 @@ pub(crate) trait ReexecutionStateReader { }) .collect() } + + fn get_old_block_hash(&self, old_block_number: BlockNumber) -> ReexecutionResult; } diff --git a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs index 8252c8a3a6..c2effd18e5 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fs; use std::sync::{Arc, Mutex}; +use blockifier::abi::constants; use blockifier::blockifier::block::BlockInfo; use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::TransactionExecutor; @@ -15,14 +16,19 @@ use blockifier::transaction::transaction_execution::Transaction as BlockifierTra use blockifier::versioned_constants::VersionedConstants; use serde::{Deserialize, Serialize}; use serde_json::{json, to_value}; -use starknet_api::block::{BlockNumber, StarknetVersion}; +use starknet_api::block::{BlockHash, BlockHashAndNumber, BlockNumber, StarknetVersion}; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_api::transaction::{Transaction, TransactionHash}; use starknet_core::types::ContractClass as StarknetContractClass; use starknet_gateway::config::RpcStateReaderConfig; use starknet_gateway::errors::{serde_err_to_state_err, RPCStateReaderError}; -use starknet_gateway::rpc_objects::{BlockHeader, GetBlockWithTxHashesParams, ResourcePrice}; +use starknet_gateway::rpc_objects::{ + BlockHeader, + BlockId, + GetBlockWithTxHashesParams, + ResourcePrice, +}; use starknet_gateway::rpc_state_reader::RpcStateReader; use starknet_types_core::felt::Felt; @@ -295,11 +301,17 @@ impl TestStateReader { block_context_next_block: BlockContext, transaction_executor_config: Option, ) -> ReexecutionResult> { - Ok(TransactionExecutor::::new( - CachedState::new(self), + let old_block_number = BlockNumber( + block_context_next_block.block_info().block_number.0 + - constants::STORED_BLOCK_HASH_BUFFER, + ); + let old_block_hash = self.get_old_block_hash(old_block_number)?; + Ok(TransactionExecutor::::pre_process_and_create( + self, block_context_next_block, + Some(BlockHashAndNumber { number: old_block_number, hash: old_block_hash }), transaction_executor_config.unwrap_or_default(), - )) + )?) } pub fn get_state_diff(&self) -> ReexecutionResult { @@ -375,6 +387,15 @@ impl ReexecutionStateReader for TestStateReader { } Ok(contract_class) } + + fn get_old_block_hash(&self, old_block_number: BlockNumber) -> ReexecutionResult { + let block_id = BlockId::Number(old_block_number); + let params = GetBlockWithTxHashesParams { block_id }; + let response = + self.rpc_state_reader.send_rpc_request("starknet_getBlockWithTxHashes", params)?; + let block_hash_raw: String = serde_json::from_value(response["block_hash"].clone())?; + Ok(BlockHash(Felt::from_hex(&block_hash_raw).unwrap())) + } } /// Trait of the functions \ queries required for reexecution. @@ -503,6 +524,10 @@ impl ReexecutionStateReader for OfflineStateReader { )))? .clone()) } + + fn get_old_block_hash(&self, _old_block_number: BlockNumber) -> ReexecutionResult { + todo!() + } } impl OfflineStateReader {