Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: safe match for next base fee #1399

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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