reth_ethereum_payload_builder/
config.rs1use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT_30M;
2use reth_primitives_traits::constants::GAS_LIMIT_BOUND_DIVISOR;
3
4#[derive(PartialEq, Eq, Clone, Debug)]
6pub struct EthereumBuilderConfig {
7    pub desired_gas_limit: u64,
9    pub await_payload_on_missing: bool,
12}
13
14impl Default for EthereumBuilderConfig {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl EthereumBuilderConfig {
21    pub const fn new() -> Self {
23        Self { desired_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT_30M, await_payload_on_missing: true }
24    }
25
26    pub const fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
28        self.desired_gas_limit = desired_gas_limit;
29        self
30    }
31
32    pub const fn with_await_payload_on_missing(mut self, await_payload_on_missing: bool) -> Self {
35        self.await_payload_on_missing = await_payload_on_missing;
36        self
37    }
38}
39
40impl EthereumBuilderConfig {
41    pub fn gas_limit(&self, parent_gas_limit: u64) -> u64 {
44        calculate_block_gas_limit(parent_gas_limit, self.desired_gas_limit)
45    }
46}
47
48pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
51    let delta = (parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR).saturating_sub(1);
52    let min_gas_limit = parent_gas_limit - delta;
53    let max_gas_limit = parent_gas_limit + delta;
54    desired_gas_limit.clamp(min_gas_limit, max_gas_limit)
55}