Skip to content
Merged
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
26 changes: 15 additions & 11 deletions crates/op-rbuilder/src/builders/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,21 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
.record(tx_simulation_start_time.elapsed());
self.metrics.tx_byte_size.record(tx.inner().size() as f64);
num_txs_simulated += 1;

// Run the per-address gas limiting before checking if the tx has
// reverted or not, as this is a check against maliciously searchers
// sending txs that are expensive to compute but always revert.
let gas_used = result.gas_used();
if self
.address_gas_limiter
.consume_gas(tx.signer(), gas_used)
.is_err()
{
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
best_txs.mark_invalid(tx.signer(), tx.nonce());
continue;
}

if result.is_success() {
log_txn(TxnExecutionResult::Success);
num_txs_simulated_success += 1;
Expand All @@ -480,7 +495,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {

// add gas used by the transaction to cumulative gas used, before creating the
// receipt
let gas_used = result.gas_used();
if let Some(max_gas_per_txn) = self.max_gas_per_txn {
if gas_used > max_gas_per_txn {
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
Expand All @@ -489,16 +503,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
}
}

if self
.address_gas_limiter
.consume_gas(tx.signer(), gas_used)
.is_err()
{
log_txn(TxnExecutionResult::MaxGasUsageExceeded);
best_txs.mark_invalid(tx.signer(), tx.nonce());
continue;
}

info.cumulative_gas_used += gas_used;
// record tx da size
info.cumulative_da_bytes_used += tx_da_size;
Expand Down
Loading