Skip to content

Commit

Permalink
fix: safe match for next base fee (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Sep 30, 2024
1 parent 35b1507 commit 16dbd30
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/eips/src/eip1559/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ pub fn calc_next_block_base_fee(
+ (core::cmp::max(
// Ensure a minimum increase of 1.
1,
base_fee * (gas_used - gas_target)
/ (gas_target * base_fee_params.max_change_denominator as u64),
))
base_fee as u128 * (gas_used - gas_target) as u128
/ (gas_target as u128 * base_fee_params.max_change_denominator),
) as u64)
}
// If the gas used in the current block is less than the gas target, calculate a new
// decreased base fee.
core::cmp::Ordering::Less => {
// Calculate the decrease in base fee based on the formula defined by EIP-1559.
base_fee.saturating_sub(
base_fee * (gas_target - gas_used)
/ (gas_target * base_fee_params.max_change_denominator as u64),
(base_fee as u128 * (gas_target - gas_used) as u128
/ (gas_target as u128 * base_fee_params.max_change_denominator))
as u64,
)
}
}
Expand Down

0 comments on commit 16dbd30

Please sign in to comment.