From dfb9e29b1b3745a6370ef6c9fdcb1e41add05ebb Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Mon, 14 Oct 2024 10:21:20 +0300 Subject: [PATCH] refactor(execution): delete starknet version string constants and usages --- .../papyrus_execution/src/execution_test.rs | 8 ++--- crates/papyrus_execution/src/lib.rs | 35 +++---------------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/crates/papyrus_execution/src/execution_test.rs b/crates/papyrus_execution/src/execution_test.rs index f3d2605bc9..fa4d71b60b 100644 --- a/crates/papyrus_execution/src/execution_test.rs +++ b/crates/papyrus_execution/src/execution_test.rs @@ -8,6 +8,7 @@ use blockifier::execution::call_info::Retdata; use blockifier::execution::errors::ConstructorEntryPointExecutionError; use blockifier::execution::stack_trace::gen_tx_execution_error_trace; use blockifier::transaction::errors::TransactionExecutionError as BlockifierTransactionExecutionError; +use blockifier::versioned_constants::VersionedConstants; use indexmap::indexmap; use papyrus_storage::test_utils::get_test_storage; use pretty_assertions::assert_eq; @@ -56,7 +57,6 @@ use crate::testing_instances::get_test_execution_config; use crate::{ estimate_fee, execute_call, - get_versioned_constants, ExecutableTransactionInput, ExecutionError, FeeEstimationResult, @@ -853,10 +853,10 @@ fn test_get_versioned_constants() { let starknet_version_13_0 = StarknetVersion::try_from("0.13.0".to_string()).unwrap(); let starknet_version_13_1 = StarknetVersion::try_from("0.13.1".to_string()).unwrap(); let starknet_version_13_2 = StarknetVersion::try_from("0.13.2".to_string()).unwrap(); - let versioned_constants = get_versioned_constants(Some(&starknet_version_13_0)).unwrap(); + let versioned_constants = VersionedConstants::get(&starknet_version_13_0).unwrap(); assert_eq!(versioned_constants.invoke_tx_max_n_steps, 3_000_000); - let versioned_constants = get_versioned_constants(Some(&starknet_version_13_1)).unwrap(); + let versioned_constants = VersionedConstants::get(&starknet_version_13_1).unwrap(); assert_eq!(versioned_constants.invoke_tx_max_n_steps, 4_000_000); - let versioned_constants = get_versioned_constants(Some(&starknet_version_13_2)).unwrap(); + let versioned_constants = VersionedConstants::get(&starknet_version_13_2).unwrap(); assert_eq!(versioned_constants.invoke_tx_max_n_steps, 10_000_000); } diff --git a/crates/papyrus_execution/src/lib.rs b/crates/papyrus_execution/src/lib.rs index 97338954c8..e96d0ea0bb 100644 --- a/crates/papyrus_execution/src/lib.rs +++ b/crates/papyrus_execution/src/lib.rs @@ -81,9 +81,6 @@ use tracing::trace; use crate::objects::{tx_execution_output_to_fee_estimation, FeeEstimation, PendingData}; -const STARKNET_VERSION_O_13_0: &str = "0.13.0"; -const STARKNET_VERSION_O_13_1: &str = "0.13.1"; -const STARKNET_VERSION_O_13_2: &str = "0.13.2"; /// The address of the STRK fee contract on Starknet. pub const STRK_FEE_CONTRACT_ADDRESS: &str = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"; @@ -368,10 +365,11 @@ fn create_block_context( eth_fee_token_address: execution_config.eth_fee_contract_address, }, }; - let starknet_version: Option = - storage_reader.begin_ro_txn()?.get_starknet_version(block_number)?; - let versioned_constants: &VersionedConstants = - get_versioned_constants(starknet_version.as_ref())?; + let starknet_version = storage_reader + .begin_ro_txn()? + .get_starknet_version(block_number)? + .unwrap_or(StarknetVersion::LATEST); + let versioned_constants = VersionedConstants::get(&starknet_version)?; let block_context = BlockContext::new( block_info, @@ -860,29 +858,6 @@ fn to_blockifier_tx( } } -// TODO(dan): add 0_13_1_1 support -fn get_versioned_constants( - starknet_version: Option<&StarknetVersion>, -) -> ExecutionResult<&'static VersionedConstants> { - let versioned_constants = match starknet_version { - Some(starknet_version) => { - let version = starknet_version.to_string(); - let starknet_api_starknet_version = if version == STARKNET_VERSION_O_13_0 { - StarknetVersion::V0_13_0 - } else if version == STARKNET_VERSION_O_13_1 { - StarknetVersion::V0_13_1 - } else if version == STARKNET_VERSION_O_13_2 { - StarknetVersion::V0_13_2 - } else { - StarknetVersion::V0_13_3 - }; - VersionedConstants::get(&starknet_api_starknet_version)? - } - None => VersionedConstants::latest_constants(), - }; - Ok(versioned_constants) -} - /// Simulates a series of transactions and returns the transaction traces and the fee estimations. // TODO(yair): Return structs instead of tuples. #[allow(clippy::too_many_arguments)]