Skip to content
Closed
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
12 changes: 12 additions & 0 deletions crates/execution-payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ impl Display for UnprocessableTransactionError {
}

impl std::error::Error for UnprocessableTransactionError {}

/// Error type for when cumulative gas accounting overflows a `u64` while building a payload.
#[derive(Debug)]
pub struct CumulativeGasOverflowError;

impl Display for CumulativeGasOverflowError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "cumulative gas accounting overflowed u64 while building payload")
}
}

impl std::error::Error for CumulativeGasOverflowError {}
15 changes: 8 additions & 7 deletions crates/execution-payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use std::{
};
use tracing::{debug, error, info, trace, warn};

use crate::builder::CumulativeGasOverflowError;
use crate::builder::UnprocessableTransactionError;
use crate::metrics::PayloadBuildMetrics;
use arc_execution_txpool::InvalidTxList;
Expand Down Expand Up @@ -760,12 +761,12 @@ where
break;
}

// ensure we still have capacity for this transaction
if block_gas_limit
< cumulative_gas_used
.checked_add(pool_tx.gas_limit())
.expect("total gas shouldn't overflow")
{
// ensure we still have capacity for this transaction. Treat an overflow of the
// addition the same as "doesn't fit": it can never fit in a bounded block anyway.
let fits_in_block = cumulative_gas_used
.checked_add(pool_tx.gas_limit())
.is_some_and(|total| total <= block_gas_limit);
if !fits_in_block {
// 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
Expand Down Expand Up @@ -873,7 +874,7 @@ where
}
cumulative_gas_used = cumulative_gas_used
.checked_add(gas_used)
.expect("total gas shouldn't overflow");
.ok_or_else(|| PayloadBuilderError::other(CumulativeGasOverflowError))?;
}

PayloadBuildMetrics::record_stage_tx_execution(loop_started.elapsed());
Expand Down
Loading