From 4df20c415a212b53714075ccb9036c442244bfe0 Mon Sep 17 00:00:00 2001 From: aner-starkware <147302140+aner-starkware@users.noreply.github.com> Date: Sun, 3 Nov 2024 11:00:35 +0200 Subject: [PATCH] fix(blockifier_reexecution): fix get_contract_class signature and remove duplicate (#1736) --- .../state_reader/reexecution_state_reader.rs | 6 ++-- .../src/state_reader/test_state_reader.rs | 29 +++++-------------- 2 files changed, 10 insertions(+), 25 deletions(-) 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 843a3278d9..e0b1b67734 100644 --- a/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs @@ -1,4 +1,5 @@ use blockifier::execution::contract_class::ClassInfo; +use blockifier::state::state_api::StateResult; use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction; use papyrus_execution::DEPRECATED_CONTRACT_SIERRA_SIZE; use starknet_api::core::ClassHash; @@ -10,11 +11,10 @@ use crate::state_reader::errors::ReexecutionError; use crate::state_reader::test_state_reader::ReexecutionResult; pub(crate) trait ReexecutionStateReader { - fn get_contract_class(&self, class_hash: ClassHash) - -> ReexecutionResult; + fn get_contract_class(&self, class_hash: &ClassHash) -> StateResult; fn get_class_info(&self, class_hash: ClassHash) -> ReexecutionResult { - match self.get_contract_class(class_hash)? { + match self.get_contract_class(&class_hash)? { StarknetContractClass::Sierra(sierra) => { let abi_length = sierra.abi.len(); let sierra_length = sierra.sierra_program.len(); 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 e7902b3c9e..13b86f691a 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -158,24 +158,6 @@ impl TestStateReader { )?) } - pub fn get_contract_class(&self, class_hash: &ClassHash) -> StateResult { - let params = json!({ - "block_id": self.rpc_state_reader.block_id, - "class_hash": class_hash.0.to_string(), - }); - let contract_class: StarknetContractClass = serde_json::from_value( - self.rpc_state_reader.send_rpc_request("starknet_getClass", params.clone())?, - ) - .map_err(serde_err_to_state_err)?; - // Create a binding to avoid value being dropped. - let mut dumper_binding = self.contract_class_mapping_dumper.lock().unwrap(); - // If dumper exists, insert the contract class to the mapping. - if let Some(contract_class_mapping_dumper) = dumper_binding.as_mut() { - contract_class_mapping_dumper.insert(*class_hash, contract_class.clone()); - } - Ok(contract_class) - } - pub fn get_all_txs_in_block(&self) -> ReexecutionResult> { // TODO(Aviv): Use batch request to get all txs in a block. self.get_tx_hashes()? @@ -262,10 +244,7 @@ impl TestStateReader { } impl ReexecutionStateReader for TestStateReader { - fn get_contract_class( - &self, - class_hash: ClassHash, - ) -> ReexecutionResult { + fn get_contract_class(&self, class_hash: &ClassHash) -> StateResult { let params = json!({ "block_id": self.rpc_state_reader.block_id, "class_hash": class_hash.0.to_string(), @@ -274,6 +253,12 @@ impl ReexecutionStateReader for TestStateReader { self.rpc_state_reader.send_rpc_request("starknet_getClass", params.clone())?, ) .map_err(serde_err_to_state_err)?; + // Create a binding to avoid value being dropped. + let mut dumper_binding = self.contract_class_mapping_dumper.lock().unwrap(); + // If dumper exists, insert the contract class to the mapping. + if let Some(contract_class_mapping_dumper) = dumper_binding.as_mut() { + contract_class_mapping_dumper.insert(*class_hash, contract_class.clone()); + } Ok(contract_class) } }