Skip to content

Commit f0f410d

Browse files
author
Solar Mithril
committed
conflict changes
1 parent 8f15b79 commit f0f410d

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

crates/op-rbuilder/src/builders/context.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloy_consensus::{Eip658Value, Transaction, TxEip1559};
2-
use alloy_eips::Typed2718;
2+
use alloy_eips::{Encodable2718, Typed2718};
33
use 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};
55
use alloy_rpc_types_eth::Withdrawals;
66
use core::fmt::Debug;
77
use op_alloy_consensus::{OpDepositReceipt, OpTypedTransaction};
@@ -19,6 +19,7 @@ use reth_optimism_forks::OpHardforks;
1919
use reth_optimism_node::OpPayloadBuilderAttributes;
2020
use reth_optimism_payload_builder::{config::OpDAConfig, error::OpPayloadBuilderError};
2121
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
22+
use reth_optimism_txpool::estimated_da_size::DataAvailabilitySized;
2223
use reth_payload_builder::PayloadId;
2324
use reth_primitives::{Recovered, SealedHeader};
2425
use 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| {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ where
222222

223223
let gas_per_batch = ctx.block_gas_limit() / self.config.flashblocks_per_block();
224224
let mut total_gas_per_batch = gas_per_batch;
225-
let total_da_bytes_per_batch = ctx
225+
let da_per_batch = ctx
226226
.da_config
227227
.max_da_block_size()
228-
.map(|limit| limit / self.config.flashblocks_per_block());
228+
.map(|da_limit| da_limit / self.config.flashblocks_per_block());
229+
let mut total_da_per_batch = da_per_batch;
229230

230231
let mut flashblock_count = 0;
231232
// Create a channel to coordinate flashblock building
@@ -295,11 +296,11 @@ where
295296
// Continue with flashblock building
296297
tracing::info!(
297298
target: "payload_builder",
298-
"Building flashblock {} {}",
299+
"Building flashblock idx={} target_gas={} taget_da={}",
299300
flashblock_count,
300301
total_gas_per_batch,
302+
total_da_per_batch.unwrap_or(0),
301303
);
302-
303304
let flashblock_build_start_time = Instant::now();
304305
let state = StateProviderDatabase::new(&state_provider);
305306

@@ -324,7 +325,7 @@ where
324325
&mut db,
325326
best_txs,
326327
total_gas_per_batch.min(ctx.block_gas_limit()),
327-
total_da_bytes_per_batch,
328+
total_da_per_batch,
328329
)?;
329330
ctx.metrics
330331
.payload_tx_simulation_duration
@@ -377,6 +378,13 @@ where
377378
// Update bundle_state for next iteration
378379
bundle_state = new_bundle_state;
379380
total_gas_per_batch += gas_per_batch;
381+
if let Some(da_limit) = da_per_batch {
382+
if let Some(da) = total_da_per_batch.as_mut() {
383+
*da += da_limit;
384+
} else {
385+
error!("Builder end up in faulty invariant, if da_per_batch is set then total_da_per_batch must be set");
386+
}
387+
}
380388
flashblock_count += 1;
381389
tracing::info!(target: "payload_builder", "Flashblock {} built", flashblock_count);
382390
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,7 @@ impl<Txs: PayloadTxsBounds> OpBuilder<'_, Txs> {
355355
let block_da_limit = ctx
356356
.da_config
357357
.max_da_block_size()
358-
.map(|da_size| da_size - builder_tx_da_size as u64);
359-
// Check that it's possible to create builder tx, considering max_da_tx_size, otherwise panic
360-
if let Some(tx_da_limit) = ctx.da_config.max_da_tx_size() {
361-
// Panic indicate max_da_tx_size misconfiguration
362-
assert!(
363-
tx_da_limit >= builder_tx_da_size as u64,
364-
"The configured da_config.max_da_tx_size is too small to accommodate builder tx."
365-
);
366-
}
358+
.map(|da_size| da_size.saturating_sub(builder_tx_da_size));
367359

368360
if !ctx.attributes().no_tx_pool {
369361
let best_txs_start_time = Instant::now();

crates/op-rbuilder/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use reth_optimism_node::{
55
node::{OpAddOnsBuilder, OpPoolBuilder},
66
OpNode,
77
};
8-
use reth_optimism_payload_builder::config::OpDAConfig;
98
use reth_transaction_pool::TransactionPool;
109

1110
/// CLI argument parsing.
@@ -69,7 +68,7 @@ where
6968
cli.run(|builder, builder_args| async move {
7069
let builder_config = BuilderConfig::<B::Config>::try_from(builder_args.clone())
7170
.expect("Failed to convert rollup args to builder config");
72-
let da_config = OpDAConfig::default();
71+
let da_config = builder_config.da_config.clone();
7372
let rollup_args = builder_args.rollup_args;
7473
let op_node = OpNode::new(rollup_args.clone());
7574
let handle = builder

0 commit comments

Comments
 (0)