Skip to content

Commit

Permalink
fix(blockifier): enforce fee for allresourcebounds when l1 gas is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware committed Sep 18, 2024
1 parent 80cef7c commit eff81e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl TransactionInfo {

pub fn enforce_fee(&self) -> bool {
match self {
TransactionInfo::Current(context) => {
let l1_bounds = context.l1_resource_bounds();
let max_amount: u128 = l1_bounds.max_amount.into();
max_amount * l1_bounds.max_price_per_unit > 0
}
TransactionInfo::Current(context) => context.resource_bounds.max_possible_fee() > 0,
TransactionInfo::Deprecated(context) => context.max_fee != Fee(0),
}
}
Expand Down
18 changes: 18 additions & 0 deletions crates/starknet_api/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,24 @@ impl ValidResourceBounds {
}
}

pub fn max_possible_fee(&self) -> u128 {
match self {
ValidResourceBounds::L1Gas(l1_bounds) => {
let max_amount: u128 = l1_bounds.max_amount.into();
max_amount * l1_bounds.max_price_per_unit
}
ValidResourceBounds::AllResources(AllResourceBounds {
l1_gas,
l2_gas,
l1_data_gas,
}) => {
u128::from(l1_gas.max_amount) * l1_gas.max_price_per_unit
+ u128::from(l2_gas.max_amount) * l2_gas.max_price_per_unit
+ u128::from(l1_data_gas.max_amount) * l1_data_gas.max_price_per_unit
}
}
}

// TODO(Nimrod): Default testing bounds should probably be AllResourceBounds variant.
#[cfg(any(feature = "testing", test))]
pub fn create_for_testing() -> Self {
Expand Down

0 comments on commit eff81e9

Please sign in to comment.