From b117387bf07ed1cc270f03f9b2aaf88b1afa8793 Mon Sep 17 00:00:00 2001 From: Yonatan Iluz Date: Wed, 27 Nov 2024 08:32:35 +0200 Subject: [PATCH] refactor(blockifier): rename ContractClass to CompiledClass --- .../src/concurrency/versioned_state.rs | 6 +-- .../src/execution/contract_class.rs | 53 ++++++++++--------- .../src/execution/contract_class_test.rs | 4 +- .../deprecated_entry_point_execution.rs | 8 +-- .../src/execution/entry_point_execution.rs | 8 +-- .../src/execution/execution_utils.rs | 12 ++--- .../src/execution/native/contract_class.rs | 30 +++++------ .../execution/native/entry_point_execution.rs | 4 +- .../src/execution/native/syscall_handler.rs | 2 +- crates/blockifier/src/state/cached_state.rs | 10 ++-- crates/blockifier/src/state/global_cache.rs | 8 +-- crates/blockifier/src/state/state_api.rs | 8 +-- crates/blockifier/src/test_utils/contracts.rs | 16 +++--- .../src/test_utils/dict_state_reader.rs | 6 +-- .../blockifier/src/test_utils/struct_impls.rs | 18 +++---- .../src/transaction/account_transaction.rs | 10 ++-- .../src/state_reader/test_state_reader.rs | 6 +-- .../src/py_block_executor.rs | 4 +- .../src/py_block_executor_test.rs | 4 +- crates/native_blockifier/src/py_test_utils.rs | 4 +- .../src/state_readers/py_state_reader.rs | 18 +++---- .../papyrus_execution/src/execution_utils.rs | 16 +++--- crates/papyrus_execution/src/state_reader.rs | 16 +++--- .../src/state_reader_test.rs | 12 ++--- .../papyrus_state_reader/src/papyrus_state.rs | 18 +++---- crates/starknet_batcher/src/block_builder.rs | 4 +- .../starknet_gateway/src/rpc_state_reader.rs | 16 +++--- .../src/rpc_state_reader_test.rs | 4 +- crates/starknet_gateway/src/state_reader.rs | 4 +- .../src/state_reader_test_utils.rs | 4 +- 30 files changed, 167 insertions(+), 166 deletions(-) diff --git a/crates/blockifier/src/concurrency/versioned_state.rs b/crates/blockifier/src/concurrency/versioned_state.rs index 33d97670b9..60d5fc56c5 100644 --- a/crates/blockifier/src/concurrency/versioned_state.rs +++ b/crates/blockifier/src/concurrency/versioned_state.rs @@ -7,7 +7,7 @@ use starknet_types_core::felt::Felt; use crate::concurrency::versioned_storage::VersionedStorage; use crate::concurrency::TxIndex; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::state::cached_state::{ContractClassMapping, StateMaps}; use crate::state::errors::StateError; use crate::state::state_api::{StateReader, StateResult, UpdatableState}; @@ -34,7 +34,7 @@ pub struct VersionedState { // the compiled contract classes mapping. Each key with value false, sohuld not apprear // in the compiled contract classes mapping. declared_contracts: VersionedStorage, - compiled_contract_classes: VersionedStorage, + compiled_contract_classes: VersionedStorage, } impl VersionedState { @@ -339,7 +339,7 @@ impl StateReader for VersionedStateProxy { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let mut state = self.state(); match state.compiled_contract_classes.read(self.tx_index, class_hash) { Some(value) => Ok(value), diff --git a/crates/blockifier/src/execution/contract_class.rs b/crates/blockifier/src/execution/contract_class.rs index c1c6eec804..cf3d7289f9 100644 --- a/crates/blockifier/src/execution/contract_class.rs +++ b/crates/blockifier/src/execution/contract_class.rs @@ -37,7 +37,7 @@ use crate::execution::entry_point::CallEntryPoint; use crate::execution::errors::PreExecutionError; use crate::execution::execution_utils::{poseidon_hash_many_cost, sn_api_to_cairo_vm_program}; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::transaction::errors::TransactionExecutionError; use crate::versioned_constants::CompilerVersion; @@ -58,16 +58,17 @@ pub enum TrackedResource { SierraGas, // AKA Sierra mode. } -/// Represents a runnable Starknet contract class (meaning, the program is runnable by the VM). +/// Represents a runnable Starknet compiled class. +/// Meaning, the program is runnable by the VM (or natively). #[derive(Clone, Debug, Eq, PartialEq, derive_more::From)] -pub enum RunnableContractClass { - V0(ContractClassV0), - V1(ContractClassV1), +pub enum RunnableCompiledClass { + V0(CompiledClassV0), + V1(CompiledClassV1), #[cfg(feature = "cairo_native")] - V1Native(NativeContractClassV1), + V1Native(NativeCompiledClassV1), } -impl TryFrom for RunnableContractClass { +impl TryFrom for RunnableCompiledClass { type Error = ProgramError; fn try_from(raw_contract_class: ContractClass) -> Result { @@ -80,7 +81,7 @@ impl TryFrom for RunnableContractClass { } } -impl RunnableContractClass { +impl RunnableCompiledClass { pub fn constructor_selector(&self) -> Option { match self { Self::V0(class) => class.constructor_selector(), @@ -156,16 +157,16 @@ impl RunnableContractClass { // Note: when deserializing from a SN API class JSON string, the ABI field is ignored // by serde, since it is not required for execution. #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct ContractClassV0(pub Arc); -impl Deref for ContractClassV0 { - type Target = ContractClassV0Inner; +pub struct CompiledClassV0(pub Arc); +impl Deref for CompiledClassV0 { + type Target = CompiledClassV0Inner; fn deref(&self) -> &Self::Target { &self.0 } } -impl ContractClassV0 { +impl CompiledClassV0 { fn constructor_selector(&self) -> Option { Some(self.entry_points_by_type[&EntryPointType::Constructor].first()?.selector) } @@ -201,24 +202,24 @@ impl ContractClassV0 { TrackedResource::CairoSteps } - pub fn try_from_json_string(raw_contract_class: &str) -> Result { - let contract_class: ContractClassV0Inner = serde_json::from_str(raw_contract_class)?; - Ok(ContractClassV0(Arc::new(contract_class))) + pub fn try_from_json_string(raw_contract_class: &str) -> Result { + let contract_class: CompiledClassV0Inner = serde_json::from_str(raw_contract_class)?; + Ok(CompiledClassV0(Arc::new(contract_class))) } } #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] -pub struct ContractClassV0Inner { +pub struct CompiledClassV0Inner { #[serde(deserialize_with = "deserialize_program")] pub program: Program, pub entry_points_by_type: HashMap>, } -impl TryFrom for ContractClassV0 { +impl TryFrom for CompiledClassV0 { type Error = ProgramError; fn try_from(class: DeprecatedContractClass) -> Result { - Ok(Self(Arc::new(ContractClassV0Inner { + Ok(Self(Arc::new(CompiledClassV0Inner { program: sn_api_to_cairo_vm_program(class.program)?, entry_points_by_type: class.entry_points_by_type, }))) @@ -227,12 +228,12 @@ impl TryFrom for ContractClassV0 { // V1. -/// Represents a runnable Cario (Cairo 1) Starknet contract class (meaning, the program is runnable +/// Represents a runnable Cario (Cairo 1) Starknet compiled class (meaning, the program is runnable /// by the VM). We wrap the actual class in an Arc to avoid cloning the program when cloning the /// class. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct ContractClassV1(pub Arc); -impl Deref for ContractClassV1 { +pub struct CompiledClassV1(pub Arc); +impl Deref for CompiledClassV1 { type Target = ContractClassV1Inner; fn deref(&self) -> &Self::Target { @@ -240,7 +241,7 @@ impl Deref for ContractClassV1 { } } -impl ContractClassV1 { +impl CompiledClassV1 { pub fn constructor_selector(&self) -> Option { self.0.entry_points_by_type.constructor.first().map(|ep| ep.selector) } @@ -286,9 +287,9 @@ impl ContractClassV1 { get_visited_segments(&self.bytecode_segment_lengths, &mut reversed_visited_pcs, &mut 0) } - pub fn try_from_json_string(raw_contract_class: &str) -> Result { + pub fn try_from_json_string(raw_contract_class: &str) -> Result { let casm_contract_class: CasmContractClass = serde_json::from_str(raw_contract_class)?; - let contract_class = ContractClassV1::try_from(casm_contract_class)?; + let contract_class = CompiledClassV1::try_from(casm_contract_class)?; Ok(contract_class) } @@ -413,7 +414,7 @@ impl HasSelector for EntryPointV1 { } } -impl TryFrom for ContractClassV1 { +impl TryFrom for CompiledClassV1 { type Error = ProgramError; fn try_from(class: CasmContractClass) -> Result { @@ -466,7 +467,7 @@ impl TryFrom for ContractClassV1 { Version::parse(&class.compiler_version) .unwrap_or_else(|_| panic!("Invalid version: '{}'", class.compiler_version)), ); - Ok(ContractClassV1(Arc::new(ContractClassV1Inner { + Ok(CompiledClassV1(Arc::new(ContractClassV1Inner { program, entry_points_by_type, hints: string_to_hint, diff --git a/crates/blockifier/src/execution/contract_class_test.rs b/crates/blockifier/src/execution/contract_class_test.rs index 6dcfd7411e..bbf9bedc6c 100644 --- a/crates/blockifier/src/execution/contract_class_test.rs +++ b/crates/blockifier/src/execution/contract_class_test.rs @@ -5,12 +5,12 @@ use assert_matches::assert_matches; use cairo_lang_starknet_classes::NestedIntList; use rstest::rstest; -use crate::execution::contract_class::{ContractClassV1, ContractClassV1Inner}; +use crate::execution::contract_class::{CompiledClassV1, ContractClassV1Inner}; use crate::transaction::errors::TransactionExecutionError; #[rstest] fn test_get_visited_segments() { - let test_contract = ContractClassV1(Arc::new(ContractClassV1Inner { + let test_contract = CompiledClassV1(Arc::new(ContractClassV1Inner { program: Default::default(), entry_points_by_type: Default::default(), hints: Default::default(), diff --git a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs index fd4084682d..199d232d71 100644 --- a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs +++ b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs @@ -14,7 +14,7 @@ use starknet_api::hash::StarkHash; use super::execution_utils::SEGMENT_ARENA_BUILTIN_SIZE; use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources}; -use crate::execution::contract_class::{ContractClassV0, TrackedResource}; +use crate::execution::contract_class::{CompiledClassV0, TrackedResource}; use crate::execution::deprecated_syscalls::hint_processor::DeprecatedSyscallHintProcessor; use crate::execution::entry_point::{ CallEntryPoint, @@ -44,7 +44,7 @@ pub const CAIRO0_BUILTINS_NAMES: [BuiltinName; 6] = [ /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: ContractClassV0, + contract_class: CompiledClassV0, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { @@ -67,7 +67,7 @@ pub fn execute_entry_point_call( pub fn initialize_execution_context<'a>( call: &CallEntryPoint, - contract_class: ContractClassV0, + contract_class: CompiledClassV0, state: &'a mut dyn State, context: &'a mut EntryPointExecutionContext, ) -> Result, PreExecutionError> { @@ -110,7 +110,7 @@ pub fn initialize_execution_context<'a>( pub fn resolve_entry_point_pc( call: &CallEntryPoint, - contract_class: &ContractClassV0, + contract_class: &CompiledClassV0, ) -> Result { if call.entry_point_type == EntryPointType::Constructor && call.entry_point_selector != selector_from_name(CONSTRUCTOR_ENTRY_POINT_NAME) diff --git a/crates/blockifier/src/execution/entry_point_execution.rs b/crates/blockifier/src/execution/entry_point_execution.rs index 070e55be8a..bddfe994aa 100644 --- a/crates/blockifier/src/execution/entry_point_execution.rs +++ b/crates/blockifier/src/execution/entry_point_execution.rs @@ -14,7 +14,7 @@ use starknet_api::execution_resources::GasAmount; use starknet_types_core::felt::Felt; use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources, Retdata}; -use crate::execution::contract_class::{ContractClassV1, EntryPointV1, TrackedResource}; +use crate::execution::contract_class::{CompiledClassV1, EntryPointV1, TrackedResource}; use crate::execution::entry_point::{ CallEntryPoint, EntryPointExecutionContext, @@ -57,7 +57,7 @@ pub struct CallResult { /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: ContractClassV1, + contract_class: CompiledClassV1, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { @@ -142,7 +142,7 @@ fn register_visited_pcs( pub fn initialize_execution_context<'a>( call: CallEntryPoint, - contract_class: &'a ContractClassV1, + contract_class: &'a CompiledClassV1, state: &'a mut dyn State, context: &'a mut EntryPointExecutionContext, ) -> Result, PreExecutionError> { @@ -189,7 +189,7 @@ pub fn initialize_execution_context<'a>( fn prepare_program_extra_data( runner: &mut CairoRunner, - contract_class: &ContractClassV1, + contract_class: &CompiledClassV1, read_only_segments: &mut ReadOnlySegments, gas_costs: &GasCosts, ) -> Result { diff --git a/crates/blockifier/src/execution/execution_utils.rs b/crates/blockifier/src/execution/execution_utils.rs index d2c0b9aeaf..54498ae76d 100644 --- a/crates/blockifier/src/execution/execution_utils.rs +++ b/crates/blockifier/src/execution/execution_utils.rs @@ -22,7 +22,7 @@ use starknet_api::transaction::fields::Calldata; use starknet_types_core::felt::Felt; use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; -use crate::execution::contract_class::{RunnableContractClass, TrackedResource}; +use crate::execution::contract_class::{RunnableCompiledClass, TrackedResource}; use crate::execution::entry_point::{ execute_constructor_entry_point, CallEntryPoint, @@ -52,7 +52,7 @@ pub const SEGMENT_ARENA_BUILTIN_SIZE: usize = 3; /// A wrapper for execute_entry_point_call that performs pre and post-processing. pub fn execute_entry_point_call_wrapper( mut call: CallEntryPoint, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, state: &mut dyn State, context: &mut EntryPointExecutionContext, remaining_gas: &mut u64, @@ -120,12 +120,12 @@ pub fn execute_entry_point_call_wrapper( /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { match contract_class { - RunnableContractClass::V0(contract_class) => { + RunnableCompiledClass::V0(contract_class) => { deprecated_entry_point_execution::execute_entry_point_call( call, contract_class, @@ -133,11 +133,11 @@ pub fn execute_entry_point_call( context, ) } - RunnableContractClass::V1(contract_class) => { + RunnableCompiledClass::V1(contract_class) => { entry_point_execution::execute_entry_point_call(call, contract_class, state, context) } #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(contract_class) => { + RunnableCompiledClass::V1Native(contract_class) => { if context.tracked_resource_stack.last() == Some(&TrackedResource::CairoSteps) { // We cannot run native with cairo steps as the tracked resources (it's a vm // resouorce). diff --git a/crates/blockifier/src/execution/native/contract_class.rs b/crates/blockifier/src/execution/native/contract_class.rs index 2e85feb4f2..da884062fd 100644 --- a/crates/blockifier/src/execution/native/contract_class.rs +++ b/crates/blockifier/src/execution/native/contract_class.rs @@ -4,20 +4,20 @@ use std::sync::Arc; use cairo_native::executor::AotContractExecutor; use starknet_api::core::EntryPointSelector; -use crate::execution::contract_class::{ContractClassV1, EntryPointV1}; +use crate::execution::contract_class::{CompiledClassV1, EntryPointV1}; use crate::execution::entry_point::CallEntryPoint; use crate::execution::errors::PreExecutionError; #[derive(Clone, Debug, PartialEq, Eq)] -pub struct NativeContractClassV1(pub Arc); -impl Deref for NativeContractClassV1 { - type Target = NativeContractClassV1Inner; +pub struct NativeCompiledClassV1(pub Arc); +impl Deref for NativeCompiledClassV1 { + type Target = NativeCompiledClassV1Inner; fn deref(&self) -> &Self::Target { &self.0 } } -impl NativeContractClassV1 { +impl NativeCompiledClassV1 { pub(crate) fn constructor_selector(&self) -> Option { self.casm.constructor_selector() } @@ -26,8 +26,8 @@ impl NativeContractClassV1 { /// /// executor must be derived from sierra_program which in turn must be derived from /// sierra_contract_class. - pub fn new(executor: AotContractExecutor, casm: ContractClassV1) -> NativeContractClassV1 { - let contract = NativeContractClassV1Inner::new(executor, casm); + pub fn new(executor: AotContractExecutor, casm: CompiledClassV1) -> NativeCompiledClassV1 { + let contract = NativeCompiledClassV1Inner::new(executor, casm); Self(Arc::new(contract)) } @@ -39,29 +39,29 @@ impl NativeContractClassV1 { self.casm.get_entry_point(call) } - pub fn casm(&self) -> ContractClassV1 { + pub fn casm(&self) -> CompiledClassV1 { self.casm.clone() } } #[derive(Debug)] -pub struct NativeContractClassV1Inner { +pub struct NativeCompiledClassV1Inner { pub executor: AotContractExecutor, - casm: ContractClassV1, + casm: CompiledClassV1, } -impl NativeContractClassV1Inner { - fn new(executor: AotContractExecutor, casm: ContractClassV1) -> Self { - NativeContractClassV1Inner { executor, casm } +impl NativeCompiledClassV1Inner { + fn new(executor: AotContractExecutor, casm: CompiledClassV1) -> Self { + NativeCompiledClassV1Inner { executor, casm } } } // The location where the compiled contract is loaded into memory will not // be the same therefore we exclude it from the comparison. -impl PartialEq for NativeContractClassV1Inner { +impl PartialEq for NativeCompiledClassV1Inner { fn eq(&self, other: &Self) -> bool { self.casm == other.casm } } -impl Eq for NativeContractClassV1Inner {} +impl Eq for NativeCompiledClassV1Inner {} diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 9a338d593b..cedf50c7da 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -11,14 +11,14 @@ use crate::execution::entry_point::{ EntryPointExecutionResult, }; use crate::execution::errors::{EntryPointExecutionError, PostExecutionError}; -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::execution::native::syscall_handler::NativeSyscallHandler; use crate::state::state_api::State; // todo(rodrigo): add an `entry point not found` test for Native pub fn execute_entry_point_call( call: CallEntryPoint, - contract_class: NativeContractClassV1, + contract_class: NativeCompiledClassV1, state: &mut dyn State, context: &mut EntryPointExecutionContext, ) -> EntryPointExecutionResult { diff --git a/crates/blockifier/src/execution/native/syscall_handler.rs b/crates/blockifier/src/execution/native/syscall_handler.rs index 0c0869d535..654833c8de 100644 --- a/crates/blockifier/src/execution/native/syscall_handler.rs +++ b/crates/blockifier/src/execution/native/syscall_handler.rs @@ -32,7 +32,7 @@ use starknet_types_core::felt::Felt; use crate::execution::call_info::{MessageToL1, OrderedL2ToL1Message, Retdata}; use crate::execution::common_hints::ExecutionMode; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::execution::entry_point::{ CallEntryPoint, CallType, diff --git a/crates/blockifier/src/state/cached_state.rs b/crates/blockifier/src/state/cached_state.rs index ac26d64bd3..7844945809 100644 --- a/crates/blockifier/src/state/cached_state.rs +++ b/crates/blockifier/src/state/cached_state.rs @@ -8,7 +8,7 @@ use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; use crate::context::TransactionContext; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::state::errors::StateError; use crate::state::state_api::{State, StateReader, StateResult, UpdatableState}; use crate::transaction::objects::TransactionExecutionInfo; @@ -18,7 +18,7 @@ use crate::utils::{strict_subtract_mappings, subtract_mappings}; #[path = "cached_state_test.rs"] mod test; -pub type ContractClassMapping = HashMap; +pub type ContractClassMapping = HashMap; /// Caches read and write requests. /// @@ -177,7 +177,7 @@ impl StateReader for CachedState { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let mut cache = self.cache.borrow_mut(); let class_hash_to_class = &mut *self.class_hash_to_class.borrow_mut(); @@ -260,7 +260,7 @@ impl State for CachedState { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, ) -> StateResult<()> { self.class_hash_to_class.get_mut().insert(class_hash, contract_class); let mut cache = self.cache.borrow_mut(); @@ -531,7 +531,7 @@ impl<'a, S: StateReader + ?Sized> StateReader for MutRefState<'a, S> { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { self.0.get_compiled_contract_class(class_hash) } diff --git a/crates/blockifier/src/state/global_cache.rs b/crates/blockifier/src/state/global_cache.rs index 040b116337..f26d4ab39d 100644 --- a/crates/blockifier/src/state/global_cache.rs +++ b/crates/blockifier/src/state/global_cache.rs @@ -8,7 +8,7 @@ use starknet_api::core::ClassHash; use starknet_api::state::SierraContractClass; #[cfg(feature = "cairo_native")] -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; type ContractClassLRUCache = SizedCache; pub type LockedContractClassCache<'a, T> = MutexGuard<'a, ContractClassLRUCache>; @@ -53,18 +53,18 @@ impl GlobalContractCache { #[cfg(feature = "cairo_native")] pub struct GlobalContractCacheManager { - pub casm_cache: GlobalContractCache, + pub casm_cache: GlobalContractCache, pub native_cache: GlobalContractCache, pub sierra_cache: GlobalContractCache>, } #[cfg(feature = "cairo_native")] impl GlobalContractCacheManager { - pub fn get_casm(&self, class_hash: &ClassHash) -> Option { + pub fn get_casm(&self, class_hash: &ClassHash) -> Option { self.casm_cache.get(class_hash) } - pub fn set_casm(&self, class_hash: ClassHash, contract_class: RunnableContractClass) { + pub fn set_casm(&self, class_hash: ClassHash, contract_class: RunnableCompiledClass) { self.casm_cache.set(class_hash, contract_class); } diff --git a/crates/blockifier/src/state/state_api.rs b/crates/blockifier/src/state/state_api.rs index 2b4464d6ab..8b73911f1e 100644 --- a/crates/blockifier/src/state/state_api.rs +++ b/crates/blockifier/src/state/state_api.rs @@ -6,7 +6,7 @@ use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; use super::cached_state::{ContractClassMapping, StateMaps}; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::state::errors::StateError; pub type StateResult = Result; @@ -39,11 +39,11 @@ pub trait StateReader { /// Default: 0 (uninitialized class hash) for an uninitialized contract address. fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult; - /// Returns the contract class of the given class hash. + /// Returns the compiled contract class of the given class hash. fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult; + ) -> StateResult; /// Returns the compiled class hash of the given class hash. fn get_compiled_class_hash(&self, class_hash: ClassHash) -> StateResult; @@ -96,7 +96,7 @@ pub trait State: StateReader { fn set_contract_class( &mut self, class_hash: ClassHash, - contract_class: RunnableContractClass, + contract_class: RunnableCompiledClass, ) -> StateResult<()>; /// Sets the given compiled class hash under the given class hash. diff --git a/crates/blockifier/src/test_utils/contracts.rs b/crates/blockifier/src/test_utils/contracts.rs index 7a4bb8fa93..c3d4ea4ce2 100644 --- a/crates/blockifier/src/test_utils/contracts.rs +++ b/crates/blockifier/src/test_utils/contracts.rs @@ -12,10 +12,10 @@ use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; use strum_macros::EnumIter; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::execution::entry_point::CallEntryPoint; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; #[cfg(feature = "cairo_native")] use crate::test_utils::cairo_compile::starknet_compile; use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile}; @@ -185,12 +185,12 @@ impl FeatureContract { } } - pub fn get_runnable_class(&self) -> RunnableContractClass { + pub fn get_runnable_class(&self) -> RunnableCompiledClass { #[cfg(feature = "cairo_native")] if CairoVersion::Native == self.cairo_version() { let native_contract_class = - NativeContractClassV1::compile_or_get_cached(&self.get_compiled_path()); - return RunnableContractClass::V1Native(native_contract_class); + NativeCompiledClassV1::compile_or_get_cached(&self.get_compiled_path()); + return RunnableCompiledClass::V1Native(native_contract_class); } self.get_class().try_into().unwrap() @@ -365,7 +365,7 @@ impl FeatureContract { entry_point_type: EntryPointType, ) -> EntryPointOffset { match self.get_runnable_class() { - RunnableContractClass::V0(class) => { + RunnableCompiledClass::V0(class) => { class .entry_points_by_type .get(&entry_point_type) @@ -375,7 +375,7 @@ impl FeatureContract { .unwrap() .offset } - RunnableContractClass::V1(class) => { + RunnableCompiledClass::V1(class) => { class .entry_points_by_type .get_entry_point(&CallEntryPoint { @@ -387,7 +387,7 @@ impl FeatureContract { .offset } #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(_) => { + RunnableCompiledClass::V1Native(_) => { panic!("Not implemented for cairo native contracts") } } diff --git a/crates/blockifier/src/test_utils/dict_state_reader.rs b/crates/blockifier/src/test_utils/dict_state_reader.rs index 469e6cbdb7..255aaa2a18 100644 --- a/crates/blockifier/src/test_utils/dict_state_reader.rs +++ b/crates/blockifier/src/test_utils/dict_state_reader.rs @@ -4,7 +4,7 @@ use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::state::StorageKey; use starknet_types_core::felt::Felt; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::state::cached_state::StorageEntry; use crate::state::errors::StateError; use crate::state::state_api::{StateReader, StateResult}; @@ -15,7 +15,7 @@ pub struct DictStateReader { pub storage_view: HashMap, pub address_to_nonce: HashMap, pub address_to_class_hash: HashMap, - pub class_hash_to_class: HashMap, + pub class_hash_to_class: HashMap, pub class_hash_to_compiled_class_hash: HashMap, } @@ -38,7 +38,7 @@ impl StateReader for DictStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let contract_class = self.class_hash_to_class.get(&class_hash).cloned(); match contract_class { Some(contract_class) => Ok(contract_class), diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 581263a05c..dee7020eac 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -27,14 +27,14 @@ use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionCont use crate::execution::call_info::{CallExecution, CallInfo, Retdata}; use crate::execution::common_hints::ExecutionMode; #[cfg(feature = "cairo_native")] -use crate::execution::contract_class::ContractClassV1; +use crate::execution::contract_class::CompiledClassV1; use crate::execution::entry_point::{ CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult, }; #[cfg(feature = "cairo_native")] -use crate::execution::native::contract_class::NativeContractClassV1; +use crate::execution::native::contract_class::NativeCompiledClassV1; use crate::state::state_api::State; use crate::test_utils::{ get_raw_contract_class, @@ -242,12 +242,12 @@ impl BouncerWeights { } #[cfg(feature = "cairo_native")] -static COMPILED_NATIVE_CONTRACT_CACHE: LazyLock>> = +static COMPILED_NATIVE_CONTRACT_CACHE: LazyLock>> = LazyLock::new(|| RwLock::new(HashMap::new())); #[cfg(feature = "cairo_native")] -impl NativeContractClassV1 { - /// Convenience function to construct a NativeContractClassV1 from a raw contract class. +impl NativeCompiledClassV1 { + /// Convenience function to construct a NativeCompiledClassV1 from a raw contract class. /// If control over the compilation is desired use [Self::new] instead. pub fn try_from_json_string(raw_sierra_contract_class: &str) -> Self { let sierra_contract_class: SierraContractClass = @@ -268,10 +268,10 @@ impl NativeContractClassV1 { let casm_contract_class = CasmContractClass::from_contract_class(sierra_contract_class, false, usize::MAX) .expect("Cannot compile sierra contract class into casm contract class"); - let casm = ContractClassV1::try_from(casm_contract_class) - .expect("Cannot get ContractClassV1 from CasmContractClass"); + let casm = CompiledClassV1::try_from(casm_contract_class) + .expect("Cannot get CompiledClassV1 from CasmContractClass"); - NativeContractClassV1::new(executor, casm) + NativeCompiledClassV1::new(executor, casm) } pub fn from_file(contract_path: &str) -> Self { @@ -287,7 +287,7 @@ impl NativeContractClassV1 { } std::mem::drop(cache); - let class = NativeContractClassV1::from_file(path); + let class = NativeCompiledClassV1::from_file(path); let mut cache = COMPILED_NATIVE_CONTRACT_CACHE.write().unwrap(); cache.insert(path.to_string(), class.clone()); class diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 479e2d78e7..58897c3d6a 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -28,7 +28,7 @@ use starknet_types_core::felt::Felt; use crate::context::{BlockContext, TransactionContext}; use crate::execution::call_info::CallInfo; -use crate::execution::contract_class::RunnableContractClass; +use crate::execution::contract_class::RunnableCompiledClass; use crate::execution::entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext}; use crate::execution::stack_trace::{ extract_trailing_cairo1_revert_trace, @@ -932,11 +932,11 @@ impl ValidatableTransaction for AccountTransaction { } } -pub fn is_cairo1(contract_class: &RunnableContractClass) -> bool { +pub fn is_cairo1(contract_class: &RunnableCompiledClass) -> bool { match contract_class { - RunnableContractClass::V0(_) => false, - RunnableContractClass::V1(_) => true, + RunnableCompiledClass::V0(_) => false, + RunnableCompiledClass::V1(_) => true, #[cfg(feature = "cairo_native")] - RunnableContractClass::V1Native(_) => true, + RunnableCompiledClass::V1Native(_) => true, } } 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 5362a6ef63..74411727f0 100644 --- a/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs +++ b/crates/blockifier_reexecution/src/state_reader/test_state_reader.rs @@ -9,7 +9,7 @@ use blockifier::blockifier::config::TransactionExecutorConfig; use blockifier::blockifier::transaction_executor::TransactionExecutor; use blockifier::bouncer::BouncerConfig; use blockifier::context::BlockContext; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::cached_state::{CommitmentStateDiff, StateMaps}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; @@ -220,7 +220,7 @@ impl StateReader for TestStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let contract_class = retry_request!(self.retry_config, || self.get_contract_class(&class_hash))?; @@ -594,7 +594,7 @@ impl StateReader for OfflineStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { match self.get_contract_class(&class_hash)? { StarknetContractClass::Sierra(sierra) => { Ok(sierra_to_contact_class_v1(sierra).unwrap().try_into().unwrap()) diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 17f8604bb1..0cefe8026d 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -6,7 +6,7 @@ use blockifier::blockifier::transaction_executor::{TransactionExecutor, Transact use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses}; use blockifier::execution::call_info::CallInfo; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::fee::receipt::TransactionReceipt; use blockifier::state::global_cache::GlobalContractCache; use blockifier::transaction::objects::{ExecutionResourcesTraits, TransactionExecutionInfo}; @@ -130,7 +130,7 @@ pub struct PyBlockExecutor { pub tx_executor: Option>, /// `Send` trait is required for `pyclass` compatibility as Python objects must be threadsafe. pub storage: Box, - pub global_contract_cache: GlobalContractCache, + pub global_contract_cache: GlobalContractCache, } #[pymethods] diff --git a/crates/native_blockifier/src/py_block_executor_test.rs b/crates/native_blockifier/src/py_block_executor_test.rs index 47a39d3409..cf9c073caf 100644 --- a/crates/native_blockifier/src/py_block_executor_test.rs +++ b/crates/native_blockifier/src/py_block_executor_test.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use blockifier::blockifier::transaction_executor::BLOCK_STATE_ACCESS_ERR; -use blockifier::execution::contract_class::{ContractClassV1, RunnableContractClass}; +use blockifier::execution::contract_class::{CompiledClassV1, RunnableCompiledClass}; use blockifier::state::state_api::StateReader; use cached::Cached; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; @@ -33,7 +33,7 @@ fn global_contract_cache_update() { }; let sierra = SierraContractClass::default(); let contract_class = - RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm.clone()).unwrap()); let class_hash = class_hash!("0x1"); let temp_storage_path = tempfile::tempdir().unwrap().into_path(); diff --git a/crates/native_blockifier/src/py_test_utils.rs b/crates/native_blockifier/src/py_test_utils.rs index 6cae66fa3f..2ba5ac4d48 100644 --- a/crates/native_blockifier/src/py_test_utils.rs +++ b/crates/native_blockifier/src/py_test_utils.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use blockifier::execution::contract_class::ContractClassV0; +use blockifier::execution::contract_class::CompiledClassV0; use blockifier::state::cached_state::CachedState; use blockifier::test_utils::dict_state_reader::DictStateReader; use blockifier::test_utils::struct_impls::LoadContractFromFile; @@ -14,7 +14,7 @@ pub const TOKEN_FOR_TESTING_CONTRACT_PATH: &str = starknet/core/test_contract/token_for_testing.json"; pub fn create_py_test_state() -> CachedState { - let contract_class: ContractClassV0 = + let contract_class: CompiledClassV0 = ContractClass::from_file(TOKEN_FOR_TESTING_CONTRACT_PATH).try_into().unwrap(); let class_hash_to_class = HashMap::from([(class_hash!(TOKEN_FOR_TESTING_CLASS_HASH), contract_class.into())]); diff --git a/crates/native_blockifier/src/state_readers/py_state_reader.rs b/crates/native_blockifier/src/state_readers/py_state_reader.rs index f379dcb05b..6be9e7fca1 100644 --- a/crates/native_blockifier/src/state_readers/py_state_reader.rs +++ b/crates/native_blockifier/src/state_readers/py_state_reader.rs @@ -1,7 +1,7 @@ use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; @@ -71,8 +71,8 @@ impl StateReader for PyStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { - Python::with_gil(|py| -> Result { + ) -> StateResult { + Python::with_gil(|py| -> Result { let args = (PyFelt::from(class_hash),); let py_raw_compiled_class: PyRawCompiledClass = self .state_reader_proxy @@ -80,7 +80,7 @@ impl StateReader for PyStateReader { .call_method1("get_raw_compiled_class", args)? .extract()?; - Ok(RunnableContractClass::try_from(py_raw_compiled_class)?) + Ok(RunnableCompiledClass::try_from(py_raw_compiled_class)?) }) .map_err(|err| { if Python::with_gil(|py| err.is_instance_of::(py)) { @@ -110,14 +110,14 @@ pub struct PyRawCompiledClass { pub version: usize, } -impl TryFrom for RunnableContractClass { +impl TryFrom for RunnableCompiledClass { type Error = NativeBlockifierError; fn try_from(raw_compiled_class: PyRawCompiledClass) -> NativeBlockifierResult { match raw_compiled_class.version { - 0 => Ok(ContractClassV0::try_from_json_string(&raw_compiled_class.raw_compiled_class)? + 0 => Ok(CompiledClassV0::try_from_json_string(&raw_compiled_class.raw_compiled_class)? .into()), - 1 => Ok(ContractClassV1::try_from_json_string(&raw_compiled_class.raw_compiled_class)? + 1 => Ok(CompiledClassV1::try_from_json_string(&raw_compiled_class.raw_compiled_class)? .into()), _ => Err(NativeBlockifierInputError::UnsupportedContractClassVersion { version: raw_compiled_class.version, diff --git a/crates/papyrus_execution/src/execution_utils.rs b/crates/papyrus_execution/src/execution_utils.rs index 45e45d16b8..9a6f34ffb7 100644 --- a/crates/papyrus_execution/src/execution_utils.rs +++ b/crates/papyrus_execution/src/execution_utils.rs @@ -3,9 +3,9 @@ use std::fs::File; use std::path::PathBuf; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, MutRefState}; use blockifier::state::state_api::StateReader; @@ -59,15 +59,15 @@ pub(crate) fn get_contract_class( txn: &StorageTxn<'_, RO>, class_hash: &ClassHash, state_number: StateNumber, -) -> Result, ExecutionUtilsError> { +) -> Result, ExecutionUtilsError> { match txn.get_state_reader()?.get_class_definition_block_number(class_hash)? { Some(block_number) if state_number.is_before(block_number) => return Ok(None), Some(_block_number) => { let Some(casm) = txn.get_casm(class_hash)? else { return Err(ExecutionUtilsError::CasmTableNotSynced); }; - return Ok(Some(RunnableContractClass::V1( - ContractClassV1::try_from(casm).map_err(ExecutionUtilsError::ProgramError)?, + return Ok(Some(RunnableCompiledClass::V1( + CompiledClassV1::try_from(casm).map_err(ExecutionUtilsError::ProgramError)?, ))); } None => {} @@ -78,8 +78,8 @@ pub(crate) fn get_contract_class( else { return Ok(None); }; - Ok(Some(RunnableContractClass::V0( - ContractClassV0::try_from(deprecated_class).map_err(ExecutionUtilsError::ProgramError)?, + Ok(Some(RunnableCompiledClass::V0( + CompiledClassV0::try_from(deprecated_class).map_err(ExecutionUtilsError::ProgramError)?, ))) } diff --git a/crates/papyrus_execution/src/state_reader.rs b/crates/papyrus_execution/src/state_reader.rs index a963241f61..003bc0688e 100644 --- a/crates/papyrus_execution/src/state_reader.rs +++ b/crates/papyrus_execution/src/state_reader.rs @@ -5,9 +5,9 @@ mod state_reader_test; use std::cell::Cell; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; @@ -78,14 +78,14 @@ impl BlockifierStateReader for ExecutionStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { if let Some(pending_casm) = self .maybe_pending_data .as_ref() .and_then(|pending_data| pending_data.classes.get_compiled_class(class_hash)) { - return Ok(RunnableContractClass::V1( - ContractClassV1::try_from(pending_casm).map_err(StateError::ProgramError)?, + return Ok(RunnableCompiledClass::V1( + CompiledClassV1::try_from(pending_casm).map_err(StateError::ProgramError)?, )); } if let Some(ApiContractClass::DeprecatedContractClass(pending_deprecated_class)) = self @@ -93,8 +93,8 @@ impl BlockifierStateReader for ExecutionStateReader { .as_ref() .and_then(|pending_data| pending_data.classes.get_class(class_hash)) { - return Ok(RunnableContractClass::V0( - ContractClassV0::try_from(pending_deprecated_class) + return Ok(RunnableCompiledClass::V0( + CompiledClassV0::try_from(pending_deprecated_class) .map_err(StateError::ProgramError)?, )); } diff --git a/crates/papyrus_execution/src/state_reader_test.rs b/crates/papyrus_execution/src/state_reader_test.rs index ac16c98afa..bab7b98411 100644 --- a/crates/papyrus_execution/src/state_reader_test.rs +++ b/crates/papyrus_execution/src/state_reader_test.rs @@ -2,9 +2,9 @@ use std::cell::Cell; use assert_matches::assert_matches; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::StateReader; @@ -50,7 +50,7 @@ fn read_state() { let class0 = SierraContractClass::default(); let casm0 = get_test_casm(); let blockifier_casm0 = - RunnableContractClass::V1(ContractClassV1::try_from(casm0.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm0.clone()).unwrap()); let compiled_class_hash0 = CompiledClassHash(StarkHash::default()); let class_hash1 = ClassHash(1u128.into()); @@ -65,7 +65,7 @@ fn read_state() { let mut casm1 = get_test_casm(); casm1.bytecode[0] = BigUintAsHex { value: 12345u32.into() }; let blockifier_casm1 = - RunnableContractClass::V1(ContractClassV1::try_from(casm1.clone()).unwrap()); + RunnableCompiledClass::V1(CompiledClassV1::try_from(casm1.clone()).unwrap()); let nonce1 = Nonce(felt!(2_u128)); let class_hash3 = ClassHash(567_u128.into()); let class_hash4 = ClassHash(89_u128.into()); @@ -241,7 +241,7 @@ fn read_state() { // Test that if the class is deprecated it is returned. assert_eq!( state_reader2.get_compiled_contract_class(class_hash4).unwrap(), - RunnableContractClass::V0(ContractClassV0::try_from(class1).unwrap()) + RunnableCompiledClass::V0(CompiledClassV0::try_from(class1).unwrap()) ); // Test get_class_hash_at when the class is replaced. diff --git a/crates/papyrus_state_reader/src/papyrus_state.rs b/crates/papyrus_state_reader/src/papyrus_state.rs index 3ff2cdc46e..f8c729cea4 100644 --- a/crates/papyrus_state_reader/src/papyrus_state.rs +++ b/crates/papyrus_state_reader/src/papyrus_state.rs @@ -1,7 +1,7 @@ use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; @@ -23,14 +23,14 @@ type RawPapyrusReader<'env> = papyrus_storage::StorageTxn<'env, RO>; pub struct PapyrusReader { storage_reader: StorageReader, latest_block: BlockNumber, - global_class_hash_to_class: GlobalContractCache, + global_class_hash_to_class: GlobalContractCache, } impl PapyrusReader { pub fn new( storage_reader: StorageReader, latest_block: BlockNumber, - global_class_hash_to_class: GlobalContractCache, + global_class_hash_to_class: GlobalContractCache, ) -> Self { Self { storage_reader, latest_block, global_class_hash_to_class } } @@ -46,7 +46,7 @@ impl PapyrusReader { fn get_compiled_contract_class_inner( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let state_number = StateNumber(self.latest_block); let class_declaration_block_number = self .reader()? @@ -66,7 +66,7 @@ impl PapyrusReader { inconsistent.", ); - return Ok(RunnableContractClass::V1(ContractClassV1::try_from(casm_contract_class)?)); + return Ok(RunnableCompiledClass::V1(CompiledClassV1::try_from(casm_contract_class)?)); } let v0_contract_class = self @@ -77,7 +77,7 @@ impl PapyrusReader { match v0_contract_class { Some(starknet_api_contract_class) => { - Ok(ContractClassV0::try_from(starknet_api_contract_class)?.into()) + Ok(CompiledClassV0::try_from(starknet_api_contract_class)?.into()) } None => Err(StateError::UndeclaredClassHash(class_hash)), } @@ -127,7 +127,7 @@ impl StateReader for PapyrusReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { // Assumption: the global cache is cleared upon reverted blocks. let contract_class = self.global_class_hash_to_class.get(&class_hash); diff --git a/crates/starknet_batcher/src/block_builder.rs b/crates/starknet_batcher/src/block_builder.rs index 4eab564c0f..ecb944c347 100644 --- a/crates/starknet_batcher/src/block_builder.rs +++ b/crates/starknet_batcher/src/block_builder.rs @@ -11,7 +11,7 @@ use blockifier::blockifier::transaction_executor::{ }; use blockifier::bouncer::{BouncerConfig, BouncerWeights}; use blockifier::context::{BlockContext, ChainInfo}; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::state::errors::StateError; use blockifier::state::global_cache::GlobalContractCache; @@ -296,7 +296,7 @@ impl SerializeConfig for BlockBuilderConfig { pub struct BlockBuilderFactory { pub block_builder_config: BlockBuilderConfig, pub storage_reader: StorageReader, - pub global_class_hash_to_class: GlobalContractCache, + pub global_class_hash_to_class: GlobalContractCache, } impl BlockBuilderFactory { diff --git a/crates/starknet_gateway/src/rpc_state_reader.rs b/crates/starknet_gateway/src/rpc_state_reader.rs index 57eb41212c..55a9c427dc 100644 --- a/crates/starknet_gateway/src/rpc_state_reader.rs +++ b/crates/starknet_gateway/src/rpc_state_reader.rs @@ -1,8 +1,8 @@ use blockifier::blockifier::block::BlockInfo; use blockifier::execution::contract_class::{ - ContractClassV0, - ContractClassV1, - RunnableContractClass, + CompiledClassV0, + CompiledClassV1, + RunnableCompiledClass, }; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; @@ -142,7 +142,7 @@ impl BlockifierStateReader for RpcStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { let get_compiled_class_params = GetCompiledContractClassParams { class_hash, block_id: self.block_id }; @@ -151,11 +151,11 @@ impl BlockifierStateReader for RpcStateReader { let contract_class: CompiledContractClass = serde_json::from_value(result).map_err(serde_err_to_state_err)?; match contract_class { - CompiledContractClass::V1(contract_class_v1) => Ok(RunnableContractClass::V1( - ContractClassV1::try_from(contract_class_v1).map_err(StateError::ProgramError)?, + CompiledContractClass::V1(contract_class_v1) => Ok(RunnableCompiledClass::V1( + CompiledClassV1::try_from(contract_class_v1).map_err(StateError::ProgramError)?, )), - CompiledContractClass::V0(contract_class_v0) => Ok(RunnableContractClass::V0( - ContractClassV0::try_from(contract_class_v0).map_err(StateError::ProgramError)?, + CompiledContractClass::V0(contract_class_v0) => Ok(RunnableCompiledClass::V0( + CompiledClassV0::try_from(contract_class_v0).map_err(StateError::ProgramError)?, )), } } diff --git a/crates/starknet_gateway/src/rpc_state_reader_test.rs b/crates/starknet_gateway/src/rpc_state_reader_test.rs index 034c9db09c..3cae118226 100644 --- a/crates/starknet_gateway/src/rpc_state_reader_test.rs +++ b/crates/starknet_gateway/src/rpc_state_reader_test.rs @@ -1,4 +1,4 @@ -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::state_api::StateReader; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use papyrus_rpc::CompiledContractClass; @@ -188,7 +188,7 @@ async fn test_get_compiled_contract_class() { .await .unwrap() .unwrap(); - assert_eq!(result, RunnableContractClass::V1(expected_result.try_into().unwrap())); + assert_eq!(result, RunnableCompiledClass::V1(expected_result.try_into().unwrap())); mock.assert_async().await; } diff --git a/crates/starknet_gateway/src/state_reader.rs b/crates/starknet_gateway/src/state_reader.rs index 993fe4b5d5..56378525c0 100644 --- a/crates/starknet_gateway/src/state_reader.rs +++ b/crates/starknet_gateway/src/state_reader.rs @@ -1,5 +1,5 @@ use blockifier::blockifier::block::BlockInfo; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; #[cfg(test)] @@ -48,7 +48,7 @@ impl BlockifierStateReader for Box { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { self.as_ref().get_compiled_contract_class(class_hash) } diff --git a/crates/starknet_gateway/src/state_reader_test_utils.rs b/crates/starknet_gateway/src/state_reader_test_utils.rs index faf1121a53..8ca3389407 100644 --- a/crates/starknet_gateway/src/state_reader_test_utils.rs +++ b/crates/starknet_gateway/src/state_reader_test_utils.rs @@ -1,6 +1,6 @@ use blockifier::blockifier::block::BlockInfo; use blockifier::context::BlockContext; -use blockifier::execution::contract_class::RunnableContractClass; +use blockifier::execution::contract_class::RunnableCompiledClass; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader as BlockifierStateReader, StateResult}; use blockifier::test_utils::contracts::FeatureContract; @@ -47,7 +47,7 @@ impl BlockifierStateReader for TestStateReader { fn get_compiled_contract_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { self.blockifier_state_reader.get_compiled_contract_class(class_hash) }