reth_ethereum_payload_builder/
config.rs1use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT_30M;
2use alloy_primitives::Bytes;
3use reth_primitives_traits::constants::GAS_LIMIT_BOUND_DIVISOR;
4
5#[derive(PartialEq, Eq, Clone, Debug)]
7pub struct EthereumBuilderConfig {
8 pub desired_gas_limit: u64,
10 pub await_payload_on_missing: bool,
13 pub max_blobs_per_block: Option<u64>,
17 pub extra_data: Bytes,
19}
20
21impl Default for EthereumBuilderConfig {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl EthereumBuilderConfig {
28 pub const fn new() -> Self {
30 Self {
31 desired_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT_30M,
32 await_payload_on_missing: true,
33 max_blobs_per_block: None,
34 extra_data: Bytes::new(),
35 }
36 }
37
38 pub const fn with_gas_limit(mut self, desired_gas_limit: u64) -> Self {
40 self.desired_gas_limit = desired_gas_limit;
41 self
42 }
43
44 pub const fn with_await_payload_on_missing(mut self, await_payload_on_missing: bool) -> Self {
47 self.await_payload_on_missing = await_payload_on_missing;
48 self
49 }
50
51 pub const fn with_max_blobs_per_block(mut self, max_blobs_per_block: Option<u64>) -> Self {
53 self.max_blobs_per_block = max_blobs_per_block;
54 self
55 }
56
57 pub fn with_extra_data(mut self, extra_data: Bytes) -> Self {
59 self.extra_data = extra_data;
60 self
61 }
62}
63
64impl EthereumBuilderConfig {
65 pub fn gas_limit(&self, parent_gas_limit: u64) -> u64 {
68 calculate_block_gas_limit(parent_gas_limit, self.desired_gas_limit)
69 }
70}
71
72pub fn calculate_block_gas_limit(parent_gas_limit: u64, desired_gas_limit: u64) -> u64 {
75 let delta = (parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR).saturating_sub(1);
76 let min_gas_limit = parent_gas_limit - delta;
77 let max_gas_limit = parent_gas_limit + delta;
78 desired_gas_limit.clamp(min_gas_limit, max_gas_limit)
79}