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
28 changes: 8 additions & 20 deletions crates/op-rbuilder/src/builders/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use alloy_op_evm::block::receipt_builder::OpReceiptBuilder;
use alloy_primitives::{Address, Bytes, TxKind, U256};
use alloy_rpc_types_eth::Withdrawals;
use core::fmt::Debug;
use derive_more::Display;
use op_alloy_consensus::{OpDepositReceipt, OpTypedTransaction};
use op_revm::{OpSpecId, OpTransactionError};
use op_revm::OpSpecId;
use reth::payload::PayloadBuilderAttributes;
use reth_basic_payload_builder::PayloadConfig;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
Expand Down Expand Up @@ -39,8 +38,11 @@ use tokio_util::sync::CancellationToken;
use tracing::{info, trace, warn};

use crate::{
metrics::OpRBuilderMetrics, primitives::reth::ExecutionInfo, traits::PayloadTxsBounds,
tx::MaybeRevertingTransaction, tx_signer::Signer,
metrics::OpRBuilderMetrics,
primitives::reth::{ExecutionInfo, TxnExecutionResult},
traits::PayloadTxsBounds,
tx::MaybeRevertingTransaction,
tx_signer::Signer,
};

/// Container type that holds all necessities to build a new payload.
Expand Down Expand Up @@ -191,20 +193,6 @@ impl OpPayloadBuilderCtx {
}
}

#[derive(Debug, Display)]
enum TxnExecutionResult {
InvalidDASize,
SequencerTransaction,
NonceTooLow,
InteropFailed,
#[display("InternalError({_0})")]
InternalError(OpTransactionError),
EvmError,
Success,
Reverted,
RevertedAndExcluded,
}

impl OpPayloadBuilderCtx {
/// Constructs a receipt for the given transaction.
fn build_receipt<E: Evm>(
Expand Down Expand Up @@ -383,7 +371,7 @@ impl OpPayloadBuilderCtx {

num_txs_considered += 1;
// ensure we still have capacity for this transaction
if info.is_tx_over_limits(
if let Err(result) = info.is_tx_over_limits(
tx_da_size,
block_gas_limit,
tx_da_limit,
Expand All @@ -393,7 +381,7 @@ impl OpPayloadBuilderCtx {
// we can't fit this transaction into the block, so we need to mark it as
// invalid which also removes all dependent transaction from
// the iterator before we can continue
log_txn(TxnExecutionResult::InvalidDASize);
log_txn(result);
best_txs.mark_invalid(tx.signer(), tx.nonce());
continue;
}
Expand Down
29 changes: 25 additions & 4 deletions crates/op-rbuilder/src/primitives/reth/execution.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
//! Heavily influenced by [reth](https://github.com/paradigmxyz/reth/blob/1e965caf5fa176f244a31c0d2662ba1b590938db/crates/optimism/payload/src/builder.rs#L570)
use alloy_primitives::{Address, U256};
use core::fmt::Debug;
use derive_more::Display;
use op_revm::OpTransactionError;
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};

#[derive(Debug, Display)]
pub enum TxnExecutionResult {
TransactionDALimitExceeded,
BlockDALimitExceeded,
TransactionGasLimitExceeded,
SequencerTransaction,
NonceTooLow,
InteropFailed,
#[display("InternalError({_0})")]
InternalError(OpTransactionError),
EvmError,
Success,
Reverted,
RevertedAndExcluded,
}

#[derive(Default, Debug)]
pub struct ExecutionInfo<Extra: Debug + Default = ()> {
/// All executed transactions (unrecovered).
Expand Down Expand Up @@ -48,17 +66,20 @@ impl<T: Debug + Default> ExecutionInfo<T> {
tx_data_limit: Option<u64>,
block_data_limit: Option<u64>,
tx_gas_limit: u64,
) -> bool {
) -> Result<(), TxnExecutionResult> {
if tx_data_limit.is_some_and(|da_limit| tx_da_size > da_limit) {
return true;
return Err(TxnExecutionResult::TransactionDALimitExceeded);
}

if block_data_limit
.is_some_and(|da_limit| self.cumulative_da_bytes_used + tx_da_size > da_limit)
{
return true;
return Err(TxnExecutionResult::BlockDALimitExceeded);
}

self.cumulative_gas_used + tx_gas_limit > block_gas_limit
if self.cumulative_gas_used + tx_gas_limit > block_gas_limit {
return Err(TxnExecutionResult::TransactionGasLimitExceeded);
}
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/op-rbuilder/src/primitives/reth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod execution;
pub use execution::ExecutionInfo;
pub use execution::{ExecutionInfo, TxnExecutionResult};
Loading