@@ -460,6 +460,21 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
460460 . record ( tx_simulation_start_time. elapsed ( ) ) ;
461461 self . metrics . tx_byte_size . record ( tx. inner ( ) . size ( ) as f64 ) ;
462462 num_txs_simulated += 1 ;
463+
464+ // Run the per-address gas limiting before checking if the tx has
465+ // reverted or not, as this is a check against maliciously searchers
466+ // sending txs that are expensive to compute but always revert.
467+ let gas_used = result. gas_used ( ) ;
468+ if self
469+ . address_gas_limiter
470+ . consume_gas ( tx. signer ( ) , gas_used)
471+ . is_err ( )
472+ {
473+ log_txn ( TxnExecutionResult :: MaxGasUsageExceeded ) ;
474+ best_txs. mark_invalid ( tx. signer ( ) , tx. nonce ( ) ) ;
475+ continue ;
476+ }
477+
463478 if result. is_success ( ) {
464479 log_txn ( TxnExecutionResult :: Success ) ;
465480 num_txs_simulated_success += 1 ;
@@ -480,7 +495,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
480495
481496 // add gas used by the transaction to cumulative gas used, before creating the
482497 // receipt
483- let gas_used = result. gas_used ( ) ;
484498 if let Some ( max_gas_per_txn) = self . max_gas_per_txn {
485499 if gas_used > max_gas_per_txn {
486500 log_txn ( TxnExecutionResult :: MaxGasUsageExceeded ) ;
@@ -489,16 +503,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
489503 }
490504 }
491505
492- if self
493- . address_gas_limiter
494- . consume_gas ( tx. signer ( ) , gas_used)
495- . is_err ( )
496- {
497- log_txn ( TxnExecutionResult :: MaxGasUsageExceeded ) ;
498- best_txs. mark_invalid ( tx. signer ( ) , tx. nonce ( ) ) ;
499- continue ;
500- }
501-
502506 info. cumulative_gas_used += gas_used;
503507 // record tx da size
504508 info. cumulative_da_bytes_used += tx_da_size;
0 commit comments