@@ -4,7 +4,7 @@ use super::ScrollPayloadBuilderError;
44use crate :: config:: { PayloadBuildingBreaker , ScrollBuilderConfig } ;
55
66use alloy_consensus:: { Transaction , Typed2718 } ;
7- use alloy_primitives:: { B256 , U256 } ;
7+ use alloy_primitives:: U256 ;
88use alloy_rlp:: Encodable ;
99use core:: fmt:: Debug ;
1010use reth_basic_payload_builder:: {
@@ -22,9 +22,7 @@ use reth_execution_types::ExecutionOutcome;
2222use reth_payload_builder:: PayloadId ;
2323use reth_payload_primitives:: { PayloadBuilderAttributes , PayloadBuilderError } ;
2424use reth_payload_util:: { BestPayloadTransactions , NoopPayloadTransactions , PayloadTransactions } ;
25- use reth_primitives_traits:: {
26- NodePrimitives , RecoveredBlock , SealedHeader , SignedTransaction , TxTy ,
27- } ;
25+ use reth_primitives_traits:: { RecoveredBlock , SealedHeader , SignedTransaction , TxTy } ;
2826use reth_revm:: { cancelled:: CancelOnDrop , database:: StateProviderDatabase , db:: State } ;
2927use reth_scroll_chainspec:: { ChainConfig , ScrollChainConfig } ;
3028use reth_scroll_engine_primitives:: { ScrollBuiltPayload , ScrollPayloadBuilderAttributes } ;
@@ -437,6 +435,8 @@ where
437435 builder : & mut impl BlockBuilder < Primitives = Evm :: Primitives > ,
438436 ) -> Result < ExecutionInfo , PayloadBuilderError > {
439437 let mut info = ExecutionInfo :: new ( ) ;
438+ let block_gas_limit = builder. evm ( ) . block ( ) . gas_limit ;
439+ let mut gas_spent_by_transactions = Vec :: new ( ) ;
440440
441441 for sequencer_tx in & self . attributes ( ) . transactions {
442442 // A sequencer's block should never contain blob transactions.
@@ -445,7 +445,6 @@ where
445445 ScrollPayloadBuilderError :: BlobTransactionRejected ,
446446 ) )
447447 }
448-
449448 // Convert the transaction to a [RecoveredTx]. This is
450449 // purely for the purposes of utilizing the `evm_config.tx_env`` function.
451450 // Deposit transactions do not have signatures, so if the tx is a deposit, this
@@ -454,6 +453,18 @@ where
454453 PayloadBuilderError :: other ( ScrollPayloadBuilderError :: TransactionEcRecoverFailed )
455454 } ) ?;
456455
456+ let tx_gas = sequencer_tx. gas_limit ( ) ;
457+ // check we don't go over the block gas limit
458+ if info. cumulative_gas_used + tx_gas > block_gas_limit {
459+ gas_spent_by_transactions. push ( tx_gas) ;
460+ return Err ( PayloadBuilderError :: other (
461+ ScrollPayloadBuilderError :: BlockGasLimitExceededBySequencerTransactions {
462+ gas_spent_by_tx : gas_spent_by_transactions,
463+ gas : block_gas_limit,
464+ } ,
465+ ) ) ;
466+ }
467+
457468 let gas_used = match builder. execute_transaction ( sequencer_tx. clone ( ) ) {
458469 Ok ( gas_used) => gas_used,
459470 Err ( BlockExecutionError :: Validation ( BlockValidationError :: InvalidTx {
@@ -469,8 +480,14 @@ where
469480 }
470481 } ;
471482
472- // add gas used by the transaction to cumulative gas used, before creating the receipt
483+ // unspent gas is not refunded and not reallocated to other transactions for L1
484+ // messages.
485+ let gas_used =
486+ if sequencer_tx. is_l1_message ( ) { sequencer_tx. gas_limit ( ) } else { gas_used } ;
487+
488+ // add gas used by the transaction to cumulative gas used
473489 info. cumulative_gas_used += gas_used;
490+ gas_spent_by_transactions. push ( gas_used) ;
474491 }
475492
476493 Ok ( info)
@@ -559,19 +576,6 @@ where
559576 }
560577}
561578
562- /// Holds the state after execution
563- #[ derive( Debug ) ]
564- pub struct ExecutedPayload < N : NodePrimitives > {
565- /// Tracked execution info
566- pub info : ExecutionInfo ,
567- /// Withdrawal hash.
568- pub withdrawals_root : Option < B256 > ,
569- /// The transaction receipts.
570- pub receipts : Vec < N :: Receipt > ,
571- /// The block env used during execution.
572- pub block_env : BlockEnv ,
573- }
574-
575579/// This acts as the container for executed transactions and its byproducts (receipts, gas used)
576580#[ derive( Default , Debug ) ]
577581pub struct ExecutionInfo {
0 commit comments