diff --git a/crates/blockifier/src/state/global_cache.rs b/crates/blockifier/src/state/global_cache.rs index 0a21c3759d8..040b1163375 100644 --- a/crates/blockifier/src/state/global_cache.rs +++ b/crates/blockifier/src/state/global_cache.rs @@ -5,7 +5,7 @@ use cached::{Cached, SizedCache}; use cairo_native::executor::AotContractExecutor; use starknet_api::core::ClassHash; #[cfg(feature = "cairo_native")] -use starknet_api::state::ContractClass as SierraContractClass; +use starknet_api::state::SierraContractClass; #[cfg(feature = "cairo_native")] use crate::execution::contract_class::RunnableContractClass; diff --git a/crates/native_blockifier/src/py_block_executor_test.rs b/crates/native_blockifier/src/py_block_executor_test.rs index 1bd931d7c18..47a39d3409c 100644 --- a/crates/native_blockifier/src/py_block_executor_test.rs +++ b/crates/native_blockifier/src/py_block_executor_test.rs @@ -8,7 +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_api::state::SierraContractClass; use starknet_types_core::felt::Felt; use crate::py_block_executor::{PyBlockExecutor, PyOsConfig}; @@ -31,7 +31,7 @@ fn global_contract_cache_update() { pythonic_hints: Default::default(), entry_points_by_type: Default::default(), }; - let sierra = ContractClass::default(); + let sierra = SierraContractClass::default(); let contract_class = RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap()); let class_hash = class_hash!("0x1"); diff --git a/crates/native_blockifier/src/storage.rs b/crates/native_blockifier/src/storage.rs index ce88de830ea..8f6dc054715 100644 --- a/crates/native_blockifier/src/storage.rs +++ b/crates/native_blockifier/src/storage.rs @@ -13,7 +13,7 @@ use starknet_api::block::{BlockHash, BlockHeader, BlockHeaderWithoutHash, BlockN use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, StateDiff, StateNumber, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateDiff, StateNumber, ThinStateDiff}; use crate::errors::NativeBlockifierResult; use crate::py_state_diff::PyBlockInfo; @@ -170,7 +170,8 @@ impl Storage for PapyrusStorage { py_state_diff.address_to_class_hash.remove(&address.into()); }); - let mut declared_classes = IndexMap::::new(); + let mut declared_classes = + IndexMap::::new(); let mut undeclared_casm_contracts = Vec::<(ClassHash, CasmContractClass)>::new(); for (class_hash, (raw_sierra, (compiled_class_hash, raw_casm))) in declared_class_hash_to_class @@ -184,7 +185,7 @@ impl Storage for PapyrusStorage { .is_none(); if class_undeclared { - let sierra_contract_class: ContractClass = serde_json::from_str(&raw_sierra)?; + let sierra_contract_class: SierraContractClass = serde_json::from_str(&raw_sierra)?; declared_classes.insert( class_hash, (CompiledClassHash(compiled_class_hash.0), sierra_contract_class), diff --git a/crates/papyrus_common/src/class_hash.rs b/crates/papyrus_common/src/class_hash.rs index fe74ecd8855..a1b1e91cad8 100644 --- a/crates/papyrus_common/src/class_hash.rs +++ b/crates/papyrus_common/src/class_hash.rs @@ -6,7 +6,7 @@ use sha3::Digest; use starknet_api::contract_class::EntryPointType; use starknet_api::core::ClassHash; use starknet_api::hash::PoseidonHash; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; use starknet_types_core::felt::Felt; use starknet_types_core::hash::{Poseidon, StarkHash}; @@ -18,7 +18,7 @@ lazy_static! { /// Calculates the hash of a contract class. // Based on Pathfinder code (the starknet.io doc is incorrect). -pub fn calculate_class_hash(class: &ContractClass) -> ClassHash { +pub fn calculate_class_hash(class: &SierraContractClass) -> ClassHash { let external_entry_points_hash = entry_points_hash(class, &EntryPointType::External); let l1_handler_entry_points_hash = entry_points_hash(class, &EntryPointType::L1Handler); let constructor_entry_points_hash = entry_points_hash(class, &EntryPointType::Constructor); @@ -38,7 +38,10 @@ pub fn calculate_class_hash(class: &ContractClass) -> ClassHash { ClassHash(class_hash) } -fn entry_points_hash(class: &ContractClass, entry_point_type: &EntryPointType) -> PoseidonHash { +fn entry_points_hash( + class: &SierraContractClass, + entry_point_type: &EntryPointType, +) -> PoseidonHash { PoseidonHash(Poseidon::hash_array( class .entry_points_by_type diff --git a/crates/papyrus_common/src/class_hash_test.rs b/crates/papyrus_common/src/class_hash_test.rs index 84ac2ea4a27..29617bf22ea 100644 --- a/crates/papyrus_common/src/class_hash_test.rs +++ b/crates/papyrus_common/src/class_hash_test.rs @@ -1,12 +1,12 @@ use starknet_api::class_hash; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; use starknet_api::test_utils::read_json_file; use crate::class_hash::calculate_class_hash; #[test] fn class_hash() { - let class: ContractClass = serde_json::from_value(read_json_file("class.json")).unwrap(); + let class: SierraContractClass = serde_json::from_value(read_json_file("class.json")).unwrap(); let expected_class_hash = class_hash!("0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"); let calculated_class_hash = calculate_class_hash(&class); diff --git a/crates/papyrus_common/src/pending_classes.rs b/crates/papyrus_common/src/pending_classes.rs index 85abd49c6db..79de3849e84 100644 --- a/crates/papyrus_common/src/pending_classes.rs +++ b/crates/papyrus_common/src/pending_classes.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use starknet_api::core::ClassHash; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; pub trait PendingClassesTrait { // TODO(shahak) Return an Arc to avoid cloning the class. This requires to re-implement @@ -33,7 +33,7 @@ pub struct PendingClasses { #[derive(Debug, Eq, PartialEq, Clone)] pub enum ApiContractClass { DeprecatedContractClass(DeprecatedContractClass), - ContractClass(ContractClass), + ContractClass(SierraContractClass), } impl ApiContractClass { @@ -44,7 +44,7 @@ impl ApiContractClass { } } - pub fn into_cairo1(self) -> Option { + pub fn into_cairo1(self) -> Option { match self { Self::ContractClass(class) => Some(class), _ => None, diff --git a/crates/papyrus_execution/src/state_reader_test.rs b/crates/papyrus_execution/src/state_reader_test.rs index ce52a279ef6..ac16c98afa6 100644 --- a/crates/papyrus_execution/src/state_reader_test.rs +++ b/crates/papyrus_execution/src/state_reader_test.rs @@ -26,7 +26,7 @@ use papyrus_storage::test_utils::get_test_storage; use starknet_api::block::{BlockBody, BlockHash, BlockHeader, BlockHeaderWithoutHash, BlockNumber}; use starknet_api::core::{ClassHash, CompiledClassHash, Nonce}; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, StateNumber, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, ThinStateDiff}; use starknet_api::{contract_address, felt, storage_key}; use starknet_types_core::felt::Felt; @@ -47,7 +47,7 @@ fn read_state() { let storage_value0 = felt!(777_u128); let storage_value1 = felt!(888_u128); // The class is not used in the execution, so it can be default. - let class0 = ContractClass::default(); + let class0 = SierraContractClass::default(); let casm0 = get_test_casm(); let blockifier_casm0 = RunnableContractClass::V1(ContractClassV1::try_from(casm0.clone()).unwrap()); diff --git a/crates/papyrus_execution/src/test_utils.rs b/crates/papyrus_execution/src/test_utils.rs index 928a4abd265..861fc4b2316 100644 --- a/crates/papyrus_execution/src/test_utils.rs +++ b/crates/papyrus_execution/src/test_utils.rs @@ -30,7 +30,7 @@ use starknet_api::core::{ SequencerContractAddress, }; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::{ContractClass, StateNumber, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, ThinStateDiff}; use starknet_api::test_utils::read_json_file; use starknet_api::transaction::fields::Fee; use starknet_api::transaction::{ @@ -163,7 +163,7 @@ pub fn prepare_storage(mut storage_writer: StorageWriter) { .unwrap() .append_classes( BlockNumber(0), - &[(class_hash0, &ContractClass::default())], + &[(class_hash0, &SierraContractClass::default())], &[ (*TEST_ERC20_CONTRACT_CLASS_HASH, &get_test_erc20_fee_contract_class()), (class_hash1, &get_test_deprecated_contract_class()), diff --git a/crates/papyrus_p2p_sync/src/server/test.rs b/crates/papyrus_p2p_sync/src/server/test.rs index 01e324b5174..29f74535cf8 100644 --- a/crates/papyrus_p2p_sync/src/server/test.rs +++ b/crates/papyrus_p2p_sync/src/server/test.rs @@ -41,7 +41,7 @@ use starknet_api::block::{ BlockSignature, }; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; use starknet_api::transaction::{ Event, FullTransaction, @@ -491,7 +491,7 @@ lazy_static! { .into_iter() .flat_map(|tx_output| tx_output.into_iter().flat_map(|output| output.events().to_vec())) .collect(); - static ref CLASSES_WITH_HASHES: Vec> = { + static ref CLASSES_WITH_HASHES: Vec> = { THIN_STATE_DIFFS .iter() .map(|state_diff| { @@ -499,7 +499,7 @@ lazy_static! { .declared_classes .iter() .map(|(class_hash, _)| { - (*class_hash, ContractClass::get_test_instance(&mut get_rng())) + (*class_hash, SierraContractClass::get_test_instance(&mut get_rng())) }) .collect::>(); class_vec diff --git a/crates/papyrus_protobuf/src/converters/class.rs b/crates/papyrus_protobuf/src/converters/class.rs index 414ca5e43fa..770f2bdee9a 100644 --- a/crates/papyrus_protobuf/src/converters/class.rs +++ b/crates/papyrus_protobuf/src/converters/class.rs @@ -67,7 +67,7 @@ impl TryFrom for (ApiContractClass, ClassHash) { ) } Some(protobuf::class::Class::Cairo1(class)) => { - ApiContractClass::ContractClass(state::ContractClass::try_from(class)?) + ApiContractClass::ContractClass(state::SierraContractClass::try_from(class)?) } None => { return Err(ProtobufConversionError::MissingField { @@ -199,7 +199,7 @@ impl From for protobuf::Cairo0Class { } } -impl TryFrom for state::ContractClass { +impl TryFrom for state::SierraContractClass { type Error = ProtobufConversionError; fn try_from(value: protobuf::Cairo1Class) -> Result { let abi = value.abi; @@ -243,12 +243,12 @@ impl TryFrom for state::ContractClass { ); } - Ok(state::ContractClass { sierra_program, entry_points_by_type, abi }) + Ok(state::SierraContractClass { sierra_program, entry_points_by_type, abi }) } } -impl From for protobuf::Cairo1Class { - fn from(value: state::ContractClass) -> Self { +impl From for protobuf::Cairo1Class { + fn from(value: state::SierraContractClass) -> Self { let abi = value.abi; let program = diff --git a/crates/papyrus_rpc/src/v0_8/api/test.rs b/crates/papyrus_rpc/src/v0_8/api/test.rs index cc4871c0c31..54819a917f4 100644 --- a/crates/papyrus_rpc/src/v0_8/api/test.rs +++ b/crates/papyrus_rpc/src/v0_8/api/test.rs @@ -69,7 +69,7 @@ use starknet_api::deprecated_contract_class::{ FunctionStateMutability, }; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass as StarknetApiContractClass, StateDiff}; +use starknet_api::state::{SierraContractClass as StarknetApiContractClass, StateDiff}; use starknet_api::transaction::{ Event as StarknetApiEvent, EventContent, diff --git a/crates/papyrus_rpc/src/v0_8/execution_test.rs b/crates/papyrus_rpc/src/v0_8/execution_test.rs index 0d6ab94691b..6566ba0ad37 100644 --- a/crates/papyrus_rpc/src/v0_8/execution_test.rs +++ b/crates/papyrus_rpc/src/v0_8/execution_test.rs @@ -1561,7 +1561,7 @@ async fn write_block_0_as_pending( .unwrap(); let class_hash1 = class_hash!("0x1"); - let class2 = starknet_api::state::ContractClass::default(); + let class2 = starknet_api::state::SierraContractClass::default(); let casm = serde_json::from_value::(read_json_file("casm.json")).unwrap(); let class_hash2 = class_hash!("0x2"); let compiled_class_hash = CompiledClassHash(StarkHash::default()); @@ -1653,7 +1653,7 @@ fn prepare_storage_for_execution(mut storage_writer: StorageWriter) -> StorageWr .unwrap(); let class_hash1 = class_hash!("0x1"); - let class2 = starknet_api::state::ContractClass::default(); + let class2 = starknet_api::state::SierraContractClass::default(); let casm = serde_json::from_value::(read_json_file("casm.json")).unwrap(); let class_hash2 = class_hash!("0x2"); let compiled_class_hash = CompiledClassHash(StarkHash::default()); diff --git a/crates/papyrus_rpc/src/v0_8/state.rs b/crates/papyrus_rpc/src/v0_8/state.rs index f701b278f16..a50f705b235 100644 --- a/crates/papyrus_rpc/src/v0_8/state.rs +++ b/crates/papyrus_rpc/src/v0_8/state.rs @@ -214,8 +214,8 @@ pub struct ContractClass { pub abi: String, } -impl From for ContractClass { - fn from(class: starknet_api::state::ContractClass) -> Self { +impl From for ContractClass { + fn from(class: starknet_api::state::SierraContractClass) -> Self { Self { sierra_program: class.sierra_program, contract_class_version: CONTRACT_CLASS_VERSION.to_owned(), diff --git a/crates/papyrus_storage/src/class.rs b/crates/papyrus_storage/src/class.rs index ceede70b943..7245542e4d8 100644 --- a/crates/papyrus_storage/src/class.rs +++ b/crates/papyrus_storage/src/class.rs @@ -19,7 +19,7 @@ //! use starknet_api::core::{ClassHash, CompiledClassHash}; //! use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; //! use starknet_api::hash::StarkHash; -//! use starknet_api::state::{ContractClass, ThinStateDiff}; +//! use starknet_api::state::{SierraContractClass, ThinStateDiff}; //! //! # let dir_handle = tempfile::tempdir().unwrap(); //! # let dir = dir_handle.path().to_path_buf(); @@ -71,7 +71,7 @@ use papyrus_proc_macros::latency_histogram; use starknet_api::block::BlockNumber; use starknet_api::core::ClassHash; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; use crate::db::table_types::Table; use crate::db::{TransactionKind, RW}; @@ -90,7 +90,7 @@ use crate::{ /// Interface for reading data related to classes or deprecated classes. pub trait ClassStorageReader { /// Returns the Cairo 1 class with the given hash. - fn get_class(&self, class_hash: &ClassHash) -> StorageResult>; + fn get_class(&self, class_hash: &ClassHash) -> StorageResult>; /// Returns the Cairo 0 class with the given hash. fn get_deprecated_class( @@ -119,13 +119,13 @@ where fn append_classes( self, block_number: BlockNumber, - classes: &[(ClassHash, &ContractClass)], + classes: &[(ClassHash, &SierraContractClass)], deprecated_classes: &[(ClassHash, &DeprecatedContractClass)], ) -> StorageResult; } impl<'env, Mode: TransactionKind> ClassStorageReader for StorageTxn<'env, Mode> { - fn get_class(&self, class_hash: &ClassHash) -> StorageResult> { + fn get_class(&self, class_hash: &ClassHash) -> StorageResult> { let declared_classes_table = self.open_table(&self.tables.declared_classes)?; let contract_class_location = declared_classes_table.get(&self.txn, class_hash)?; contract_class_location @@ -159,7 +159,7 @@ impl<'env> ClassStorageWriter for StorageTxn<'env, RW> { fn append_classes( self, block_number: BlockNumber, - classes: &[(ClassHash, &ContractClass)], + classes: &[(ClassHash, &SierraContractClass)], deprecated_classes: &[(ClassHash, &DeprecatedContractClass)], ) -> StorageResult { let declared_classes_table = self.open_table(&self.tables.declared_classes)?; @@ -201,7 +201,7 @@ impl<'env> ClassStorageWriter for StorageTxn<'env, RW> { } fn write_classes<'env>( - classes: &[(ClassHash, &ContractClass)], + classes: &[(ClassHash, &SierraContractClass)], txn: &DbTransaction<'env, RW>, declared_classes_table: &'env DeclaredClassesTable<'env>, file_handlers: &FileHandlers, diff --git a/crates/papyrus_storage/src/class_test.rs b/crates/papyrus_storage/src/class_test.rs index 5bfb67744f1..8d569a78b0b 100644 --- a/crates/papyrus_storage/src/class_test.rs +++ b/crates/papyrus_storage/src/class_test.rs @@ -5,7 +5,7 @@ use starknet_api::block::BlockNumber; use starknet_api::core::{ClassHash, CompiledClassHash}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, StateNumber, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, ThinStateDiff}; use starknet_api::test_utils::read_json_file; use super::{ClassStorageReader, ClassStorageWriter}; @@ -16,7 +16,7 @@ use crate::StorageError; #[test] fn append_classes_writes_correct_data() { let class_json = read_json_file("class.json"); - let expected_class: ContractClass = serde_json::from_value(class_json).unwrap(); + let expected_class: SierraContractClass = serde_json::from_value(class_json).unwrap(); let deprecated_class_json = read_json_file("deprecated_class.json"); let expected_deprecated_class: DeprecatedContractClass = serde_json::from_value(deprecated_class_json).unwrap(); diff --git a/crates/papyrus_storage/src/lib.rs b/crates/papyrus_storage/src/lib.rs index a8f44558198..2cc0101272e 100644 --- a/crates/papyrus_storage/src/lib.rs +++ b/crates/papyrus_storage/src/lib.rs @@ -125,7 +125,7 @@ use serde::{Deserialize, Serialize}; use starknet_api::block::{BlockHash, BlockNumber, BlockSignature, StarknetVersion}; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::{ContractClass, StateNumber, StorageKey, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, StorageKey, ThinStateDiff}; use starknet_api::transaction::{Transaction, TransactionHash, TransactionOutput}; use starknet_types_core::felt::Felt; use tracing::{debug, warn}; @@ -666,7 +666,7 @@ pub(crate) type MarkersTable<'env> = #[derive(Clone, Debug)] struct FileHandlers { thin_state_diff: FileHandler, Mode>, - contract_class: FileHandler, Mode>, + contract_class: FileHandler, Mode>, casm: FileHandler, Mode>, deprecated_contract_class: FileHandler, Mode>, transaction_output: FileHandler, Mode>, @@ -681,7 +681,7 @@ impl FileHandlers { } // Appends a contract class to the corresponding file and returns its location. - fn append_contract_class(&self, contract_class: &ContractClass) -> LocationInFile { + fn append_contract_class(&self, contract_class: &SierraContractClass) -> LocationInFile { self.clone().contract_class.append(contract_class) } @@ -748,7 +748,7 @@ impl FileHandlers { fn get_contract_class_unchecked( &self, location: LocationInFile, - ) -> StorageResult { + ) -> StorageResult { self.contract_class.get(location)?.ok_or(StorageError::DBInconsistency { msg: format!("ContractClass at location {:?} not found.", location), }) diff --git a/crates/papyrus_storage/src/serialization/serializers.rs b/crates/papyrus_storage/src/serialization/serializers.rs index 972b5769b3c..d4dab673a5b 100644 --- a/crates/papyrus_storage/src/serialization/serializers.rs +++ b/crates/papyrus_storage/src/serialization/serializers.rs @@ -66,7 +66,13 @@ use starknet_api::deprecated_contract_class::{ }; use starknet_api::execution_resources::{Builtin, ExecutionResources, GasAmount, GasVector}; use starknet_api::hash::{PoseidonHash, StarkHash}; -use starknet_api::state::{ContractClass, EntryPoint, FunctionIndex, StorageKey, ThinStateDiff}; +use starknet_api::state::{ + EntryPoint, + FunctionIndex, + SierraContractClass, + StorageKey, + ThinStateDiff, +}; use starknet_api::transaction::fields::{ AccountDeploymentData, AllResourceBounds, @@ -960,7 +966,7 @@ impl StorageSerde for TransactionOffsetInBlock { //////////////////////////////////////////////////////////////////////// // Custom serialization with compression. //////////////////////////////////////////////////////////////////////// -impl StorageSerde for ContractClass { +impl StorageSerde for SierraContractClass { fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> { serialize_and_compress(&self.sierra_program)?.serialize_into(res)?; self.entry_points_by_type.serialize_into(res)?; @@ -981,7 +987,7 @@ impl StorageSerde for ContractClass { } } #[cfg(test)] -create_storage_serde_test!(ContractClass); +create_storage_serde_test!(SierraContractClass); impl StorageSerde for DeprecatedContractClass { fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> { diff --git a/crates/papyrus_storage/src/state/data.rs b/crates/papyrus_storage/src/state/data.rs index c1c922a488b..62ec32fddd5 100644 --- a/crates/papyrus_storage/src/state/data.rs +++ b/crates/papyrus_storage/src/state/data.rs @@ -2,11 +2,11 @@ use indexmap::IndexMap; use starknet_api::block::BlockNumber; use starknet_api::core::ClassHash; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::ContractClass; +use starknet_api::state::SierraContractClass; use crate::mmap_file::LocationInFile; -pub type DeclaredClasses = IndexMap; +pub type DeclaredClasses = IndexMap; pub type DeprecatedDeclaredClasses = IndexMap; /// Data structs that are serialized into the database. diff --git a/crates/papyrus_storage/src/state/mod.rs b/crates/papyrus_storage/src/state/mod.rs index 5a872c29ecb..023df4fe5b3 100644 --- a/crates/papyrus_storage/src/state/mod.rs +++ b/crates/papyrus_storage/src/state/mod.rs @@ -62,7 +62,7 @@ use papyrus_proc_macros::latency_histogram; use starknet_api::block::BlockNumber; use starknet_api::core::{ClassHash, ContractAddress, Nonce}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; -use starknet_api::state::{ContractClass, StateNumber, StorageKey, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, StorageKey, ThinStateDiff}; use starknet_types_core::felt::Felt; use tracing::debug; @@ -135,7 +135,7 @@ pub trait StateStorageReader { type RevertedStateDiff = ( ThinStateDiff, - IndexMap, + IndexMap, IndexMap, IndexMap, ); @@ -358,7 +358,7 @@ impl<'env, Mode: TransactionKind> StateReader<'env, Mode> { &self, state_number: StateNumber, class_hash: &ClassHash, - ) -> StorageResult> { + ) -> StorageResult> { let Some(block_number) = self.declared_classes_block_table.get(self.txn, class_hash)? else { return Ok(None); @@ -706,7 +706,7 @@ fn delete_declared_classes<'env>( declared_classes_table: &'env DeclaredClassesTable<'env>, declared_classes_block_table: &'env DeclaredClassesBlockTable<'env>, file_handlers: &FileHandlers, -) -> StorageResult> { +) -> StorageResult> { let mut deleted_data = IndexMap::new(); for class_hash in thin_state_diff.declared_classes.keys() { let Some(contract_class_location) = declared_classes_table.get(txn, class_hash)? else { diff --git a/crates/papyrus_storage/src/state/state_test.rs b/crates/papyrus_storage/src/state/state_test.rs index 1dd45670d0a..3f82f82f0ff 100644 --- a/crates/papyrus_storage/src/state/state_test.rs +++ b/crates/papyrus_storage/src/state/state_test.rs @@ -7,7 +7,7 @@ use starknet_api::block::BlockNumber; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, StateNumber, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, StateNumber, ThinStateDiff}; use starknet_api::{class_hash, contract_address, felt, storage_key}; use starknet_types_core::felt::Felt; @@ -26,7 +26,7 @@ fn get_class_definition_at() { // New classes. let nc0 = class_hash!("0x10"); let nc1 = class_hash!("0x11"); - let new_class = ContractClass::default(); + let new_class = SierraContractClass::default(); let compiled_class_hash = CompiledClassHash::default(); let diff0 = ThinStateDiff { deprecated_declared_classes: vec![dc0, dc1], @@ -496,7 +496,7 @@ fn revert_state() { .unwrap() .append_classes( BlockNumber(1), - &[(class2, &ContractClass::default())], + &[(class2, &SierraContractClass::default())], &[(class1, &DeprecatedContractClass::default())], ) .unwrap() @@ -528,7 +528,7 @@ fn revert_state() { let expected_deleted_deprecated_classes = IndexMap::from([(class1, DeprecatedContractClass::default())]); - let expected_deleted_classes = IndexMap::from([(class2, ContractClass::default())]); + let expected_deleted_classes = IndexMap::from([(class2, SierraContractClass::default())]); let expected_deleted_compiled_classes = IndexMap::from([( class2, CasmContractClass { @@ -711,7 +711,7 @@ fn declare_revert_declare_scenario() { let deprecated_class_hash = class_hash!("0xc1a55"); let class_hash = class_hash!("0xdec1a55"); let deprecated_class = DeprecatedContractClass::default(); - let class = ContractClass::default(); + let class = SierraContractClass::default(); let compiled_class_hash = CompiledClassHash::default(); let diff0 = ThinStateDiff { deployed_contracts: IndexMap::from([(contract_address, deprecated_class_hash)]), diff --git a/crates/papyrus_storage/src/utils_test.rs b/crates/papyrus_storage/src/utils_test.rs index 92ef71f12ee..157e2e7efd9 100644 --- a/crates/papyrus_storage/src/utils_test.rs +++ b/crates/papyrus_storage/src/utils_test.rs @@ -9,7 +9,7 @@ use prometheus_parse::Value::{Counter, Gauge}; use starknet_api::block::BlockNumber; use starknet_api::core::{ClassHash, CompiledClassHash}; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, ThinStateDiff}; +use starknet_api::state::{SierraContractClass, ThinStateDiff}; use starknet_types_core::felt::Felt; use super::update_storage_metrics; @@ -30,7 +30,7 @@ fn test_dump_declared_classes() { let i_felt = Felt::from(u128::try_from(i).expect("usize should fit in u128")); declared_classes.push(( ClassHash(i_felt), - ContractClass { + SierraContractClass { sierra_program: vec![i_felt, i_felt], entry_points_by_type: HashMap::new(), abi: "".to_string(), diff --git a/crates/papyrus_sync/src/sources/central_test.rs b/crates/papyrus_sync/src/sources/central_test.rs index 5580d2683cc..c8c593ee10d 100644 --- a/crates/papyrus_sync/src/sources/central_test.rs +++ b/crates/papyrus_sync/src/sources/central_test.rs @@ -17,7 +17,7 @@ use starknet_api::core::{ClassHash, CompiledClassHash, GlobalRoot, Nonce, Sequen use starknet_api::crypto::utils::PublicKey; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass as sn_api_ContractClass, ThinStateDiff}; +use starknet_api::state::{SierraContractClass as sn_api_ContractClass, ThinStateDiff}; use starknet_api::{class_hash, contract_address, felt, storage_key}; use starknet_client::reader::objects::block::BlockPostV0_13_1; use starknet_client::reader::{ @@ -424,11 +424,17 @@ async fn stream_state_updates() { IndexMap::from([ ( new_class_hash1, - (compiled_class_hash1, starknet_api::state::ContractClass::from(contract_class1)) + ( + compiled_class_hash1, + starknet_api::state::SierraContractClass::from(contract_class1) + ) ), ( new_class_hash2, - (compiled_class_hash2, starknet_api::state::ContractClass::from(contract_class2)) + ( + compiled_class_hash2, + starknet_api::state::SierraContractClass::from(contract_class2) + ) ), ]), state_diff.declared_classes, diff --git a/crates/papyrus_sync/src/sync_test.rs b/crates/papyrus_sync/src/sync_test.rs index 20a813a3827..7a2796d2f0d 100644 --- a/crates/papyrus_sync/src/sync_test.rs +++ b/crates/papyrus_sync/src/sync_test.rs @@ -16,7 +16,7 @@ use starknet_api::block::{BlockHash, BlockHeader, BlockHeaderWithoutHash, BlockN use starknet_api::core::{ClassHash, CompiledClassHash, Nonce}; use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; use starknet_api::hash::StarkHash; -use starknet_api::state::{ContractClass, StateDiff}; +use starknet_api::state::{SierraContractClass, StateDiff}; use starknet_api::{contract_address, felt, storage_key}; use starknet_client::reader::objects::pending_data::{ AcceptedOnL2ExtraData, @@ -57,9 +57,9 @@ fn state_sorted() { let storage_key_0 = storage_key!("0x0"); let storage_key_1 = storage_key!("0x1"); let declare_class_0 = - (ClassHash(hash0), (CompiledClassHash::default(), ContractClass::default())); + (ClassHash(hash0), (CompiledClassHash::default(), SierraContractClass::default())); let declare_class_1 = - (ClassHash(hash1), (CompiledClassHash::default(), ContractClass::default())); + (ClassHash(hash1), (CompiledClassHash::default(), SierraContractClass::default())); let deprecated_declared_0 = (ClassHash(hash0), DeprecatedContractClass::default()); let deprecated_declared_1 = (ClassHash(hash1), DeprecatedContractClass::default()); let nonce_0 = (contract_address_0, Nonce(hash0)); @@ -676,7 +676,8 @@ async fn pending_sync_classes_request_only_new_classes() { let first_class = ApiContractClass::DeprecatedContractClass( DeprecatedContractClass::get_test_instance(&mut rng), ); - let second_class = ApiContractClass::ContractClass(ContractClass::get_test_instance(&mut rng)); + let second_class = + ApiContractClass::ContractClass(SierraContractClass::get_test_instance(&mut rng)); let compiled_class = CasmContractClass::get_test_instance(&mut rng); let mut expected_pending_classes = PendingClasses::default(); diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index b00d2a15cfc..358f1c18017 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -99,9 +99,9 @@ use starknet_api::rpc_transaction::{ RpcTransaction, }; use starknet_api::state::{ - ContractClass, EntryPoint, FunctionIndex, + SierraContractClass, StateDiff, StorageKey, ThinStateDiff, @@ -496,7 +496,7 @@ auto_impl_get_test_instance! { pub struct ClassHash(pub StarkHash); pub struct CompiledClassHash(pub StarkHash); pub struct ContractAddressSalt(pub StarkHash); - pub struct ContractClass { + pub struct SierraContractClass { pub sierra_program: Vec, pub entry_points_by_type: HashMap>, pub abi: String, @@ -817,7 +817,7 @@ auto_impl_get_test_instance! { pub struct StateDiff { pub deployed_contracts: IndexMap, pub storage_diffs: IndexMap>, - pub declared_classes: IndexMap, + pub declared_classes: IndexMap, pub deprecated_declared_classes: IndexMap, pub nonces: IndexMap, pub replaced_classes: IndexMap, @@ -920,7 +920,7 @@ auto_impl_get_test_instance! { (ContractAddress, Nonce); (ContractAddress, StorageKey, BlockHash); (ContractAddress, StorageKey, BlockNumber); - (CompiledClassHash, ContractClass); + (CompiledClassHash, SierraContractClass); (usize, Vec); (usize, Vec); } diff --git a/crates/starknet_api/src/state.rs b/crates/starknet_api/src/state.rs index 289ce13663b..e0e37067a02 100644 --- a/crates/starknet_api/src/state.rs +++ b/crates/starknet_api/src/state.rs @@ -24,7 +24,7 @@ use crate::deprecated_contract_class::ContractClass as DeprecatedContractClass; use crate::hash::StarkHash; use crate::{impl_from_through_intermediate, StarknetApiError}; -pub type DeclaredClasses = IndexMap; +pub type DeclaredClasses = IndexMap; pub type DeprecatedDeclaredClasses = IndexMap; /// The differences between two states before and after a block with hash block_hash @@ -45,7 +45,7 @@ pub struct StateUpdate { pub struct StateDiff { pub deployed_contracts: IndexMap, pub storage_diffs: IndexMap>, - pub declared_classes: IndexMap, + pub declared_classes: IndexMap, pub deprecated_declared_classes: IndexMap, pub nonces: IndexMap, pub replaced_classes: IndexMap, @@ -211,7 +211,7 @@ impl_from_through_intermediate!(u128, StorageKey, u8, u16, u32, u64); /// A contract class. #[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] -pub struct ContractClass { +pub struct SierraContractClass { pub sierra_program: Vec, pub entry_points_by_type: HashMap>, pub abi: String, diff --git a/crates/starknet_client/src/reader/objects/state.rs b/crates/starknet_client/src/reader/objects/state.rs index 0a22ec272e4..67ad35b75b0 100644 --- a/crates/starknet_client/src/reader/objects/state.rs +++ b/crates/starknet_client/src/reader/objects/state.rs @@ -63,7 +63,7 @@ pub struct ContractClass { pub abi: String, } -impl From for starknet_api::state::ContractClass { +impl From for starknet_api::state::SierraContractClass { fn from(class: ContractClass) -> Self { Self { sierra_program: class.sierra_program,