Skip to content

Commit

Permalink
const fn & simplify delta
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Dec 12, 2024
1 parent 31f9fcc commit 4301c5f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/ethereum/payload/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl EthereumBuilderConfig {
}

/// Set desired gas limit.
pub fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
pub const fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
self.desired_gas_limit = desired_gas_limit;
self
}
Expand All @@ -40,8 +40,8 @@ impl EthereumBuilderConfig {
/// Calculate the gas limit for the next block based on parent and desired gas limits.
/// Ref: <https://github.com/ethereum/go-ethereum/blob/88cbfab332c96edfbe99d161d9df6a40721bd786/core/block_validator.go#L166>
pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR;
let min_gas_limit = parent_gas_limit + delta - 1;
let max_gas_limit = parent_gas_limit - delta + 1;
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR - 1;
let min_gas_limit = parent_gas_limit + delta;
let max_gas_limit = parent_gas_limit - delta;
desired_gas_limit.clamp(min_gas_limit, max_gas_limit)
}

0 comments on commit 4301c5f

Please sign in to comment.