reth_ethereum_payload_builder/
config.rsuse alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_primitives::Bytes;
use reth_primitives_traits::constants::GAS_LIMIT_BOUND_DIVISOR;
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct EthereumBuilderConfig {
pub extra_data: Bytes,
pub desired_gas_limit: u64,
}
impl EthereumBuilderConfig {
pub const fn new(extra_data: Bytes) -> Self {
Self { extra_data, desired_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT }
}
pub const fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
self.desired_gas_limit = desired_gas_limit;
self
}
}
impl EthereumBuilderConfig {
pub fn extra_data(&self) -> Bytes {
self.extra_data.clone()
}
pub fn gas_limit(&self, parent_gas_limit: u64) -> u64 {
calculate_block_gas_limit(parent_gas_limit, self.desired_gas_limit)
}
}
pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
let delta = (parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR).saturating_sub(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)
}