diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index f370ed496f..27778da8f4 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -1,12 +1,17 @@ //! Optimism payload builder implementation. -use std::{fmt::Display, sync::Arc}; - +use crate::{ + config::OpBuilderConfig, + error::OpPayloadBuilderError, + payload::{OpBuiltPayload, OpPayloadBuilderAttributes}, +}; use alloy_consensus::{Header, Transaction, EMPTY_OMMER_ROOT_HASH}; use alloy_eips::{eip4895::Withdrawals, merge::BEACON_NONCE}; use alloy_primitives::{Address, Bytes, B256, U256}; use alloy_rpc_types_debug::ExecutionWitness; use alloy_rpc_types_engine::PayloadId; +use op_alloy_consensus::DepositTransaction; +use op_alloy_rpc_types_engine::OpPayloadAttributes; use reth_basic_payload_builder::*; use reth_chain_state::ExecutedBlock; use reth_chainspec::{ChainSpecProvider, EthereumHardforks}; @@ -26,9 +31,10 @@ use reth_provider::{ HashedPostStateProvider, ProviderError, StateProofProvider, StateProviderFactory, StateRootProvider, }; -use reth_revm::database::StateProviderDatabase; +use reth_revm::{database::StateProviderDatabase, witness::ExecutionWitnessRecord}; use reth_transaction_pool::{ - noop::NoopTransactionPool, BestTransactionsAttributes, PoolTransaction, TransactionPool, + noop::NoopTransactionPool, pool::BestPayloadTransactions, BestTransactionsAttributes, + PoolTransaction, TransactionPool, }; use revm::{ db::{states::bundle_state::BundleRetention, State}, @@ -38,25 +44,19 @@ use revm::{ }, Database, DatabaseCommit, }; +use std::{fmt::Display, sync::Arc}; use tracing::{debug, trace, warn}; -use crate::{ - error::OpPayloadBuilderError, - payload::{OpBuiltPayload, OpPayloadBuilderAttributes}, -}; -use op_alloy_consensus::DepositTransaction; -use op_alloy_rpc_types_engine::OpPayloadAttributes; -use reth_revm::witness::ExecutionWitnessRecord; -use reth_transaction_pool::pool::BestPayloadTransactions; - /// Optimism's payload builder -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct OpPayloadBuilder { /// The rollup's compute pending block configuration option. // TODO(clabby): Implement this feature. pub compute_pending_block: bool, /// The type responsible for creating the evm. pub evm_config: EvmConfig, + /// Settings for the builder, e.g. DA settings. + pub config: OpBuilderConfig, /// The type responsible for yielding the best transactions for the payload if mempool /// transactions are allowed. pub best_transactions: Txs, @@ -64,8 +64,15 @@ pub struct OpPayloadBuilder { impl OpPayloadBuilder { /// `OpPayloadBuilder` constructor. - pub const fn new(evm_config: EvmConfig) -> Self { - Self { compute_pending_block: true, evm_config, best_transactions: () } + /// + /// Configures the builder with the default settings. + pub fn new(evm_config: EvmConfig) -> Self { + Self::with_builder_config(evm_config, Default::default()) + } + + /// Configures the builder with the given [`OpBuilderConfig`]. + pub const fn with_builder_config(evm_config: EvmConfig, config: OpBuilderConfig) -> Self { + Self { compute_pending_block: true, evm_config, config, best_transactions: () } } } @@ -82,8 +89,8 @@ impl OpPayloadBuilder { self, best_transactions: T, ) -> OpPayloadBuilder { - let Self { compute_pending_block, evm_config, .. } = self; - OpPayloadBuilder { compute_pending_block, evm_config, best_transactions } + let Self { compute_pending_block, evm_config, config, .. } = self; + OpPayloadBuilder { compute_pending_block, evm_config, best_transactions, config } } /// Enables the rollup's compute pending block configuration option. diff --git a/crates/optimism/payload/src/config.rs b/crates/optimism/payload/src/config.rs index 5055c05c42..469bfc9fe3 100644 --- a/crates/optimism/payload/src/config.rs +++ b/crates/optimism/payload/src/config.rs @@ -2,7 +2,34 @@ use std::sync::{atomic::AtomicU64, Arc}; +/// Settings for the OP builder. +#[derive(Debug, Clone, Default)] +pub struct OpBuilderConfig { + /// Data availability configuration for the OP builder. + pub da_config: OpDAConfig, +} + +impl OpBuilderConfig { + /// Creates a new OP builder configuration with the given data availability configuration. + pub const fn new(da_config: OpDAConfig) -> Self { + Self { da_config } + } + + /// Returns the Data Availability configuration for the OP builder, if it has configured + /// constraints. + pub fn constrained_da_config(&self) -> Option<&OpDAConfig> { + if self.da_config.is_empty() { + None + } else { + Some(&self.da_config) + } + } +} + /// Contains the Data Availability configuration for the OP builder. +/// +/// This type is shareable and can be used to update the DA configuration for the OP payload +/// builder. #[derive(Debug, Clone, Default)] pub struct OpDAConfig { inner: Arc, @@ -16,6 +43,11 @@ impl OpDAConfig { this } + /// Returns whether the configuration is empty. + pub fn is_empty(&self) -> bool { + self.max_da_tx_size().is_none() && self.max_da_block_size().is_none() + } + /// Returns the max allowed data availability size per transactions, if any. pub fn max_da_tx_size(&self) -> Option { let val = self.inner.max_da_tx_size.load(std::sync::atomic::Ordering::Relaxed); @@ -84,4 +116,10 @@ mod tests { assert_eq!(da.max_da_tx_size(), None); assert_eq!(da.max_da_block_size(), None); } + + #[test] + fn test_da_constrained() { + let config = OpBuilderConfig::default(); + assert!(config.constrained_da_config().is_none()); + } }