Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 67 additions & 8 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use reth_optimism_evm::{OpEvmConfig, OpRethReceiptBuilder};
use reth_optimism_forks::OpHardforks;
use reth_optimism_payload_builder::{
builder::OpPayloadTransactions,
config::{OpBuilderConfig, OpDAConfig},
config::{OpBuilderConfig, OpDAConfig, OpGasLimitConfig},
OpAttributes, OpBuiltPayload, OpPayloadPrimitives,
};
use reth_optimism_primitives::{DepositReceipt, OpPrimitives};
Expand Down Expand Up @@ -118,6 +118,10 @@ pub struct OpNode {
///
/// By default no throttling is applied.
pub da_config: OpDAConfig,
/// Gas limit configuration for the OP builder.
/// Used to control the gas limit of the blocks produced by the OP builder.(configured by the
/// batcher via the `miner_` api)
pub gas_limit_config: OpGasLimitConfig,
}

/// A [`ComponentsBuilder`] with its generic arguments set to a stack of Optimism specific builders.
Expand All @@ -133,7 +137,11 @@ pub type OpNodeComponentBuilder<Node, Payload = OpPayloadBuilder> = ComponentsBu
impl OpNode {
/// Creates a new instance of the Optimism node type.
pub fn new(args: RollupArgs) -> Self {
Self { args, da_config: OpDAConfig::default() }
Self {
args,
da_config: OpDAConfig::default(),
gas_limit_config: OpGasLimitConfig::default(),
}
}

/// Configure the data availability configuration for the OP builder.
Expand All @@ -142,6 +150,12 @@ impl OpNode {
self
}

/// Configure the gas limit configuration for the OP builder.
pub fn with_gas_limit_config(mut self, gas_limit_config: OpGasLimitConfig) -> Self {
self.gas_limit_config = gas_limit_config;
self
}

/// Returns the components for the given [`RollupArgs`].
pub fn components<Node>(&self) -> OpNodeComponentBuilder<Node>
where
Expand All @@ -161,7 +175,9 @@ impl OpNode {
)
.executor(OpExecutorBuilder::default())
.payload(BasicPayloadServiceBuilder::new(
OpPayloadBuilder::new(compute_pending_block).with_da_config(self.da_config.clone()),
OpPayloadBuilder::new(compute_pending_block)
.with_da_config(self.da_config.clone())
.with_gas_limit_config(self.gas_limit_config.clone()),
))
.network(OpNetworkBuilder::new(disable_txpool_gossip, !discovery_v4))
.consensus(OpConsensusBuilder::default())
Expand All @@ -173,6 +189,7 @@ impl OpNode {
.with_sequencer(self.args.sequencer.clone())
.with_sequencer_headers(self.args.sequencer_headers.clone())
.with_da_config(self.da_config.clone())
.with_gas_limit_config(self.gas_limit_config.clone())
.with_enable_tx_conditional(self.args.enable_tx_conditional)
.with_min_suggested_priority_fee(self.args.min_suggested_priority_fee)
.with_historical_rpc(self.args.historical_rpc.clone())
Expand Down Expand Up @@ -286,6 +303,8 @@ pub struct OpAddOns<
pub rpc_add_ons: RpcAddOns<N, EthB, PVB, EB, EVB, RpcMiddleware>,
/// Data availability configuration for the OP builder.
pub da_config: OpDAConfig,
/// Gas limit configuration for the OP builder.
pub gas_limit_config: OpGasLimitConfig,
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
/// network.
pub sequencer_url: Option<String>,
Expand All @@ -306,9 +325,11 @@ where
EthB: EthApiBuilder<N>,
{
/// Creates a new instance from components.
#[allow(clippy::too_many_arguments)]
pub const fn new(
rpc_add_ons: RpcAddOns<N, EthB, PVB, EB, EVB, RpcMiddleware>,
da_config: OpDAConfig,
gas_limit_config: OpGasLimitConfig,
sequencer_url: Option<String>,
sequencer_headers: Vec<String>,
historical_rpc: Option<String>,
Expand All @@ -318,6 +339,7 @@ where
Self {
rpc_add_ons,
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
historical_rpc,
Expand Down Expand Up @@ -368,6 +390,7 @@ where
let Self {
rpc_add_ons,
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
historical_rpc,
Expand All @@ -378,6 +401,7 @@ where
OpAddOns::new(
rpc_add_ons.with_engine_api(engine_api_builder),
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
historical_rpc,
Expand All @@ -394,6 +418,7 @@ where
let Self {
rpc_add_ons,
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
enable_tx_conditional,
Expand All @@ -404,6 +429,7 @@ where
OpAddOns::new(
rpc_add_ons.with_payload_validator(payload_validator_builder),
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
historical_rpc,
Expand All @@ -423,6 +449,7 @@ where
let Self {
rpc_add_ons,
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
enable_tx_conditional,
Expand All @@ -433,6 +460,7 @@ where
OpAddOns::new(
rpc_add_ons.with_rpc_middleware(rpc_middleware),
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
historical_rpc,
Expand Down Expand Up @@ -496,6 +524,7 @@ where
let Self {
rpc_add_ons,
da_config,
gas_limit_config,
sequencer_url,
sequencer_headers,
enable_tx_conditional,
Expand Down Expand Up @@ -536,7 +565,7 @@ where
Box::new(ctx.node.task_executor().clone()),
builder,
);
let miner_ext = OpMinerExtApi::new(da_config);
let miner_ext = OpMinerExtApi::new(da_config, gas_limit_config);

let sequencer_client = if let Some(url) = sequencer_url {
Some(SequencerClient::new_with_headers(url, sequencer_headers).await?)
Expand Down Expand Up @@ -652,6 +681,8 @@ pub struct OpAddOnsBuilder<NetworkT, RpcMiddleware = Identity> {
historical_rpc: Option<String>,
/// Data availability configuration for the OP builder.
da_config: Option<OpDAConfig>,
/// Gas limit configuration for the OP builder.
gas_limit_config: Option<OpGasLimitConfig>,
/// Enable transaction conditionals.
enable_tx_conditional: bool,
/// Marker for network types.
Expand All @@ -673,6 +704,7 @@ impl<NetworkT> Default for OpAddOnsBuilder<NetworkT> {
sequencer_headers: Vec::new(),
historical_rpc: None,
da_config: None,
gas_limit_config: None,
enable_tx_conditional: false,
min_suggested_priority_fee: 1_000_000,
_nt: PhantomData,
Expand Down Expand Up @@ -702,6 +734,12 @@ impl<NetworkT, RpcMiddleware> OpAddOnsBuilder<NetworkT, RpcMiddleware> {
self
}

/// Configure the gas limit configuration for the OP payload builder.
pub fn with_gas_limit_config(mut self, gas_limit_config: OpGasLimitConfig) -> Self {
self.gas_limit_config = Some(gas_limit_config);
self
}

/// Configure if transaction conditional should be enabled.
pub const fn with_enable_tx_conditional(mut self, enable_tx_conditional: bool) -> Self {
self.enable_tx_conditional = enable_tx_conditional;
Expand Down Expand Up @@ -735,6 +773,7 @@ impl<NetworkT, RpcMiddleware> OpAddOnsBuilder<NetworkT, RpcMiddleware> {
sequencer_headers,
historical_rpc,
da_config,
gas_limit_config,
enable_tx_conditional,
min_suggested_priority_fee,
tokio_runtime,
Expand All @@ -747,6 +786,7 @@ impl<NetworkT, RpcMiddleware> OpAddOnsBuilder<NetworkT, RpcMiddleware> {
sequencer_headers,
historical_rpc,
da_config,
gas_limit_config,
enable_tx_conditional,
min_suggested_priority_fee,
_nt,
Expand Down Expand Up @@ -779,6 +819,7 @@ impl<NetworkT, RpcMiddleware> OpAddOnsBuilder<NetworkT, RpcMiddleware> {
sequencer_url,
sequencer_headers,
da_config,
gas_limit_config,
enable_tx_conditional,
min_suggested_priority_fee,
historical_rpc,
Expand All @@ -802,6 +843,7 @@ impl<NetworkT, RpcMiddleware> OpAddOnsBuilder<NetworkT, RpcMiddleware> {
)
.with_tokio_runtime(tokio_runtime),
da_config.unwrap_or_default(),
gas_limit_config.unwrap_or_default(),
sequencer_url,
sequencer_headers,
historical_rpc,
Expand Down Expand Up @@ -1006,28 +1048,42 @@ pub struct OpPayloadBuilder<Txs = ()> {
/// This data availability configuration specifies constraints for the payload builder
/// when assembling payloads
pub da_config: OpDAConfig,
/// Gas limit configuration for the OP builder.
/// This is used to configure gas limit related constraints for the payload builder.
pub gas_limit_config: OpGasLimitConfig,
}

impl OpPayloadBuilder {
/// Create a new instance with the given `compute_pending_block` flag and data availability
/// config.
pub fn new(compute_pending_block: bool) -> Self {
Self { compute_pending_block, best_transactions: (), da_config: OpDAConfig::default() }
Self {
compute_pending_block,
best_transactions: (),
da_config: OpDAConfig::default(),
gas_limit_config: OpGasLimitConfig::default(),
}
}

/// Configure the data availability configuration for the OP payload builder.
pub fn with_da_config(mut self, da_config: OpDAConfig) -> Self {
self.da_config = da_config;
self
}

/// Configure the gas limit configuration for the OP payload builder.
pub fn with_gas_limit_config(mut self, gas_limit_config: OpGasLimitConfig) -> Self {
self.gas_limit_config = gas_limit_config;
self
}
}

impl<Txs> OpPayloadBuilder<Txs> {
/// Configures the type responsible for yielding the transactions that should be included in the
/// payload.
pub fn with_transactions<T>(self, best_transactions: T) -> OpPayloadBuilder<T> {
let Self { compute_pending_block, da_config, .. } = self;
OpPayloadBuilder { compute_pending_block, best_transactions, da_config }
let Self { compute_pending_block, da_config, gas_limit_config, .. } = self;
OpPayloadBuilder { compute_pending_block, best_transactions, da_config, gas_limit_config }
}
}

Expand Down Expand Up @@ -1068,7 +1124,10 @@ where
pool,
ctx.provider().clone(),
evm_config,
OpBuilderConfig { da_config: self.da_config.clone() },
OpBuilderConfig {
da_config: self.da_config.clone(),
gas_limit_config: self.gas_limit_config.clone(),
},
)
.with_transactions(self.best_transactions.clone())
.set_compute_pending_block(self.compute_pending_block);
Expand Down
25 changes: 14 additions & 11 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Optimism payload builder implementation.
use crate::{
config::{OpBuilderConfig, OpDAConfig},
error::OpPayloadBuilderError,
payload::OpBuiltPayload,
OpAttributes, OpPayloadBuilderAttributes, OpPayloadPrimitives,
config::OpBuilderConfig, error::OpPayloadBuilderError, payload::OpBuiltPayload, OpAttributes,
OpPayloadBuilderAttributes, OpPayloadPrimitives,
};
use alloy_consensus::{BlockHeader, Transaction, Typed2718};
use alloy_evm::Evm as AlloyEvm;
Expand Down Expand Up @@ -187,7 +185,7 @@ where

let ctx = OpPayloadBuilderCtx {
evm_config: self.evm_config.clone(),
da_config: self.config.da_config.clone(),
builder_config: self.config.clone(),
chain_spec: self.client.chain_spec(),
config,
cancel,
Expand Down Expand Up @@ -223,7 +221,7 @@ where
let config = PayloadConfig { parent_header: Arc::new(parent), attributes };
let ctx = OpPayloadBuilderCtx {
evm_config: self.evm_config.clone(),
da_config: self.config.da_config.clone(),
builder_config: self.config.clone(),
chain_spec: self.client.chain_spec(),
config,
cancel: Default::default(),
Expand Down Expand Up @@ -550,8 +548,8 @@ pub struct OpPayloadBuilderCtx<
> {
/// The type that knows how to perform system calls and configure the evm.
pub evm_config: Evm,
/// The DA config for the payload builder
pub da_config: OpDAConfig,
/// Additional config for the builder/sequencer, e.g. DA and gas limit
pub builder_config: OpBuilderConfig,
/// The chainspec
pub chain_spec: Arc<ChainSpec>,
/// How to build the payload.
Expand Down Expand Up @@ -684,9 +682,14 @@ where
Builder: BlockBuilder<Primitives = Evm::Primitives>,
<<Builder::Executor as BlockExecutor>::Evm as AlloyEvm>::DB: Database,
{
let block_gas_limit = builder.evm_mut().block().gas_limit();
let block_da_limit = self.da_config.max_da_block_size();
let tx_da_limit = self.da_config.max_da_tx_size();
let mut block_gas_limit = builder.evm_mut().block().gas_limit();
if let Some(gas_limit_config) = self.builder_config.gas_limit_config.gas_limit() {
// If a gas limit is configured, use that limit as target if it's smaller, otherwise use
// the block's actual gas limit.
block_gas_limit = gas_limit_config.min(block_gas_limit);
};
Comment on lines +686 to +690
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haardikk21 this is the actual integration for the sequencer tx execution.

this doesnt alter the block's gas limit but enforces how much we fill the block with

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

let block_da_limit = self.builder_config.da_config.max_da_block_size();
let tx_da_limit = self.builder_config.da_config.max_da_tx_size();
let base_fee = builder.evm_mut().block().basefee();

while let Some(tx) = best_txs.next(()) {
Expand Down
Loading