Skip to content

Commit 3e9ffeb

Browse files
author
Solar Mithril
authored
Add another builder tx after the first flashblock (#121)
* Add another builder tx after the first flashblock * Fix fb test
1 parent 2397b4f commit 3e9ffeb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ where
324324
);
325325
let flashblock_build_start_time = Instant::now();
326326
let state = StateProviderDatabase::new(&state_provider);
327+
invoke_on_first_flashblock(flashblock_count, || {
328+
total_gas_per_batch -= builder_tx_gas;
329+
// saturating sub just in case, we will log an error if da_limit too small for builder_tx_da_size
330+
if let Some(da_limit) = total_da_per_batch.as_mut() {
331+
*da_limit = da_limit.saturating_sub(builder_tx_da_size);
332+
}
333+
});
327334
invoke_on_last_flashblock(flashblock_count, last_flashblock, || {
328335
total_gas_per_batch -= builder_tx_gas;
329336
// saturating sub just in case, we will log an error if da_limit too small for builder_tx_da_size
@@ -367,6 +374,11 @@ where
367374
return Ok(());
368375
}
369376

377+
// TODO: temporary we add builder tx to the first flashblock too
378+
invoke_on_first_flashblock(flashblock_count, || {
379+
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
380+
});
381+
370382
// If it is the last flashblocks, add the builder txn to the block if enabled
371383
invoke_on_last_flashblock(flashblock_count, last_flashblock, || {
372384
ctx.add_builder_tx(&mut info, &mut db, builder_tx_gas, message.clone());
@@ -689,6 +701,12 @@ where
689701
))
690702
}
691703

704+
pub fn invoke_on_first_flashblock<F: FnOnce()>(current_flashblock: u64, fun: F) {
705+
if current_flashblock == 0 {
706+
fun()
707+
}
708+
}
709+
692710
pub fn invoke_on_last_flashblock<F: FnOnce()>(
693711
current_flashblock: u64,
694712
flashblock_limit: u64,

crates/op-rbuilder/src/tests/flashblocks/smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async fn chain_produces_blocks() -> eyre::Result<()> {
4949
}
5050

5151
let generated_block = generator.generate_block().await?;
52-
assert_eq!(generated_block.num_transactions(), 7); // 5 normal txn + deposit + builder txn
52+
assert_eq!(generated_block.num_transactions(), 8); // 5 normal txn + deposit + 2 builder txn
5353

5454
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
5555
}

0 commit comments

Comments
 (0)