11use alloy_consensus:: { Eip658Value , Transaction , TxEip1559 } ;
2- use alloy_eips:: Typed2718 ;
2+ use alloy_eips:: { Encodable2718 , Typed2718 } ;
33use alloy_op_evm:: block:: receipt_builder:: OpReceiptBuilder ;
4- use alloy_primitives:: { private :: alloy_rlp :: Encodable , Address , Bytes , TxKind , U256 } ;
4+ use alloy_primitives:: { Address , Bytes , TxKind , U256 } ;
55use alloy_rpc_types_eth:: Withdrawals ;
66use core:: fmt:: Debug ;
77use op_alloy_consensus:: { OpDepositReceipt , OpTypedTransaction } ;
@@ -19,6 +19,7 @@ use reth_optimism_forks::OpHardforks;
1919use reth_optimism_node:: OpPayloadBuilderAttributes ;
2020use reth_optimism_payload_builder:: { config:: OpDAConfig , error:: OpPayloadBuilderError } ;
2121use reth_optimism_primitives:: { OpReceipt , OpTransactionSigned } ;
22+ use reth_optimism_txpool:: estimated_da_size:: DataAvailabilitySized ;
2223use reth_payload_builder:: PayloadId ;
2324use reth_primitives:: { Recovered , SealedHeader } ;
2425use reth_primitives_traits:: { InMemorySize , SignedTransaction } ;
@@ -329,11 +330,18 @@ impl OpPayloadBuilderCtx {
329330
330331 while let Some ( tx) = best_txs. next ( ( ) ) {
331332 let exclude_reverting_txs = tx. exclude_reverting_txs ( ) ;
333+ let tx_da_size = tx. estimated_da_size ( ) ;
332334
333335 let tx = tx. into_consensus ( ) ;
334336 num_txs_considered += 1 ;
335337 // ensure we still have capacity for this transaction
336- if info. is_tx_over_limits ( tx. inner ( ) , block_gas_limit, tx_da_limit, block_da_limit) {
338+ if info. is_tx_over_limits (
339+ tx_da_size,
340+ block_gas_limit,
341+ tx_da_limit,
342+ block_da_limit,
343+ tx. gas_limit ( ) ,
344+ ) {
337345 // we can't fit this transaction into the block, so we need to mark it as
338346 // invalid which also removes all dependent transaction from
339347 // the iterator before we can continue
@@ -394,6 +402,8 @@ impl OpPayloadBuilderCtx {
394402 // receipt
395403 let gas_used = result. gas_used ( ) ;
396404 info. cumulative_gas_used += gas_used;
405+ // record tx da size
406+ info. cumulative_da_bytes_used += tx_da_size;
397407
398408 // Push transaction changeset and calculate header bloom filter for receipt.
399409 let ctx = ReceiptBuilderCtx {
@@ -498,7 +508,7 @@ impl OpPayloadBuilderCtx {
498508 db : & mut State < DB > ,
499509 builder_tx_gas : u64 ,
500510 message : Vec < u8 > ,
501- ) -> Option < usize >
511+ ) -> Option < u64 >
502512 where
503513 DB : Database < Error = ProviderError > ,
504514 {
@@ -509,7 +519,9 @@ impl OpPayloadBuilderCtx {
509519 // Create and sign the transaction
510520 let builder_tx =
511521 signed_builder_tx ( db, builder_tx_gas, message, signer, base_fee, chain_id) ?;
512- Ok ( builder_tx. length ( ) )
522+ Ok ( op_alloy_flz:: tx_estimated_size_fjord (
523+ builder_tx. encoded_2718 ( ) . as_slice ( ) ,
524+ ) )
513525 } )
514526 . transpose ( )
515527 . unwrap_or_else ( |err : PayloadBuilderError | {
0 commit comments