Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 14 additions & 1 deletion crates/scroll/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ where
builder: &mut impl BlockBuilder<Primitives = Evm::Primitives>,
) -> Result<ExecutionInfo, PayloadBuilderError> {
let mut info = ExecutionInfo::new();
let block_gas_limit = builder.evm().block().gas_limit;

for sequencer_tx in &self.attributes().transactions {
// A sequencer's block should never contain blob transactions.
Expand All @@ -445,7 +446,6 @@ where
ScrollPayloadBuilderError::BlobTransactionRejected,
))
}

// Convert the transaction to a [RecoveredTx]. This is
// purely for the purposes of utilizing the `evm_config.tx_env`` function.
// Deposit transactions do not have signatures, so if the tx is a deposit, this
Expand All @@ -454,6 +454,19 @@ where
PayloadBuilderError::other(ScrollPayloadBuilderError::TransactionEcRecoverFailed)
})?;

let gas_limit = sequencer_tx.gas_limit();

// Check if there's enough gas in the block gas limit
let remaining_gas = block_gas_limit.saturating_sub(info.cumulative_gas_used);
if gas_limit > remaining_gas {
return Err(PayloadBuilderError::other(
ScrollPayloadBuilderError::SequencerTxGasExceedsBlock {
gas_limit,
remaining_gas,
},
));
}

let gas_used = match builder.execute_transaction(sequencer_tx.clone()) {
Ok(gas_used) => gas_used,
Err(BlockExecutionError::Validation(BlockValidationError::InvalidTx {
Expand Down
10 changes: 10 additions & 0 deletions crates/scroll/payload/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ pub enum ScrollPayloadBuilderError {
/// Thrown when a blob transaction is included in a sequencer's block.
#[error("blob transaction included in sequencer block")]
BlobTransactionRejected,
/// Thrown when sequencer transaction gas limit exceeds remaining block gas.
#[error(
"Sequencer transaction gas limit {gas_limit} exceeds remaining block gas {remaining_gas}, cannot skip sequencer transactions"
)]
SequencerTxGasExceedsBlock {
/// The gas limit of the sequencer transaction
gas_limit: u64,
/// The remaining gas available in the block
remaining_gas: u64,
},
}