Skip to content

Commit

Permalink
refactor(blockifier): BouncerWeights::sierra_gas cange from GasAmount…
Browse files Browse the repository at this point in the history
… to u64
  • Loading branch information
avivg-starkware committed Dec 18, 2024
1 parent 28a0f67 commit 41ad4db
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
11 changes: 5 additions & 6 deletions crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand All @@ -137,7 +136,7 @@ impl BouncerWeights {
message_segment_length: 0,
n_steps: 0,
state_diff_size: 0,
sierra_gas: GasAmount::ZERO,
sierra_gas: 0,
}
}
}
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -552,7 +551,7 @@ pub fn get_tx_weights<S: StateReader>(
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,
})
}

Expand Down
15 changes: 7 additions & 8 deletions crates/blockifier/src/bouncer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 };

Expand All @@ -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() };
Expand Down
12 changes: 5 additions & 7 deletions crates/native_blockifier/src/py_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions crates/starknet_api/src/execution_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 41ad4db

Please sign in to comment.