From 41ad4db8e0e77b2c3ed3791e6e2e8ede9cef0663 Mon Sep 17 00:00:00 2001 From: Aviv Greenburg Date: Wed, 18 Dec 2024 18:09:44 +0200 Subject: [PATCH] refactor(blockifier): BouncerWeights::sierra_gas cange from GasAmount to u64 --- crates/blockifier/src/bouncer.rs | 11 +++++------ crates/blockifier/src/bouncer_test.rs | 15 +++++++-------- crates/native_blockifier/src/py_objects.rs | 12 +++++------- crates/starknet_api/src/execution_resources.rs | 12 ++++++++---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/blockifier/src/bouncer.rs b/crates/blockifier/src/bouncer.rs index 99c9345184..cd498fdae3 100644 --- a/crates/blockifier/src/bouncer.rs +++ b/crates/blockifier/src/bouncer.rs @@ -6,7 +6,6 @@ use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use serde::{Deserialize, Serialize}; use starknet_api::core::ClassHash; -use starknet_api::execution_resources::GasAmount; use crate::blockifier::transaction_executor::{ TransactionExecutorError, @@ -99,7 +98,7 @@ pub struct BouncerWeights { pub n_events: usize, pub n_steps: usize, pub state_diff_size: usize, - pub sierra_gas: GasAmount, + pub sierra_gas: u64, } impl BouncerWeights { @@ -125,7 +124,7 @@ impl BouncerWeights { state_diff_size: usize::MAX, n_events: usize::MAX, builtin_count: BuiltinCount::max(), - sierra_gas: GasAmount::MAX, + sierra_gas: u64::MAX, } } @@ -137,7 +136,7 @@ impl BouncerWeights { message_segment_length: 0, n_steps: 0, state_diff_size: 0, - sierra_gas: GasAmount::ZERO, + sierra_gas: 0, } } } @@ -152,7 +151,7 @@ impl Default for BouncerWeights { n_events: 5000, state_diff_size: 4000, builtin_count: BuiltinCount::default(), - sierra_gas: GasAmount(250000000), + sierra_gas: 250000000, } } } @@ -552,7 +551,7 @@ pub fn get_tx_weights( n_steps: vm_resources.total_n_steps(), builtin_count: BuiltinCount::from(vm_resources.prover_builtins()), state_diff_size: get_onchain_data_segment_length(&state_changes_keys.count()), - sierra_gas: tx_resources.computation.sierra_gas, + sierra_gas: tx_resources.computation.sierra_gas.0, }) } diff --git a/crates/blockifier/src/bouncer_test.rs b/crates/blockifier/src/bouncer_test.rs index 32a5f22e35..00282b9567 100644 --- a/crates/blockifier/src/bouncer_test.rs +++ b/crates/blockifier/src/bouncer_test.rs @@ -4,7 +4,6 @@ use assert_matches::assert_matches; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use rstest::rstest; -use starknet_api::execution_resources::GasAmount; use starknet_api::transaction::fields::Fee; use starknet_api::{class_hash, contract_address, storage_key}; @@ -43,7 +42,7 @@ fn test_block_weights_has_room() { n_events: 10, n_steps: 10, state_diff_size: 10, - sierra_gas: GasAmount(10), + sierra_gas: 10, }; let bouncer_weights = BouncerWeights { @@ -64,7 +63,7 @@ fn test_block_weights_has_room() { n_steps: 0, n_events: 2, state_diff_size: 7, - sierra_gas: GasAmount(7), + sierra_gas: 7, }; assert!(max_bouncer_weights.has_room(bouncer_weights)); @@ -87,7 +86,7 @@ fn test_block_weights_has_room() { n_steps: 5, n_events: 5, state_diff_size: 5, - sierra_gas: GasAmount(5), + sierra_gas: 5, }; assert!(!max_bouncer_weights.has_room(bouncer_weights_exceeds_max)); @@ -123,7 +122,7 @@ fn test_block_weights_has_room() { n_steps: 10, n_events: 10, state_diff_size: 10, - sierra_gas: GasAmount(10), + sierra_gas: 10, }, })] fn test_bouncer_update(#[case] initial_bouncer: Bouncer) { @@ -154,7 +153,7 @@ fn test_bouncer_update(#[case] initial_bouncer: Bouncer) { n_steps: 0, n_events: 1, state_diff_size: 2, - sierra_gas: GasAmount(9), + sierra_gas: 9, }; let state_changes_keys_to_update = @@ -208,7 +207,7 @@ fn test_bouncer_try_update(#[case] added_ecdsa: usize, #[case] scenario: &'stati n_steps: 20, n_events: 20, state_diff_size: 20, - sierra_gas: GasAmount(20), + sierra_gas: 20, }; let bouncer_config = BouncerConfig { block_max_capacity }; @@ -230,7 +229,7 @@ fn test_bouncer_try_update(#[case] added_ecdsa: usize, #[case] scenario: &'stati n_steps: 10, n_events: 10, state_diff_size: 10, - sierra_gas: GasAmount(10), + sierra_gas: 10, }; let mut bouncer = Bouncer { accumulated_weights, bouncer_config, ..Bouncer::empty() }; diff --git a/crates/native_blockifier/src/py_objects.rs b/crates/native_blockifier/src/py_objects.rs index d2390eeaec..3cb397f2ed 100644 --- a/crates/native_blockifier/src/py_objects.rs +++ b/crates/native_blockifier/src/py_objects.rs @@ -10,7 +10,6 @@ use blockifier::versioned_constants::VersionedConstantsOverrides; use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use pyo3::prelude::*; -use starknet_api::execution_resources::GasAmount; use crate::errors::{ InvalidNativeBlockifierInputError, @@ -126,12 +125,11 @@ fn hash_map_into_bouncer_weights( let state_diff_size = data.remove(constants::STATE_DIFF_SIZE).expect("state_diff_size must be present"); let n_events = data.remove(constants::N_EVENTS).expect("n_events must be present"); - let sierra_gas = GasAmount( - data.remove(constants::SIERRA_GAS) - .expect("sierra_gas must be present") - .try_into() - .unwrap_or_else(|err| panic!("Failed to convert 'sierra_gas' into GasAmount: {err}.")), - ); + let sierra_gas = data + .remove(constants::SIERRA_GAS) + .expect("sierra_gas must be present") + .try_into() + .unwrap_or_else(|err| panic!("Failed to convert 'sierra_gas' into GasAmount: {err}.")); Ok(BouncerWeights { l1_gas, n_steps, diff --git a/crates/starknet_api/src/execution_resources.rs b/crates/starknet_api/src/execution_resources.rs index 63577a1cce..52b09bdf62 100644 --- a/crates/starknet_api/src/execution_resources.rs +++ b/crates/starknet_api/src/execution_resources.rs @@ -9,13 +9,17 @@ use crate::transaction::fields::{Fee, Resource}; #[cfg_attr( any(test, feature = "testing"), - derive(derive_more::Sum, derive_more::Div, derive_more::SubAssign) + derive( + derive_more::Add, + derive_more::AddAssign, + derive_more::Sub, + derive_more::SubAssign, + derive_more::Sum, + derive_more::Div, + ) )] #[derive( derive_more::Display, - derive_more::Sub, - derive_more::Add, - derive_more::AddAssign, Clone, Copy, Debug,