Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 10 additions & 18 deletions crates/op-rbuilder/src/builder/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use tracing::{debug, info, warn};
use crate::{
builder::{StateRootCalculator, payload::FlashblocksState, state_root::StateRootOutput},
evm::OpBlockEvmFactory,
execution::ExecutionInfo,
hardforks::ActiveHardforks,
metrics::OpRBuilderMetrics,
primitives::reth::ExecutionInfo,
};

/// Pre-resolved parameters needed by `build_block`, decoupled from
Expand Down Expand Up @@ -296,7 +296,7 @@ impl BlockAssemblyInput {
pub(super) fn assemble<DB, P>(
self,
state: &mut State<DB>,
fb_state: Option<&mut FlashblocksState>,
fb_state: Option<&FlashblocksState>,
info: &mut ExecutionInfo,
state_root_calc: &mut StateRootCalculator,
metrics: Arc<OpRBuilderMetrics>,
Expand All @@ -316,10 +316,7 @@ impl BlockAssemblyInput {

self.check_block_number()?;

let flashblock_index_for_trace = fb_state
.as_deref()
.map(|s| s.flashblock_index())
.unwrap_or(0);
let flashblock_index_for_trace = fb_state.map(|s| s.flashblock_index()).unwrap_or(0);

// Calculate the state root (returns defaults when disabled)
let state_root_start_time = Instant::now();
Expand Down Expand Up @@ -379,10 +376,8 @@ impl BlockAssemblyInput {

let block_hash = sealed_block.hash();

let target_flashblock_count_for_trace = fb_state
.as_deref()
.map(|s| s.target_flashblock_count())
.unwrap_or(0);
let target_flashblock_count_for_trace =
fb_state.map(|s| s.target_flashblock_count()).unwrap_or(0);

info!(
target: "payload_builder",
Expand Down Expand Up @@ -450,16 +445,13 @@ impl BlockAssemblyInput {
);

// pick the new transactions from the info field and update the last flashblock index
let (new_transactions, new_receipts) = if let Some(fb_state) = fb_state {
let new_txs = fb_state.slice_new_transactions(&info.executed_transactions);
let new_receipts = fb_state.slice_new_receipts(&info.receipts);
fb_state.set_last_flashblock_tx_index(info.executed_transactions.len());
let (new_transactions, new_receipts) = if fb_state.is_some() {
let new_txs = info.new_transactions_vec();
let new_receipts = info.new_receipts_vec();
info.set_last_flashblock_tx_index();
(new_txs, new_receipts)
} else {
(
info.executed_transactions.as_slice(),
info.receipts.as_slice(),
)
(info.executed_transactions.clone(), info.receipts.clone())
};

let new_transactions_encoded: Vec<Bytes> = new_transactions
Expand Down
16 changes: 6 additions & 10 deletions crates/op-rbuilder/src/builder/builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use revm::{
use tracing::{error, trace, warn};

use crate::{
evm::OpBlockEvmFactory, hardforks::ActiveHardforks, primitives::reth::ExecutionInfo,
tx_signer::Signer,
evm::OpBlockEvmFactory, execution::ExecutionInfo, hardforks::ActiveHardforks, tx_signer::Signer,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -270,20 +269,18 @@ pub trait BuilderTransactions {
continue;
}

let tx_uncompressed_size = builder_tx.signed_tx.inner().encode_2718_len() as u64;

// Skip the builder tx if including it would push the cumulative
// uncompressed block size over the configured limit. The state
// changes from the simulation are dropped (we never call commit).
if let Some(limit) = ctx.max_uncompressed_block_size
&& info.cumulative_uncompressed_bytes + tx_uncompressed_size > limit
{
if let Err(err) = info.check_uncompressed_size_limit(
builder_tx.signed_tx.inner().encode_2718_len() as u64,
ctx.max_uncompressed_block_size,
) {
warn!(
target: "payload_builder",
tx_hash = %builder_tx.signed_tx.tx_hash(),
cumulative_uncompressed = info.cumulative_uncompressed_bytes,
tx_uncompressed_size,
limit,
%err,
"skipping builder tx: would exceed max uncompressed block size"
);
continue;
Expand All @@ -293,7 +290,6 @@ pub trait BuilderTransactions {
&builder_tx.signed_tx,
result,
state,
builder_tx.da_size,
None,
None,
ctx.evm_factory,
Expand Down
11 changes: 1 addition & 10 deletions crates/op-rbuilder/src/builder/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use crate::{
cancellation::FlashblockJobCancellation,
},
evm::OpBlockEvmFactory,
execution::{ExecutionInfo, TxnExecutionResult},
hardforks::ActiveHardforks,
limiter::AddressLimiter,
metrics::OpRBuilderMetrics,
primitives::reth::{ExecutionInfo, TxnExecutionResult},
traits::PayloadTxsBounds,
};

Expand Down Expand Up @@ -256,17 +256,10 @@ impl OpPayloadJobCtx {
}
};

let tx_da_size = if !sequencer_tx.is_deposit() {
op_alloy_flz::tx_estimated_size_fjord_bytes(sequencer_tx.encoded_2718().as_slice())
} else {
0
};

info.commit_tx(
&sequencer_tx,
result,
state,
tx_da_size,
None,
depositor_nonce,
&self.evm_factory,
Expand Down Expand Up @@ -556,7 +549,6 @@ impl OpPayloadJobCtx {
&tx,
result,
state,
tx_da_size,
Some(miner_fee),
None,
&self.evm_factory,
Expand Down Expand Up @@ -801,7 +793,6 @@ impl OpPayloadJobCtx {
&bundle.backrun_tx,
br_result,
br_state,
br_tx_da_size,
Some(backrun_priority_fee),
None,
&self.evm_factory,
Expand Down
2 changes: 1 addition & 1 deletion crates/op-rbuilder/src/builder/flashblocks_builder_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
builder_tx::{BuilderTxBase, BuilderTxEnv},
get_nonce,
},
execution::ExecutionInfo,
flashtestations::builder_tx::FlashtestationsBuilderTx,
primitives::reth::ExecutionInfo,
tx_signer::Signer,
};

Expand Down
41 changes: 10 additions & 31 deletions crates/op-rbuilder/src/builder/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{
timing::{FlashblockScheduler, compute_slot_offset_ms},
},
evm::OpBlockEvmFactory,
execution::ExecutionInfo,
hardforks::ActiveHardforks,
limiter::AddressLimiter,
metrics::{OpRBuilderMetrics, record_flashblock_publish_timing},
primitives::reth::ExecutionInfo,
runtime_ext::RuntimeExt,
tokio_metrics::FlashblocksTaskMetrics,
traits::{ClientBounds, PoolBounds},
Expand All @@ -24,7 +24,7 @@ use reth_chainspec::EthChainSpec;
use reth_node_api::PayloadBuilderError;
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
use reth_optimism_node::{OpBuiltPayload, OpPayloadBuilderAttributes};
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
use reth_optimism_primitives::OpTransactionSigned;
use reth_payload_primitives::PayloadBuilderAttributes;
use reth_payload_util::BestPayloadTransactions;
use reth_provider::{
Expand Down Expand Up @@ -76,9 +76,6 @@ pub(super) struct FlashblocksState {
da_per_batch: Option<u64>,
/// DA footprint limit per flashblock
da_footprint_per_batch: Option<u64>,
/// Index into ExecutionInfo tracking the last consumed flashblock
/// Used for slicing transactions/receipts per flashblock
last_flashblock_tx_index: usize,
}

struct FallbackBuildOutput<Cache, Transition> {
Expand Down Expand Up @@ -127,7 +124,6 @@ impl FlashblocksState {
gas_per_batch: self.gas_per_batch,
da_per_batch: self.da_per_batch,
da_footprint_per_batch: self.da_footprint_per_batch,
last_flashblock_tx_index: self.last_flashblock_tx_index,
}
}

Expand Down Expand Up @@ -215,23 +211,6 @@ impl FlashblocksState {
fn target_da_footprint_for_batch(&self) -> Option<u64> {
self.target_da_footprint_for_batch
}

pub(super) fn set_last_flashblock_tx_index(&mut self, index: usize) {
self.last_flashblock_tx_index = index;
}

/// Extracts new transactions since the last flashblock
pub(super) fn slice_new_transactions<'a>(
&self,
all_transactions: &'a [OpTransactionSigned],
) -> &'a [OpTransactionSigned] {
&all_transactions[self.last_flashblock_tx_index..]
}

/// Extracts new receipts since the last flashblock
pub(super) fn slice_new_receipts<'a>(&self, all_receipts: &'a [OpReceipt]) -> &'a [OpReceipt] {
&all_receipts[self.last_flashblock_tx_index..]
}
}

/// Optimism's payload builder
Expand Down Expand Up @@ -732,10 +711,10 @@ where
let mut best_txs = FlashblockPoolTxCursor::new(&mut tx_tracker);

let mut info = info;
let mut fb_state = fb_state;
let fb_state = fb_state;
let result = builder.build_next_flashblock(
&ctx,
&mut fb_state,
&fb_state,
&mut info,
&mut state,
&state_provider,
Expand Down Expand Up @@ -839,7 +818,7 @@ where
fn build_fallback_block(
&self,
ctx: OpPayloadJobCtx,
mut fb_state: FlashblocksState,
fb_state: FlashblocksState,
mut cached_reads: CachedReads,
mut state_root_calc: StateRootCalculator,
) -> eyre::Result<FallbackBuildOutput<CacheState, Option<TransitionState>>> {
Expand Down Expand Up @@ -878,7 +857,7 @@ where

let (payload, fb_payload) = ctx.block_assembly_input()?.assemble(
&mut state,
Some(&mut fb_state),
Some(&fb_state),
&mut info,
&mut state_root_calc,
ctx.metrics.clone(),
Expand Down Expand Up @@ -908,7 +887,7 @@ where
>(
&self,
ctx: &OpPayloadJobCtx,
fb_state: &mut FlashblocksState,
fb_state: &FlashblocksState,
info: &mut ExecutionInfo,
state: &mut State<DB>,
state_provider: impl reth::providers::StateProvider + Clone,
Expand Down Expand Up @@ -992,11 +971,11 @@ where
)
.wrap_err("failed to execute best transactions")?;
// Extract last transactions
let new_transactions: Vec<_> = fb_state
.slice_new_transactions(&info.executed_transactions)
let new_transactions = info
.new_transactions_vec()
.iter()
.map(|tx| tx.tx_hash())
.collect::<Vec<_>>();
.collect();
best_txs.mark_committed(new_transactions);

// Remove reverted bundle txs from the pool so they aren't re-simulated in future blocks
Expand Down
37 changes: 8 additions & 29 deletions crates/op-rbuilder/src/builder/payload_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
syncer_config::OpPayloadSyncerConfig,
},
evm::OpBlockEvmFactory,
execution::ExecutionInfo,
hardforks::ActiveHardforks,
metrics::OpRBuilderMetrics,
primitives::reth::ExecutionInfo,
traits::ClientBounds,
};
use alloy_consensus::BlockHeader;
Expand Down Expand Up @@ -412,42 +412,21 @@ fn execute_transactions(
));
}

let new_cumulative_gas = info
.cumulative_gas_used
.checked_add(tx_gas_used)
.ok_or_else(|| {
eyre::eyre!("total gas used overflowed when executing flashblock transactions")
})?;
if new_cumulative_gas > gas_limit {
bail!("flashblock exceeded gas limit when executing transactions");
if let Err(err) = info.check_gas_limit(tx_gas_used, gas_limit) {
bail!("{err}");
}

let tx_uncompressed_size = tx_recovered.encode_2718_len() as u64;
let _new_cumulative_uncompressed = info
.cumulative_uncompressed_bytes
.checked_add(tx_uncompressed_size)
.ok_or_else(|| {
eyre::eyre!(
"total uncompressed bytes overflowed when executing flashblock transactions"
)
})?;
if let Some(limit) = max_uncompressed_block_size
&& info.cumulative_uncompressed_bytes > limit
{
bail!("flashblock exceeded max uncompressed block size when executing transactions");
if let Err(err) = info.check_uncompressed_size_limit(
tx_recovered.encode_2718_len() as u64,
max_uncompressed_block_size,
) {
bail!("{err}");
}

let tx_da_size = if !tx_recovered.is_deposit() {
op_alloy_flz::tx_estimated_size_fjord_bytes(tx_recovered.encoded_2718().as_slice())
} else {
0
};

info.commit_tx(
&tx_recovered,
result,
state,
tx_da_size,
None,
depositor_nonce,
evm_factory,
Expand Down
Loading
Loading