Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/op-rbuilder/src/builders/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ impl OpPayloadBuilderCtx {
}

/// Calculates EIP 2718 builder transaction size
// TODO: this function could be improved, ideally we shouldn't take mut ref to db and maybe
// it's possible to do this without db at all
pub fn estimate_builder_tx_da_size<DB>(
&self,
db: &mut State<DB>,
Expand Down
39 changes: 26 additions & 13 deletions crates/op-rbuilder/src/builders/flashblocks/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,29 @@ where
.with_bundle_update()
.build();

// We subtract gas limit and da limit for builder transaction from the whole limit
// TODO: we could optimise this and subtract this only for the last flashblocks
let message = format!("Block Number: {}", ctx.block_number())
.as_bytes()
.to_vec();
let builder_tx_gas = ctx
.builder_signer()
.map_or(0, |_| estimate_gas_for_builder_tx(message.clone()));
let builder_tx_da_size = ctx
.estimate_builder_tx_da_size(&mut db, builder_tx_gas, message.clone())
.unwrap_or(0);
let adjusted_block_gas_limit = ctx.block_gas_limit() - builder_tx_gas;
let adjusted_max_da_block_limit = ctx
.da_config
.max_da_block_size()
.map(|da_limit| {
let da_limit = da_limit.saturating_sub(builder_tx_da_size);
if da_limit == 0 {
error!("Builder tx da size subtraction caused max_da_block_size to be 0. No transaction would be included.");
}
da_limit
});

let mut info = execute_pre_steps(&mut db, &ctx)?;
ctx.metrics
.sequencer_tx_duration
Expand Down Expand Up @@ -219,12 +242,9 @@ where
// return early since we don't need to build a block with transactions from the pool
return Ok(());
}

let gas_per_batch = ctx.block_gas_limit() / self.config.flashblocks_per_block();
let gas_per_batch = adjusted_block_gas_limit / self.config.flashblocks_per_block();
let mut total_gas_per_batch = gas_per_batch;
let da_per_batch = ctx
.da_config
.max_da_block_size()
let da_per_batch = adjusted_max_da_block_limit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are adjusting every flashblock for a builder txn, but only the last one has a builder txn

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i wrote TODO for this
but could implement it straight away

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great in the scope of this PR.

.map(|da_limit| da_limit / self.config.flashblocks_per_block());
let mut total_da_per_batch = da_per_batch;

Expand Down Expand Up @@ -257,13 +277,6 @@ where
}
});

let message = format!("Block Number: {}", ctx.block_number())
.as_bytes()
.to_vec();
let builder_tx_gas = ctx
.builder_signer()
.map_or(0, |_| estimate_gas_for_builder_tx(message.clone()));

// Process flashblocks in a blocking loop
loop {
// Block on receiving a message, break on cancellation or closed channel
Expand Down Expand Up @@ -331,7 +344,7 @@ where
&mut info,
&mut db,
best_txs,
total_gas_per_batch.min(ctx.block_gas_limit()),
total_gas_per_batch.min(adjusted_block_gas_limit),
total_da_per_batch,
)?;
ctx.metrics
Expand Down
8 changes: 4 additions & 4 deletions crates/op-rbuilder/src/builders/standard/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
let block_da_limit = ctx
.da_config
.max_da_block_size()
.map(|da_size| {
let da_size = da_size.saturating_sub(builder_tx_da_size);
if da_size == 0 {
.map(|da_limit| {
let da_limit = da_limit.saturating_sub(builder_tx_da_size);
if da_limit == 0 {
error!("Builder tx da size subtraction caused max_da_block_size to be 0. No transaction would be included.");
}
da_size
da_limit
});

if !ctx.attributes().no_tx_pool {
Expand Down
Loading