diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 343319a239..bbbdcbf228 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -28,7 +28,13 @@ use crate::py_objects::{PyBouncerConfig, PyConcurrencyConfig, PyVersionedConstan use crate::py_state_diff::{PyBlockInfo, PyStateDiff}; use crate::py_transaction::{py_tx, PyClassInfo, PY_TX_PARSING_ERR}; use crate::py_utils::{int_to_chain_id, into_block_number_hash_pair, PyFelt}; -use crate::storage::{PapyrusStorage, Storage, StorageConfig}; +use crate::storage::{ + PapyrusStorage, + RawDeclaredClassMapping, + RawDeprecatedDeclaredClassMapping, + Storage, + StorageConfig, +}; pub(crate) type RawTransactionExecutionResult = Vec; pub(crate) type PyVisitedSegmentsMapping = Vec<(PyFelt, Vec)>; @@ -305,8 +311,8 @@ impl PyBlockExecutor { previous_block_id: Option, py_block_info: PyBlockInfo, py_state_diff: PyStateDiff, - declared_class_hash_to_class: HashMap, - deprecated_declared_class_hash_to_class: HashMap, + declared_class_hash_to_class: RawDeclaredClassMapping, + deprecated_declared_class_hash_to_class: RawDeprecatedDeclaredClassMapping, ) -> NativeBlockifierResult<()> { self.storage.append_block( block_id, diff --git a/crates/native_blockifier/src/py_block_executor_test.rs b/crates/native_blockifier/src/py_block_executor_test.rs index 826d285396..1bd931d7c1 100644 --- a/crates/native_blockifier/src/py_block_executor_test.rs +++ b/crates/native_blockifier/src/py_block_executor_test.rs @@ -8,6 +8,7 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use pretty_assertions::assert_eq; use starknet_api::class_hash; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; +use starknet_api::state::ContractClass; use starknet_types_core::felt::Felt; use crate::py_block_executor::{PyBlockExecutor, PyOsConfig}; @@ -30,6 +31,7 @@ fn global_contract_cache_update() { pythonic_hints: Default::default(), entry_points_by_type: Default::default(), }; + let sierra = ContractClass::default(); let contract_class = RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); let class_hash = class_hash!("0x1"); @@ -49,7 +51,10 @@ fn global_contract_cache_update() { PyStateDiff::default(), HashMap::from([( class_hash.into(), - (PyFelt::from(1_u8), serde_json::to_string(&casm).unwrap()), + ( + serde_json::to_string(&sierra).unwrap(), + (PyFelt::from(1_u8), serde_json::to_string(&casm).unwrap()), + ), )]), HashMap::default(), ) diff --git a/crates/native_blockifier/src/storage.rs b/crates/native_blockifier/src/storage.rs index 50b3a7efa5..ce88de830e 100644 --- a/crates/native_blockifier/src/storage.rs +++ b/crates/native_blockifier/src/storage.rs @@ -22,6 +22,11 @@ use crate::PyStateDiff; const GENESIS_BLOCK_ID: u64 = u64::MAX; +// Class hash to (raw_sierra, (compiled class hash, raw casm)). +pub type RawDeclaredClassMapping = HashMap; +// Class hash to (compiled class hash, raw casm). +pub type RawDeprecatedDeclaredClassMapping = HashMap; + // Invariant: Only one instance of this struct should exist. // Reader and writer fields must be cleared before the struct goes out of scope in Python; // to prevent possible memory leaks (TODO: see if this is indeed necessary). @@ -116,8 +121,8 @@ impl Storage for PapyrusStorage { previous_block_id: Option, py_block_info: PyBlockInfo, py_state_diff: PyStateDiff, - declared_class_hash_to_class: HashMap, - deprecated_declared_class_hash_to_class: HashMap, + declared_class_hash_to_class: RawDeclaredClassMapping, + deprecated_declared_class_hash_to_class: RawDeprecatedDeclaredClassMapping, ) -> NativeBlockifierResult<()> { log::debug!( "Appending state diff with {block_id:?} for block_number: {}.", @@ -167,7 +172,9 @@ impl Storage for PapyrusStorage { let mut declared_classes = IndexMap::::new(); let mut undeclared_casm_contracts = Vec::<(ClassHash, CasmContractClass)>::new(); - for (class_hash, (compiled_class_hash, raw_class)) in declared_class_hash_to_class { + for (class_hash, (raw_sierra, (compiled_class_hash, raw_casm))) in + declared_class_hash_to_class + { let class_hash = ClassHash(class_hash.0); let class_undeclared = self .reader() @@ -177,12 +184,13 @@ impl Storage for PapyrusStorage { .is_none(); if class_undeclared { + let sierra_contract_class: ContractClass = serde_json::from_str(&raw_sierra)?; declared_classes.insert( class_hash, - (CompiledClassHash(compiled_class_hash.0), ContractClass::default()), + (CompiledClassHash(compiled_class_hash.0), sierra_contract_class), ); - let contract_class: CasmContractClass = serde_json::from_str(&raw_class)?; - undeclared_casm_contracts.push((class_hash, contract_class)); + let casm_contract_class: CasmContractClass = serde_json::from_str(&raw_casm)?; + undeclared_casm_contracts.push((class_hash, casm_contract_class)); } } @@ -295,8 +303,8 @@ pub trait Storage { previous_block_id: Option, py_block_info: PyBlockInfo, py_state_diff: PyStateDiff, - declared_class_hash_to_class: HashMap, - deprecated_declared_class_hash_to_class: HashMap, + declared_class_hash_to_class: RawDeclaredClassMapping, + deprecated_declared_class_hash_to_class: RawDeprecatedDeclaredClassMapping, ) -> NativeBlockifierResult<()>; fn validate_aligned(&self, source_block_number: u64); diff --git a/crates/native_blockifier/src/test_utils.rs b/crates/native_blockifier/src/test_utils.rs index 13a2626ecc..1d6ed10858 100644 --- a/crates/native_blockifier/src/test_utils.rs +++ b/crates/native_blockifier/src/test_utils.rs @@ -31,11 +31,8 @@ impl Storage for MockStorage { _previous_block_id: Option, _py_block_info: crate::py_state_diff::PyBlockInfo, _py_state_diff: crate::py_state_diff::PyStateDiff, - _declared_class_hash_to_class: HashMap< - crate::py_utils::PyFelt, - (crate::py_utils::PyFelt, String), - >, - _deprecated_declared_class_hash_to_class: HashMap, + _declared_class_hash_to_class: crate::storage::RawDeclaredClassMapping, + _deprecated_declared_class_hash_to_class: crate::storage::RawDeprecatedDeclaredClassMapping, ) -> NativeBlockifierResult<()> { todo!() }