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 23, 2024
1 parent c95598e commit e6feb76
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 @@ -979,6 +979,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 e6feb76

Please sign in to comment.