reth_ethereum_payload_builder/
config.rs1pub use alloy_eips::eip1559::calculate_block_gas_limit;
2use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT_30M;
3use alloy_primitives::Bytes;
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 self.gas_limit_with_target(parent_gas_limit, None)
69 }
70
71 pub fn gas_limit_with_target(
74 &self,
75 parent_gas_limit: u64,
76 target_gas_limit: Option<u64>,
77 ) -> u64 {
78 calculate_block_gas_limit(
79 parent_gas_limit,
80 target_gas_limit.unwrap_or(self.desired_gas_limit),
81 )
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use super::*;
88
89 #[test]
90 fn gas_limit_uses_payload_target_when_present() {
91 let parent_gas_limit = 30_000_000;
92 let target_gas_limit = parent_gas_limit - 100;
93 let config = EthereumBuilderConfig::new().with_gas_limit(parent_gas_limit + 100);
94
95 assert_eq!(
96 config.gas_limit_with_target(parent_gas_limit, Some(target_gas_limit)),
97 target_gas_limit
98 );
99 }
100
101 #[test]
102 fn gas_limit_falls_back_to_configured_target() {
103 let parent_gas_limit = 30_000_000;
104 let desired_gas_limit = parent_gas_limit + 100;
105 let config = EthereumBuilderConfig::new().with_gas_limit(desired_gas_limit);
106
107 assert_eq!(config.gas_limit_with_target(parent_gas_limit, None), desired_gas_limit);
108 assert_eq!(config.gas_limit(parent_gas_limit), desired_gas_limit);
109 }
110}