Skip to content

Commit 40aebe7

Browse files
committed
Move builder tx right after deposits and put it into base flashblock
1 parent 4f1931b commit 40aebe7

File tree

1 file changed

+12
-19
lines changed
  • crates/op-rbuilder/src/builders/flashblocks

1 file changed

+12
-19
lines changed

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ where
255255
.sequencer_tx_duration
256256
.record(sequencer_tx_start_time.elapsed());
257257

258+
// If we have payload with txpool we add first builder tx right after deposits
259+
if !ctx.attributes().no_tx_pool {
260+
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
261+
}
262+
258263
let (payload, fb_payload, mut bundle_state) = build_block(db, &ctx, &mut info)?;
259264

260265
best_payload.set(payload.clone());
@@ -316,6 +321,12 @@ where
316321
}
317322
let mut total_da_per_batch = da_per_batch;
318323

324+
// Account for already included builder tx
325+
total_gas_per_batch = total_gas_per_batch.saturating_sub(builder_tx_gas);
326+
if let Some(da_limit) = total_da_per_batch.as_mut() {
327+
*da_limit = da_limit.saturating_sub(builder_tx_da_size);
328+
}
329+
319330
// TODO: we should account for a case when we will issue only 1 flashblock
320331
let last_flashblock = flashblocks_per_block.saturating_sub(1);
321332

@@ -430,15 +441,8 @@ where
430441
);
431442
let flashblock_build_start_time = Instant::now();
432443
let state = StateProviderDatabase::new(&state_provider);
433-
invoke_on_first_flashblock(flashblock_count, || {
434-
total_gas_per_batch -= builder_tx_gas;
435-
// saturating sub just in case, we will log an error if da_limit too small for builder_tx_da_size
436-
if let Some(da_limit) = total_da_per_batch.as_mut() {
437-
*da_limit = da_limit.saturating_sub(builder_tx_da_size);
438-
}
439-
});
440444
invoke_on_last_flashblock(flashblock_count, last_flashblock, || {
441-
total_gas_per_batch -= builder_tx_gas;
445+
total_gas_per_batch = total_gas_per_batch.saturating_sub(builder_tx_gas);
442446
// saturating sub just in case, we will log an error if da_limit too small for builder_tx_da_size
443447
if let Some(da_limit) = total_da_per_batch.as_mut() {
444448
*da_limit = da_limit.saturating_sub(builder_tx_da_size);
@@ -485,11 +489,6 @@ where
485489
.payload_tx_simulation_duration
486490
.record(tx_execution_start_time.elapsed());
487491

488-
// TODO: temporary we add builder tx to the first flashblock too
489-
invoke_on_first_flashblock(flashblock_count, || {
490-
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
491-
});
492-
493492
// If it is the last flashblocks, add the builder txn to the block if enabled
494493
invoke_on_last_flashblock(flashblock_count, last_flashblock, || {
495494
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
@@ -852,12 +851,6 @@ where
852851
))
853852
}
854853

855-
pub fn invoke_on_first_flashblock<F: FnOnce()>(current_flashblock: u64, fun: F) {
856-
if current_flashblock == 0 {
857-
fun()
858-
}
859-
}
860-
861854
pub fn invoke_on_last_flashblock<F: FnOnce()>(
862855
current_flashblock: u64,
863856
flashblock_limit: u64,

0 commit comments

Comments
 (0)