From 2356a367dc313cabcf9af63e9f9598655445100b Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 20 Sep 2024 15:16:48 +0200 Subject: [PATCH] native cache mechanism --- Cargo.lock | 63 ++++- Cargo.toml | 2 + crates/ef-testing/Cargo.toml | 1 + .../ef-testing/src/evm_sequencer/constants.rs | 26 ++ .../src/evm_sequencer/sequencer/mod.rs | 31 ++- crates/sequencer/Cargo.toml | 7 + crates/sequencer/src/lib.rs | 1 + crates/sequencer/src/native.rs | 251 ++++++++++++++++++ crates/sequencer/src/state.rs | 9 +- 9 files changed, 369 insertions(+), 22 deletions(-) create mode 100644 crates/sequencer/src/native.rs diff --git a/Cargo.lock b/Cargo.lock index f0417967..49e4b7a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1108,7 +1108,7 @@ dependencies = [ "ark-ff 0.4.2", "ark-secp256k1", "ark-secp256r1", - "cached", + "cached 0.44.0", "cairo-lang-casm", "cairo-lang-runner", "cairo-lang-sierra", @@ -1268,7 +1268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b195e4fbc4b6862bbd065b991a34750399c119797efff72492f28a5864de8700" dependencies = [ "async-trait", - "cached_proc_macro", + "cached_proc_macro 0.17.0", "cached_proc_macro_types", "futures", "hashbrown 0.13.2", @@ -1278,6 +1278,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "cached" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d73155ae6b28cf5de4cfc29aeb02b8a1c6dab883cb015d15cd514e42766846" +dependencies = [ + "ahash", + "cached_proc_macro 0.23.0", + "cached_proc_macro_types", + "hashbrown 0.14.5", + "once_cell", + "thiserror", + "web-time", +] + [[package]] name = "cached_proc_macro" version = "0.17.0" @@ -1291,6 +1306,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cached_proc_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f42a145ed2d10dce2191e1dcf30cfccfea9026660e143662ba5eec4017d5daa" +dependencies = [ + "darling 0.20.10", + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "cached_proc_macro_types" version = "0.1.1" @@ -1818,7 +1845,6 @@ dependencies = [ [[package]] name = "cairo-native" version = "0.2.0" -source = "git+https://github.com/enitrat/cairo_native?rev=8e8771d9a7a7b1d3948eebaf6af4022a3fc66701#8e8771d9a7a7b1d3948eebaf6af4022a3fc66701" dependencies = [ "anyhow", "aquamarine", @@ -1855,6 +1881,8 @@ dependencies = [ "num-traits 0.2.19", "p256", "sec1", + "serde", + "serde_json", "sha2 0.10.8", "starknet-types-core", "stats_alloc", @@ -1862,18 +1890,17 @@ dependencies = [ "thiserror", "tracing", "tracing-subscriber", + "utf8_iter", ] [[package]] name = "cairo-native-runtime" version = "0.2.0" -source = "git+https://github.com/enitrat/cairo_native?rev=8e8771d9a7a7b1d3948eebaf6af4022a3fc66701#8e8771d9a7a7b1d3948eebaf6af4022a3fc66701" dependencies = [ "cairo-lang-sierra-gas", "lazy_static", "libc", "rand 0.8.5", - "starknet-crypto 0.7.1", "starknet-curve 0.5.0", "starknet-types-core", ] @@ -4420,9 +4447,9 @@ checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -8045,9 +8072,15 @@ name = "sequencer" version = "0.1.0" dependencies = [ "blockifier", + "cached 0.53.1", + "cairo-lang-sierra", + "cairo-lang-starknet-classes", + "cairo-native", "eyre", "hashbrown 0.14.5", "lazy_static", + "libloading", + "once_cell", "serde", "serde_json", "starknet", @@ -9517,6 +9550,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -9720,6 +9759,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" version = "0.25.4" diff --git a/Cargo.toml b/Cargo.toml index 86c1e5cc..1922c353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,8 @@ cairo-lang-casm = "2.8.0" cairo-lang-starknet = "2.8.0" cairo-lang-utils = "2.8.0" cairo-lang-starknet-classes = "2.8.0" +cairo-lang-sierra = "2.8.0" +cairo-native = {path = "/Users/msaug/deps/cairo_native"} cairo-vm = "1.0.1" blockifier = { package = "blockifier", path = "../../deps/sequencer/crates/blockifier", default-features = false, features = [ "testing", diff --git a/crates/ef-testing/Cargo.toml b/crates/ef-testing/Cargo.toml index d992bd00..6b33f421 100644 --- a/crates/ef-testing/Cargo.toml +++ b/crates/ef-testing/Cargo.toml @@ -59,6 +59,7 @@ zip = { workspace = true, optional = true } [features] v0 = [] v1 = [] +native = [] ci = [] [build-dependencies] diff --git a/crates/ef-testing/src/evm_sequencer/constants.rs b/crates/ef-testing/src/evm_sequencer/constants.rs index 753cf37b..ee48ce5f 100644 --- a/crates/ef-testing/src/evm_sequencer/constants.rs +++ b/crates/ef-testing/src/evm_sequencer/constants.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fs; use lazy_static::lazy_static; use reth_primitives::alloy_primitives::{address, Address}; @@ -21,6 +22,13 @@ where serde_json::from_str::(&std::fs::read_to_string(path)?).map_err(eyre::Error::from) } + +pub fn get_raw_contract_class(contract_path: &str) -> String { + println!("path: {:?}", contract_path); + fs::read_to_string(contract_path).unwrap() +} + + // Chain params pub const CHAIN_ID: u64 = 0x4b4b5254; @@ -89,11 +97,23 @@ lazy_static! { pub static ref ACCOUNT_CONTRACT_CLASS: CompiledClass = load_contract_class("../../build/v1/contracts_AccountContract.compiled_contract_class.json").expect("Failed to load ContractAccount contract class"); pub static ref UNINITIALIZED_ACCOUNT_CLASS: CompiledClass = load_contract_class("../../build/v1/contracts_UninitializedAccount.compiled_contract_class.json").expect("Failed to load uninitialized account contract class"); + pub static ref KAKAROT_JSON_CLASS: String = get_raw_contract_class("../../build/v1/contracts_KakarotCore.contract_class.json"); + pub static ref ACCOUNT_CONTRACT_JSON_CLASS: String = get_raw_contract_class("../../build/v1/contracts_AccountContract.contract_class.json"); + pub static ref UNINITIALIZED_ACCOUNT_JSON_CLASS: String = get_raw_contract_class("../../build/v1/contracts_UninitializedAccount.contract_class.json"); + // Main class hashes pub static ref KAKAROT_CLASS_HASH: ClassHash = ClassHash(KAKAROT_CLASS.class_hash().unwrap()); pub static ref ACCOUNT_CONTRACT_CLASS_HASH: ClassHash = ClassHash(ACCOUNT_CONTRACT_CLASS.class_hash().unwrap()); pub static ref UNINITIALIZED_ACCOUNT_CLASS_HASH: ClassHash = ClassHash(UNINITIALIZED_ACCOUNT_CLASS.class_hash().unwrap()); pub static ref PROXY_CLASS_HASH: ClassHash = *UNINITIALIZED_ACCOUNT_CLASS_HASH; + + pub static ref CLASS_HASH_TO_JSON_CLASS: HashMap = { + let mut map = HashMap::new(); + map.insert(*KAKAROT_CLASS_HASH, KAKAROT_JSON_CLASS.clone()); + map.insert(*ACCOUNT_CONTRACT_CLASS_HASH, ACCOUNT_CONTRACT_JSON_CLASS.clone()); + map.insert(*UNINITIALIZED_ACCOUNT_CLASS_HASH, UNINITIALIZED_ACCOUNT_JSON_CLASS.clone()); + map + }; } #[cfg(not(any(feature = "v0", feature = "v1")))] @@ -114,6 +134,12 @@ lazy_static! { panic!("Kakarot class hash not defined, use features flag \"v0\" or \"v1\""); pub static ref UNINITIALIZED_ACCOUNT_CLASS: LegacyContractClass = panic!("Uninitialized account class not defined, use features flag \"v0\" or \"v1\""); + + pub static ref KAKAROT_JSON_CLASS: String = panic!("Kakarot json class not defined, use features flag \"v0\" or \"v1\""); + pub static ref ACCOUNT_CONTRACT_JSON_CLASS: String = panic!("Account contract json class not defined, use features flag \"v0\" or \"v1\""); + pub static ref UNINITIALIZED_ACCOUNT_JSON_CLASS: String = panic!("Uninitialized account json class not defined, use features flag \"v0\" or \"v1\""); + + pub static ref CLASS_HASH_TO_JSON_CLASS: HashMap = HashMap::new(); } pub mod storage_variables { diff --git a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs index 4e6ab53a..13eb16af 100644 --- a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs @@ -13,7 +13,7 @@ use crate::evm_sequencer::{ ETH_FEE_TOKEN_ADDRESS, FEE_TOKEN_CLASS, FEE_TOKEN_CLASS_HASH, KAKAROT_ADDRESS, KAKAROT_CLASS, KAKAROT_CLASS_HASH, KAKAROT_OWNER_ADDRESS, OPENZEPPELIN_ACCOUNT_CLASS, OPENZEPPELIN_ACCOUNT_CLASS_HASH, RELAYER_ADDRESS, RELAYER_BALANCE, RELAYER_VERIFYING_KEY, - STRK_FEE_TOKEN_ADDRESS, UNINITIALIZED_ACCOUNT_CLASS, UNINITIALIZED_ACCOUNT_CLASS_HASH, + STRK_FEE_TOKEN_ADDRESS, UNINITIALIZED_ACCOUNT_CLASS, UNINITIALIZED_ACCOUNT_CLASS_HASH, CLASS_HASH_TO_JSON_CLASS }, types::contract_class::CasmContractClassWrapper, utils::compute_starknet_address, @@ -29,7 +29,7 @@ use blockifier::{ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; use cairo_vm::types::errors::program_errors::ProgramError; use reth_primitives::Address; -use sequencer::{sequencer::Sequencer, state::State}; +use sequencer::{native::class_info_from_json_str, sequencer::Sequencer, state::State}; use starknet::core::types::contract::{legacy::LegacyContractClass, CompiledClass}; use starknet_api::{ block::{BlockNumber, BlockTimestamp}, @@ -231,30 +231,43 @@ lazy_static! { convert_contract_class_v0(&UNINITIALIZED_ACCOUNT_CLASS).expect("failed to convert uninitialized class") ) } + #[cfg(feature = "v1")] { + #[cfg(feature = "native")] + { + let account_json = CLASS_HASH_TO_JSON_CLASS.get(&ACCOUNT_CONTRACT_CLASS_HASH).unwrap(); + let kakarot_json = CLASS_HASH_TO_JSON_CLASS.get(&KAKAROT_CLASS_HASH).unwrap(); + let uninitialized_json = CLASS_HASH_TO_JSON_CLASS.get(&UNINITIALIZED_ACCOUNT_CLASS_HASH).unwrap(); + println!("Got account's json of length {}", account_json.len()); + println!("Got kakarot's json of length {}", kakarot_json.len()); + println!("Got uninitialized's json of length {}", uninitialized_json.len()); + let account_class_info = class_info_from_json_str(account_json, *ACCOUNT_CONTRACT_CLASS_HASH).unwrap(); + let kakarot_class_info = class_info_from_json_str(kakarot_json, *KAKAROT_CLASS_HASH).unwrap(); + let uninitialized_class_info = class_info_from_json_str(uninitialized_json, *UNINITIALIZED_ACCOUNT_CLASS_HASH).unwrap(); + println!("Got class info"); + (account_class_info.contract_class(), kakarot_class_info.contract_class(), uninitialized_class_info.contract_class()) + } + #[cfg(not(feature = "native"))] + { ( convert_contract_class_v1(&KAKAROT_CLASS).expect("failed to convert kakarot class"), convert_contract_class_v1(&ACCOUNT_CONTRACT_CLASS).expect("failed to convert account class"), convert_contract_class_v1(&UNINITIALIZED_ACCOUNT_CLASS).expect("failed to convert uninitialized class") ) + } } }; - let acc_class = ContractClass::V1Native(NativeContractClassV1::from_file("../../../../kkrt-labs/ef-tests/build/v1/contracts_AccountContract.contract_class.json")); - let kakarot_class = ContractClass::V1Native(NativeContractClassV1::from_file("../../../../kkrt-labs/ef-tests/build/v1/contracts_KakarotCore.contract_class.json")); - println!("Using kakarot native contract class"); - // Write the kakarot class and class hash. (&mut state).set_class_hash_at(*KAKAROT_ADDRESS, *KAKAROT_CLASS_HASH).expect("failed to set kakarot class hash"); (&mut state) - .set_contract_class(*KAKAROT_CLASS_HASH, kakarot_class).expect("failed to set kakarot contract class"); + .set_contract_class(*KAKAROT_CLASS_HASH, converted_kakarot_class).expect("failed to set kakarot contract class"); // Write contract account, uninitialized_account and erc20 classes and class hashes. (&mut state).set_contract_class( *ACCOUNT_CONTRACT_CLASS_HASH, - acc_class, - ).expect("failed to set contract account class"); + converted_account_class).expect("failed to set contract account class"); (&mut state) .set_contract_class(*UNINITIALIZED_ACCOUNT_CLASS_HASH, converted_uninitialized_class).expect("failed to set eoa contract class"); diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index b03c846e..2a1003ed 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -16,12 +16,19 @@ serde = { workspace = true } serde_json = { workspace = true } starknet_api = { workspace = true } starknet = { workspace = true } +cairo-lang-sierra = { workspace = true } +cairo-native = { workspace = true } +cairo-lang-starknet-classes = { workspace = true } # Other eyre = { workspace = true } tracing = { workspace = true } thiserror = { workspace = true } hashbrown = { workspace = true } +cached = "0.53.1" +once_cell = "1.19.0" +libloading = "0.8.5" +lazy_static.workspace = true [dev-dependencies] lazy_static = { workspace = true } diff --git a/crates/sequencer/src/lib.rs b/crates/sequencer/src/lib.rs index 0731f789..11ee62b9 100644 --- a/crates/sequencer/src/lib.rs +++ b/crates/sequencer/src/lib.rs @@ -5,3 +5,4 @@ pub mod sequencer; pub mod serde; pub mod state; pub mod transaction; +pub mod native; diff --git a/crates/sequencer/src/native.rs b/crates/sequencer/src/native.rs new file mode 100644 index 00000000..48e584cf --- /dev/null +++ b/crates/sequencer/src/native.rs @@ -0,0 +1,251 @@ +use blockifier::execution::contract_class::NativeContractClassV1; +use blockifier::{ + execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1}, + state::state_api::StateResult, +}; +use blockifier::{ + execution::contract_class::{ + ClassInfo as BlockifierClassInfo}, +}; +use cairo_native::{ + context::NativeContext, error::Error as NativeError, executor::AotNativeExecutor, + metadata::gas::GasMetadata, module::NativeModule, +}; +use libloading::Library; +use starknet_api::core::ClassHash; +use serde::Deserialize; + +use std::{ + ffi::{c_char, c_uchar, c_void, CStr}, + fs, + path::PathBuf, + slice, + sync::Mutex, +}; +use cached::{Cached, SizedCache}; +use once_cell::sync::Lazy; +use lazy_static::lazy_static; + +use cairo_lang_sierra::{program::Program, program_registry::ProgramRegistry}; +use hashbrown::HashMap; +struct CachedContractClass { + pub definition: ContractClass, + pub cached_on_height: u64, +} + + +lazy_static! { + static ref NATIVE_CACHE_DIR: PathBuf = setup_native_cache_dir(); +} + + +static CLASS_CACHE: Lazy>> = + Lazy::new(|| Mutex::new(SizedCache::with_size(128))); + + +/// Convenience function to construct a NativeContractClassV1 from a raw contract class. +/// If control over the compilation is desired use [Self::new] instead. +pub fn try_from_json_string( + raw_contract_class: &str, +) -> Result> { + // Compile the Sierra Program to native code and loads it into the process' + // memory space. + fn compile_and_load( + sierra_program: &cairo_lang_sierra::program::Program, + ) -> Result { + let native_context = cairo_native::context::NativeContext::new(); + println!("Started context, compiling..."); + let native_program = native_context.compile(sierra_program, true)?; + println!("Compiled, creating executor..."); + Ok(AotNativeExecutor::from_native_module( + native_program, + cairo_native::OptLevel::Default, + )) + } + + let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass = + serde_json::from_str(raw_contract_class)?; + + // todo(rodro): we are having two instances of a sierra program, one it's object form + // and another in its felt encoded form. This can be avoided by either: + // 1. Having access to the encoding/decoding functions + // 2. Refactoring the code on the Cairo mono-repo + + let sierra_program = sierra_contract_class.extract_sierra_program()?; + println!("Extracted sierra program"); + let executor = compile_and_load(&sierra_program)?; + println!("Executor created"); + + Ok(NativeContractClassV1::new(executor, sierra_contract_class)?) +} + +fn generate_library_path(class_hash: ClassHash) -> PathBuf { + let mut path = NATIVE_CACHE_DIR.clone(); + path.push(class_hash.to_string().trim_start_matches("0x")); + path +} + +/// Compiles and load contract +/// +/// Modelled after [AotNativeExecutor::from_native_module]. +/// Needs a sierra_program to workaround limitations of NativeModule +fn persist_from_native_module( + mut native_module: NativeModule, + sierra_program: &Program, + library_output_path: &PathBuf, +) -> Result> { + let object_data = cairo_native::module_to_object(native_module.module(), Default::default()) + .map_err(|err| NativeError::LLVMCompileError(err.to_string()))?; // cairo native didn't include a from instance + + cairo_native::object_to_shared_lib(&object_data, library_output_path)?; + + let gas_metadata = native_module + .remove_metadata() + .expect("native_module should have set gas_metadata"); + + // Recreate the program registry as it can't be moved out of native module. + let program_registry = ProgramRegistry::new(sierra_program)?; + + let library = unsafe { Library::new(library_output_path)? }; + + Ok(AotNativeExecutor::new( + library, + program_registry, + gas_metadata, + )) +} + +fn setup_native_cache_dir() -> PathBuf { + let mut path: PathBuf = match std::env::var("NATIVE_CACHE_DIR") { + Ok(path) => path.into(), + Err(_err) => { + let mut path = std::env::current_dir().unwrap(); + path.push("native_cache"); + path + } + }; + let _ = fs::create_dir_all(&path); + path +} + + +/// Load a contract that is already compiled. +/// +/// Returns None if the contract does not exist at the output_path. +/// +/// To compile and load a contract use [persist_from_native_module] instead. +fn load_compiled_contract( + sierra_program: &Program, + library_output_path: &PathBuf, +) -> Option>> { + fn load( + sierra_program: &Program, + library_output_path: &PathBuf, + ) -> Result> { + let has_gas_builtin = sierra_program + .type_declarations + .iter() + .any(|decl| decl.long_id.generic_id.0.as_str() == "GasBuiltin"); + let config = has_gas_builtin.then_some(Default::default()); + let gas_metadata = GasMetadata::new(sierra_program, config)?; + let program_registry = ProgramRegistry::new(sierra_program)?; + let library = unsafe { Library::new(library_output_path)? }; + Ok(AotNativeExecutor::new( + library, + program_registry, + gas_metadata, + )) + } + + library_output_path + .is_file() + .then_some(load(sierra_program, library_output_path)) +} + +/// Compiled Native contracts + +/// Load a compiled native contract into memory +/// +/// Tries to load the compiled contract class from library_output_path if it +/// exists, otherwise it will compile the raw_contract_class, load it into memory +/// and save the compilation artifact to library_output_path. +fn native_try_from_json_string( + raw_contract_class: &str, + library_output_path: &PathBuf, +) -> Result> { + fn compile_and_load( + sierra_program: Program, + library_output_path: &PathBuf, + ) -> Result> { + let native_context = NativeContext::new(); + let native_module = native_context.compile(&sierra_program, true)?; + + persist_from_native_module(native_module, &sierra_program, library_output_path) + } + + let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass = + serde_json::from_str(raw_contract_class)?; + + // todo(rodro): we are having two instances of a sierra program, one it's object form + // and another in its felt encoded form. This can be avoided by either: + // 1. Having access to the encoding/decoding functions + // 2. Refactoring the code on the Cairo mono-repo + + let sierra_program = sierra_contract_class.extract_sierra_program()?; + + // todo(xrvdg) lift this match out of the function once we do not need sierra_program anymore + let executor = match load_compiled_contract(&sierra_program, library_output_path) { + Some(executor) => { + println!("Loaded cached compiled contract from {:?}", library_output_path); + executor.or_else(|_err| compile_and_load(sierra_program, library_output_path)) + } + None => { + println!("No cached compiled contract, compiling..."); + compile_and_load(sierra_program, library_output_path) + }, + }?; + + Ok(NativeContractClassV1::new(executor, sierra_contract_class)?) +} + + +#[derive(Deserialize)] +pub struct ClassInfo { + contract_class: Box, + sierra_program_length: usize, + abi_length: usize, +} + + +pub fn class_info_from_json_str( + raw_json: &str, + class_hash: ClassHash, +) -> Result { + println!("raw json length {}", raw_json.len()); + let class_def = raw_json.to_string(); + println!("class def parsed"); + + // todo(xrvdg) Don't throw away errors + let class: ContractClass = + if let Ok(class) = ContractClassV0::try_from_json_string(class_def.as_str()) { + class.into() + } else if let Ok(class) = ContractClassV1::try_from_json_string(class_def.as_str()) { + println!("v1 contract"); + class.into() + } else if let Ok(class) = { + println!("native contract"); + let library_output_path = generate_library_path(class_hash); + native_try_from_json_string(class_def.as_str(), &library_output_path) + } { + class.into() + } else { + return Err("not a valid contract class".to_string()); + }; + + BlockifierClassInfo::new( + &class, + 100, //dummy value + 100 // dummy value + ) + .map_err(|err| err.to_string()) +} diff --git a/crates/sequencer/src/state.rs b/crates/sequencer/src/state.rs index 5eb6d00b..cea4bf99 100644 --- a/crates/sequencer/src/state.rs +++ b/crates/sequencer/src/state.rs @@ -1,6 +1,6 @@ use crate::commit::Committer; use crate::serde::SerializableState; -use blockifier::execution::contract_class::ContractClass; +use blockifier::execution::contract_class::{ContractClass, NativeContractClassV1}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{ State as BlockifierState, StateReader as BlockifierStateReader, StateResult, @@ -174,11 +174,6 @@ impl BlockifierStateReader for &mut State { .get(&class_hash) .cloned() .ok_or_else(|| StateError::UndeclaredClassHash(class_hash))?; - match res { - ContractClass::V0(_) => println!("V0"), - ContractClass::V1(_) => println!("V1"), - ContractClass::V1Native(_) => println!("V1Native"), - } Ok(res) } @@ -193,6 +188,8 @@ impl BlockifierStateReader for &mut State { } } + + #[cfg(test)] mod tests { use blockifier::execution::contract_class::ContractClassV0;