@@ -38,11 +38,12 @@ use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
38
38
use reth_optimism_forks:: OpHardforks ;
39
39
use reth_optimism_node:: OpEngineTypes ;
40
40
use reth_optimism_payload_builder:: {
41
+ config:: OpDAConfig ,
41
42
error:: OpPayloadBuilderError ,
42
43
payload:: { OpBuiltPayload , OpPayloadBuilderAttributes } ,
43
44
} ;
44
45
use reth_optimism_primitives:: { OpPrimitives , OpReceipt , OpTransactionSigned } ;
45
- use reth_optimism_txpool:: OpPooledTx ;
46
+ use reth_optimism_txpool:: { estimated_da_size :: DataAvailabilitySized , OpPooledTx } ;
46
47
use reth_payload_builder:: PayloadBuilderService ;
47
48
use reth_payload_builder_primitives:: PayloadBuilderError ;
48
49
use reth_payload_primitives:: PayloadBuilderAttributes ;
@@ -96,6 +97,7 @@ struct FlashblocksMetadata<N: NodePrimitives> {
96
97
pub struct CustomOpPayloadBuilder {
97
98
#[ expect( dead_code) ]
98
99
builder_signer : Option < Signer > ,
100
+ da_config : OpDAConfig ,
99
101
flashblocks_ws_url : String ,
100
102
chain_block_time : u64 ,
101
103
flashblock_block_time : u64 ,
@@ -106,12 +108,14 @@ impl CustomOpPayloadBuilder {
106
108
pub fn new (
107
109
builder_signer : Option < Signer > ,
108
110
extra_block_deadline : std:: time:: Duration ,
111
+ da_config : OpDAConfig ,
109
112
flashblocks_ws_url : String ,
110
113
chain_block_time : u64 ,
111
114
flashblock_block_time : u64 ,
112
115
) -> Self {
113
116
Self {
114
117
builder_signer,
118
+ da_config,
115
119
flashblocks_ws_url,
116
120
chain_block_time,
117
121
flashblock_block_time,
@@ -132,6 +136,7 @@ where
132
136
Pool : TransactionPool < Transaction : PoolTransaction < Consensus = TxTy < Node :: Types > > >
133
137
+ Unpin
134
138
+ ' static ,
139
+ <Pool as TransactionPool >:: Transaction : OpPooledTx ,
135
140
Evm : ConfigureEvm <
136
141
Primitives = PrimitivesTy < Node :: Types > ,
137
142
NextBlockEnvCtx = OpNextBlockEnvAttributes ,
@@ -149,6 +154,7 @@ where
149
154
OpEvmConfig :: optimism ( ctx. chain_spec ( ) ) ,
150
155
pool,
151
156
ctx. provider ( ) . clone ( ) ,
157
+ self . da_config ,
152
158
self . flashblocks_ws_url . clone ( ) ,
153
159
self . chain_block_time ,
154
160
self . flashblock_block_time ,
@@ -241,6 +247,8 @@ pub struct OpPayloadBuilder<Pool, Client> {
241
247
pub pool : Pool ,
242
248
/// Node client
243
249
pub client : Client ,
250
+ /// DA settings.
251
+ pub da_config : OpDAConfig ,
244
252
/// Channel sender for publishing messages
245
253
pub tx : mpsc:: UnboundedSender < String > ,
246
254
/// chain block time
@@ -259,6 +267,7 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
259
267
evm_config : OpEvmConfig ,
260
268
pool : Pool ,
261
269
client : Client ,
270
+ da_config : OpDAConfig ,
262
271
flashblocks_ws_url : String ,
263
272
chain_block_time : u64 ,
264
273
flashblock_block_time : u64 ,
@@ -276,6 +285,7 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
276
285
evm_config,
277
286
pool,
278
287
client,
288
+ da_config,
279
289
tx,
280
290
chain_block_time,
281
291
flashblock_block_time,
@@ -337,7 +347,8 @@ impl<Pool, Client> OpPayloadBuilder<Pool, Client> {
337
347
338
348
impl < Pool , Client > OpPayloadBuilder < Pool , Client >
339
349
where
340
- Pool : TransactionPool < Transaction : PoolTransaction < Consensus = OpTransactionSigned > > ,
350
+ Pool :
351
+ TransactionPool < Transaction : PoolTransaction < Consensus = OpTransactionSigned > + OpPooledTx > ,
341
352
Client : StateProviderFactory + ChainSpecProvider < ChainSpec : EthChainSpec + OpHardforks > ,
342
353
{
343
354
/// Send a message to be published
@@ -394,6 +405,7 @@ where
394
405
395
406
let ctx = OpPayloadBuilderCtx {
396
407
evm_config : self . evm_config . clone ( ) ,
408
+ da_config : self . da_config . clone ( ) ,
397
409
chain_spec : self . client . chain_spec ( ) ,
398
410
config,
399
411
evm_env,
@@ -443,8 +455,17 @@ where
443
455
444
456
let gas_per_batch = ctx. block_gas_limit ( ) / self . flashblocks_per_block ;
445
457
458
+ // We initially set total_gas_per_batch equal to 1 flashblocks portion and then
459
+ // add additional portions to the limit as we build more flashblocks
446
460
let mut total_gas_per_batch = gas_per_batch;
447
461
462
+ let da_per_batch = if let Some ( da_limit) = ctx. da_config . max_da_block_size ( ) {
463
+ Some ( da_limit / self . flashblocks_per_block )
464
+ } else {
465
+ None
466
+ } ;
467
+ let mut total_da_per_batch = da_per_batch;
468
+
448
469
let mut flashblock_count = 0 ;
449
470
// Create a channel to coordinate flashblock building
450
471
let ( build_tx, mut build_rx) = mpsc:: channel ( 1 ) ;
@@ -513,9 +534,10 @@ where
513
534
// Continue with flashblock building
514
535
tracing:: info!(
515
536
target: "payload_builder" ,
516
- "Building flashblock {} {}" ,
537
+ "Building flashblock idx= {} target_gas={} taget_da= {}" ,
517
538
flashblock_count,
518
539
total_gas_per_batch,
540
+ total_da_per_batch. unwrap_or( 0 ) ,
519
541
) ;
520
542
521
543
let flashblock_build_start_time = Instant :: now ( ) ;
@@ -542,6 +564,7 @@ where
542
564
& mut db,
543
565
best_txs,
544
566
total_gas_per_batch. min ( ctx. block_gas_limit ( ) ) ,
567
+ total_da_per_batch,
545
568
) ?;
546
569
ctx. metrics
547
570
. payload_tx_simulation_duration
@@ -596,6 +619,9 @@ where
596
619
// Update bundle_state for next iteration
597
620
bundle_state = new_bundle_state;
598
621
total_gas_per_batch += gas_per_batch;
622
+ if let Some ( da_limit) = da_per_batch {
623
+ total_da_per_batch. as_mut ( ) . map ( |da| * da += da_limit) ;
624
+ }
599
625
flashblock_count += 1 ;
600
626
tracing:: info!( target: "payload_builder" , "Flashblock {} built" , flashblock_count) ;
601
627
}
@@ -617,7 +643,8 @@ where
617
643
impl < Pool , Client > PayloadBuilder for OpPayloadBuilder < Pool , Client >
618
644
where
619
645
Client : StateProviderFactory + ChainSpecProvider < ChainSpec : EthChainSpec + OpHardforks > + Clone ,
620
- Pool : TransactionPool < Transaction : PoolTransaction < Consensus = OpTransactionSigned > > ,
646
+ Pool :
647
+ TransactionPool < Transaction : PoolTransaction < Consensus = OpTransactionSigned > + OpPooledTx > ,
621
648
{
622
649
type Attributes = OpPayloadBuilderAttributes < OpTransactionSigned > ;
623
650
type BuiltPayload = OpBuiltPayload ;
@@ -889,6 +916,8 @@ impl<T: PoolTransaction> OpPayloadTransactions<T> for () {
889
916
pub struct OpPayloadBuilderCtx < ChainSpec > {
890
917
/// The type that knows how to perform system calls and configure the evm.
891
918
pub evm_config : OpEvmConfig ,
919
+ /// The DA config for the payload builder
920
+ pub da_config : OpDAConfig ,
892
921
/// The chainspec
893
922
pub chain_spec : Arc < ChainSpec > ,
894
923
/// How to build the payload.
@@ -1145,9 +1174,10 @@ where
1145
1174
info : & mut ExecutionInfo < OpPrimitives > ,
1146
1175
db : & mut State < DB > ,
1147
1176
mut best_txs : impl PayloadTransactions <
1148
- Transaction : PoolTransaction < Consensus = OpTransactionSigned > ,
1177
+ Transaction : PoolTransaction < Consensus = OpTransactionSigned > + OpPooledTx ,
1149
1178
> ,
1150
1179
batch_gas_limit : u64 ,
1180
+ block_da_limit : Option < u64 > ,
1151
1181
) -> Result < Option < ( ) > , PayloadBuilderError >
1152
1182
where
1153
1183
DB : Database < Error = ProviderError > ,
@@ -1157,10 +1187,11 @@ where
1157
1187
let mut num_txs_simulated = 0 ;
1158
1188
let mut num_txs_simulated_success = 0 ;
1159
1189
let mut num_txs_simulated_fail = 0 ;
1160
-
1190
+ let tx_da_limit = self . da_config . max_da_tx_size ( ) ;
1161
1191
let mut evm = self . evm_config . evm_with_env ( & mut * db, self . evm_env . clone ( ) ) ;
1162
1192
1163
1193
while let Some ( tx) = best_txs. next ( ( ) ) {
1194
+ let tx_da_size = tx. estimated_da_size ( ) ;
1164
1195
let tx = tx. into_consensus ( ) ;
1165
1196
num_txs_considered += 1 ;
1166
1197
@@ -1170,7 +1201,13 @@ where
1170
1201
}
1171
1202
1172
1203
// ensure we still have capacity for this transaction
1173
- if info. is_tx_over_limits ( tx. inner ( ) , batch_gas_limit, None , None ) {
1204
+ if info. is_tx_over_limits (
1205
+ tx_da_size,
1206
+ batch_gas_limit,
1207
+ tx_da_limit,
1208
+ block_da_limit,
1209
+ tx. gas_limit ( ) ,
1210
+ ) {
1174
1211
// we can't fit this transaction into the block, so we need to mark it as
1175
1212
// invalid which also removes all dependent transaction from
1176
1213
// the iterator before we can continue
@@ -1227,6 +1264,8 @@ where
1227
1264
// add gas used by the transaction to cumulative gas used, before creating the receipt
1228
1265
let gas_used = result. gas_used ( ) ;
1229
1266
info. cumulative_gas_used += gas_used;
1267
+ // record tx da size
1268
+ info. cumulative_da_bytes_used += tx_da_size;
1230
1269
1231
1270
let ctx = ReceiptBuilderCtx {
1232
1271
tx : tx. inner ( ) ,
0 commit comments