From d043ba2f57f691141945ee66616d6a3c403d5e8b Mon Sep 17 00:00:00 2001 From: Farukest Date: Wed, 14 Jan 2026 14:42:46 +0300 Subject: [PATCH 1/3] chore(builder): remove flashblocks extra context Remove FlashblocksExtraCtx struct and inline its fields directly into OpPayloadBuilderCtx. This simplifies the code by eliminating an unnecessary layer of indirection. - Move all FlashblocksExtraCtx fields into OpPayloadBuilderCtx - Replace with_extra_ctx() with with_next_targets() - Update all ctx.extra.xxx usages to ctx.xxx - Return tuple instead of struct from build_next_flashblock() - Remove redundant flashblock_index() and target_flashblock_count() getters Closes #443 --- .../op-rbuilder/src/flashblocks/context.rs | 83 +++++-------- .../op-rbuilder/src/flashblocks/ctx.rs | 14 ++- .../op-rbuilder/src/flashblocks/mod.rs | 2 +- .../op-rbuilder/src/flashblocks/payload.rs | 114 ++++++++++-------- 4 files changed, 110 insertions(+), 103 deletions(-) diff --git a/crates/builder/op-rbuilder/src/flashblocks/context.rs b/crates/builder/op-rbuilder/src/flashblocks/context.rs index 95ed07ba..d23e654f 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/context.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/context.rs @@ -49,45 +49,6 @@ use crate::{ tx_data_store::{TxData, TxDataStore}, }; -#[derive(Debug, Default, Clone)] -pub struct FlashblocksExtraCtx { - /// Current flashblock index - pub flashblock_index: u64, - /// Target flashblock count per block - pub target_flashblock_count: u64, - /// Total gas left for the current flashblock - pub target_gas_for_batch: u64, - /// Total DA bytes left for the current flashblock - pub target_da_for_batch: Option, - /// Total DA footprint left for the current flashblock - pub target_da_footprint_for_batch: Option, - /// Gas limit per flashblock - pub gas_per_batch: u64, - /// DA bytes limit per flashblock - pub da_per_batch: Option, - /// DA footprint limit per flashblock - pub da_footprint_per_batch: Option, - /// Whether to disable state root calculation for each flashblock - pub disable_state_root: bool, -} - -impl FlashblocksExtraCtx { - pub const fn next( - self, - target_gas_for_batch: u64, - target_da_for_batch: Option, - target_da_footprint_for_batch: Option, - ) -> Self { - Self { - flashblock_index: self.flashblock_index + 1, - target_gas_for_batch, - target_da_for_batch, - target_da_footprint_for_batch, - ..self - } - } -} - /// Container type that holds all necessities to build a new payload. #[derive(Debug)] pub struct OpPayloadBuilderCtx { @@ -109,8 +70,24 @@ pub struct OpPayloadBuilderCtx { pub cancel: CancellationToken, /// The metrics for the builder pub metrics: Arc, - /// Extra context for the payload builder - pub extra: FlashblocksExtraCtx, + /// Current flashblock index + pub flashblock_index: u64, + /// Target flashblock count per block + pub target_flashblock_count: u64, + /// Total gas left for the current flashblock + pub target_gas_for_batch: u64, + /// Total DA bytes left for the current flashblock + pub target_da_for_batch: Option, + /// Total DA footprint left for the current flashblock + pub target_da_footprint_for_batch: Option, + /// Gas limit per flashblock + pub gas_per_batch: u64, + /// DA bytes limit per flashblock + pub da_per_batch: Option, + /// DA footprint limit per flashblock + pub da_footprint_per_batch: Option, + /// Whether to disable state root calculation for each flashblock + pub disable_state_root: bool, /// Max gas that can be used by a transaction. pub max_gas_per_txn: Option, /// Rate limiting based on gas. This is an optional feature. @@ -124,16 +101,20 @@ impl OpPayloadBuilderCtx { Self { cancel, ..self } } - pub(super) fn with_extra_ctx(self, extra: FlashblocksExtraCtx) -> Self { - Self { extra, ..self } - } - - pub(crate) const fn flashblock_index(&self) -> u64 { - self.extra.flashblock_index - } - - pub(crate) const fn target_flashblock_count(&self) -> u64 { - self.extra.target_flashblock_count + /// Updates the target fields for the next flashblock iteration. + pub(super) fn with_next_targets( + self, + target_gas_for_batch: u64, + target_da_for_batch: Option, + target_da_footprint_for_batch: Option, + ) -> Self { + Self { + flashblock_index: self.flashblock_index + 1, + target_gas_for_batch, + target_da_for_batch, + target_da_footprint_for_batch, + ..self + } } /// Returns the parent block the payload will be build on. diff --git a/crates/builder/op-rbuilder/src/flashblocks/ctx.rs b/crates/builder/op-rbuilder/src/flashblocks/ctx.rs index f4490f8b..b4186b85 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/ctx.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/ctx.rs @@ -14,8 +14,8 @@ use reth_optimism_primitives::OpTransactionSigned; use tokio_util::sync::CancellationToken; use crate::{ - flashblocks::{BuilderConfig, FlashblocksExtraCtx, OpPayloadBuilderCtx}, - gas_limiter::AddressGasLimiter, + flashblocks::{BuilderConfig, OpPayloadBuilderCtx}, + gas_limiter::{AddressGasLimiter}, metrics::OpRBuilderMetrics, traits::ClientBounds, tx_data_store::TxDataStore, @@ -85,7 +85,15 @@ impl OpPayloadSyncerCtx { block_env_attributes, cancel, metrics: self.metrics, - extra: FlashblocksExtraCtx::default(), + flashblock_index: 0, + target_flashblock_count: 0, + target_gas_for_batch: 0, + target_da_for_batch: None, + target_da_footprint_for_batch: None, + gas_per_batch: 0, + da_per_batch: None, + da_footprint_per_batch: None, + disable_state_root: false, max_gas_per_txn: self.max_gas_per_txn, address_gas_limiter: AddressGasLimiter::new(GasLimiterArgs::default()), tx_data_store: self.tx_data_store, diff --git a/crates/builder/op-rbuilder/src/flashblocks/mod.rs b/crates/builder/op-rbuilder/src/flashblocks/mod.rs index 2a2ba5d7..a7c7c793 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/mod.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/mod.rs @@ -16,7 +16,7 @@ pub(crate) mod service; pub(crate) mod wspub; pub use config::FlashblocksConfig; -pub use context::{FlashblocksExtraCtx, OpPayloadBuilderCtx}; +pub use context::OpPayloadBuilderCtx; pub use payload::FlashblocksExecutionInfo; pub use service::FlashblocksServiceBuilder; diff --git a/crates/builder/op-rbuilder/src/flashblocks/payload.rs b/crates/builder/op-rbuilder/src/flashblocks/payload.rs index 75bd445b..f82b5cf8 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/payload.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/payload.rs @@ -45,7 +45,7 @@ use tracing::{debug, error, info, metadata::Level, span, warn}; use super::wspub::WebSocketPublisher; use crate::{ flashblocks::{ - BuilderConfig, FlashblocksExtraCtx, + BuilderConfig, best_txs::BestFlashblocksTxs, config::FlashBlocksConfigExt, context::OpPayloadBuilderCtx, @@ -147,13 +147,22 @@ where Pool: PoolBounds, Client: ClientBounds, { + #[allow(clippy::too_many_arguments)] fn get_op_payload_builder_ctx( &self, config: reth_basic_payload_builder::PayloadConfig< OpPayloadBuilderAttributes, >, cancel: CancellationToken, - extra: FlashblocksExtraCtx, + flashblock_index: u64, + target_flashblock_count: u64, + target_gas_for_batch: u64, + target_da_for_batch: Option, + target_da_footprint_for_batch: Option, + gas_per_batch: u64, + da_per_batch: Option, + da_footprint_per_batch: Option, + disable_state_root: bool, ) -> eyre::Result { let chain_spec = self.client.chain_spec(); let timestamp = config.attributes.timestamp(); @@ -197,7 +206,15 @@ where da_config: self.config.da_config.clone(), gas_limit_config: self.config.gas_limit_config.clone(), metrics: Default::default(), - extra, + flashblock_index, + target_flashblock_count, + target_gas_for_batch, + target_da_for_batch, + target_da_footprint_for_batch, + gas_per_batch, + da_per_batch, + da_footprint_per_batch, + disable_state_root, max_gas_per_txn: self.config.max_gas_per_txn, address_gas_limiter: self.address_gas_limiter.clone(), tx_data_store: self.config.tx_data_store.clone(), @@ -235,11 +252,15 @@ where .get_op_payload_builder_ctx( config.clone(), block_cancel.clone(), - FlashblocksExtraCtx { - target_flashblock_count: self.config.flashblocks_per_block(), - disable_state_root, - ..Default::default() - }, + 0, + self.config.flashblocks_per_block(), + 0, + None, + None, + 0, + None, + None, + disable_state_root, ) .map_err(|e| PayloadBuilderError::Other(e.into()))?; @@ -306,7 +327,7 @@ where flashblocks_interval = self.config.flashblocks.interval.as_millis(), ); ctx.metrics.reduced_flashblocks_number.record( - self.config.flashblocks_per_block().saturating_sub(ctx.target_flashblock_count()) + self.config.flashblocks_per_block().saturating_sub(ctx.target_flashblock_count) as f64, ); ctx.metrics.first_flashblock_time_offset.record(first_flashblock_offset.as_millis() as f64); @@ -316,21 +337,21 @@ where let da_footprint_per_batch = info.da_footprint_scalar.map(|_| ctx.block_gas_limit() / flashblocks_per_block); - let extra = FlashblocksExtraCtx { - flashblock_index: 1, - target_flashblock_count: flashblocks_per_block, - target_gas_for_batch: gas_per_batch, - target_da_for_batch: da_per_batch, - gas_per_batch, - da_per_batch, - da_footprint_per_batch, - disable_state_root, - target_da_footprint_for_batch: da_footprint_per_batch, - }; - let mut fb_cancel = block_cancel.child_token(); let mut ctx = self - .get_op_payload_builder_ctx(config, fb_cancel.clone(), extra) + .get_op_payload_builder_ctx( + config, + fb_cancel.clone(), + 1, + flashblocks_per_block, + gas_per_batch, + da_per_batch, + da_footprint_per_batch, + gas_per_batch, + da_per_batch, + da_footprint_per_batch, + disable_state_root, + ) .map_err(|e| PayloadBuilderError::Other(e.into()))?; // Create best_transaction iterator @@ -388,7 +409,7 @@ where }; let _entered = fb_span.enter(); - if ctx.flashblock_index() > ctx.target_flashblock_count() { + if ctx.flashblock_index > ctx.target_flashblock_count { self.record_flashblocks_metrics( &ctx, &info, @@ -427,7 +448,7 @@ where error!( target: "payload_builder", "Failed to build flashblock {} for block number {}: {}", - ctx.flashblock_index(), + ctx.flashblock_index, ctx.block_number(), err ); @@ -437,7 +458,8 @@ where tokio::select! { Some(fb_cancel) = rx.recv() => { - ctx = ctx.with_cancel(fb_cancel).with_extra_ctx(next_flashblocks_ctx); + let (target_gas, target_da, target_da_footprint) = next_flashblocks_ctx; + ctx = ctx.with_cancel(fb_cancel).with_next_targets(target_gas, target_da, target_da_footprint); }, _ = block_cancel.cancelled() => { self.record_flashblocks_metrics( @@ -453,6 +475,8 @@ where } } + /// Returns `Ok(Some((target_gas, target_da, target_da_footprint)))` for the next flashblock, + /// or `Ok(None)` if building should stop. #[allow(clippy::too_many_arguments)] async fn build_next_flashblock< DB: Database + std::fmt::Debug + AsRef

, @@ -466,11 +490,11 @@ where block_cancel: &CancellationToken, best_payload: &BlockCell, span: &tracing::Span, - ) -> eyre::Result> { - let flashblock_index = ctx.flashblock_index(); - let target_gas_for_batch = ctx.extra.target_gas_for_batch; - let mut target_da_for_batch = ctx.extra.target_da_for_batch; - let mut target_da_footprint_for_batch = ctx.extra.target_da_footprint_for_batch; + ) -> eyre::Result, Option)>> { + let flashblock_index = ctx.flashblock_index; + let target_gas_for_batch = ctx.target_gas_for_batch; + let mut target_da_for_batch = ctx.target_da_for_batch; + let mut target_da_footprint_for_batch = ctx.target_da_footprint_for_batch; info!( target: "payload_builder", @@ -518,7 +542,7 @@ where self.record_flashblocks_metrics( ctx, info, - ctx.target_flashblock_count(), + ctx.target_flashblock_count, span, "Payload building complete, channel closed or job cancelled", ); @@ -536,7 +560,7 @@ where state, ctx, info, - !ctx.extra.disable_state_root || ctx.attributes().no_tx_pool, + !ctx.disable_state_root || ctx.attributes().no_tx_pool, ); let total_block_built_duration = total_block_built_duration.elapsed(); ctx.metrics.total_block_built_duration.record(total_block_built_duration); @@ -557,7 +581,7 @@ where self.record_flashblocks_metrics( ctx, info, - ctx.target_flashblock_count(), + ctx.target_flashblock_count, span, "Payload building complete, channel closed or job cancelled", ); @@ -581,7 +605,7 @@ where .record(info.executed_transactions.len() as f64); // Update bundle_state for next iteration - if let Some(da_limit) = ctx.extra.da_per_batch { + if let Some(da_limit) = ctx.da_per_batch { if let Some(da) = target_da_for_batch.as_mut() { *da += da_limit; } else { @@ -591,30 +615,24 @@ where } } - let target_gas_for_batch = ctx.extra.target_gas_for_batch + ctx.extra.gas_per_batch; + let next_target_gas_for_batch = ctx.target_gas_for_batch + ctx.gas_per_batch; if let (Some(footprint), Some(da_footprint_limit)) = - (target_da_footprint_for_batch.as_mut(), ctx.extra.da_footprint_per_batch) + (target_da_footprint_for_batch.as_mut(), ctx.da_footprint_per_batch) { *footprint += da_footprint_limit; } - let next_extra = ctx.extra.clone().next( - target_gas_for_batch, - target_da_for_batch, - target_da_footprint_for_batch, - ); - info!( target: "payload_builder", message = "Flashblock built", flashblock_index = flashblock_index, current_gas = info.cumulative_gas_used, current_da = info.cumulative_da_bytes_used, - target_flashblocks = ctx.target_flashblock_count(), + target_flashblocks = ctx.target_flashblock_count, ); - Ok(Some(next_extra)) + Ok(Some((next_target_gas_for_batch, target_da_for_batch, target_da_footprint_for_batch))) } } } @@ -629,10 +647,10 @@ where message: &str, ) { ctx.metrics.block_built_success.increment(1); - ctx.metrics.flashblock_count.record(ctx.flashblock_index() as f64); + ctx.metrics.flashblock_count.record(ctx.flashblock_index as f64); ctx.metrics .missing_flashblocks_count - .record(flashblocks_per_block.saturating_sub(ctx.flashblock_index()) as f64); + .record(flashblocks_per_block.saturating_sub(ctx.flashblock_index) as f64); ctx.metrics.payload_num_tx.record(info.executed_transactions.len() as f64); ctx.metrics.payload_num_tx_gauge.set(info.executed_transactions.len() as f64); @@ -640,10 +658,10 @@ where target: "payload_builder", message = message, flashblocks_per_block = flashblocks_per_block, - flashblock_index = ctx.flashblock_index(), + flashblock_index = ctx.flashblock_index, ); - span.record("flashblock_count", ctx.flashblock_index()); + span.record("flashblock_count", ctx.flashblock_index); } /// Calculate number of flashblocks. From 0548bb8f999aa192bcd89fea52d0ff6a99b15d04 Mon Sep 17 00:00:00 2001 From: Haardik H Date: Thu, 15 Jan 2026 22:52:06 +0530 Subject: [PATCH 2/3] clippy --- .../builder/op-rbuilder/src/flashblocks/ctx.rs | 2 +- .../op-rbuilder/src/flashblocks/payload.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/builder/op-rbuilder/src/flashblocks/ctx.rs b/crates/builder/op-rbuilder/src/flashblocks/ctx.rs index b4186b85..41dd5f7a 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/ctx.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/ctx.rs @@ -15,7 +15,7 @@ use tokio_util::sync::CancellationToken; use crate::{ flashblocks::{BuilderConfig, OpPayloadBuilderCtx}, - gas_limiter::{AddressGasLimiter}, + gas_limiter::AddressGasLimiter, metrics::OpRBuilderMetrics, traits::ClientBounds, tx_data_store::TxDataStore, diff --git a/crates/builder/op-rbuilder/src/flashblocks/payload.rs b/crates/builder/op-rbuilder/src/flashblocks/payload.rs index f82b5cf8..fcd87b73 100644 --- a/crates/builder/op-rbuilder/src/flashblocks/payload.rs +++ b/crates/builder/op-rbuilder/src/flashblocks/payload.rs @@ -327,8 +327,7 @@ where flashblocks_interval = self.config.flashblocks.interval.as_millis(), ); ctx.metrics.reduced_flashblocks_number.record( - self.config.flashblocks_per_block().saturating_sub(ctx.target_flashblock_count) - as f64, + self.config.flashblocks_per_block().saturating_sub(ctx.target_flashblock_count) as f64, ); ctx.metrics.first_flashblock_time_offset.record(first_flashblock_offset.as_millis() as f64); let gas_per_batch = ctx.block_gas_limit() / flashblocks_per_block; @@ -556,12 +555,8 @@ where ctx.metrics.payload_transaction_simulation_gauge.set(payload_transaction_simulation_time); let total_block_built_duration = Instant::now(); - let build_result = build_block( - state, - ctx, - info, - !ctx.disable_state_root || ctx.attributes().no_tx_pool, - ); + let build_result = + build_block(state, ctx, info, !ctx.disable_state_root || ctx.attributes().no_tx_pool); let total_block_built_duration = total_block_built_duration.elapsed(); ctx.metrics.total_block_built_duration.record(total_block_built_duration); ctx.metrics.total_block_built_gauge.set(total_block_built_duration); @@ -632,7 +627,11 @@ where target_flashblocks = ctx.target_flashblock_count, ); - Ok(Some((next_target_gas_for_batch, target_da_for_batch, target_da_footprint_for_batch))) + Ok(Some(( + next_target_gas_for_batch, + target_da_for_batch, + target_da_footprint_for_batch, + ))) } } } From 4e932a8b9168ad0c398931b8787b4ea9a72d3137 Mon Sep 17 00:00:00 2001 From: Haardik H Date: Thu, 15 Jan 2026 23:33:37 +0530 Subject: [PATCH 3/3] remove serde_yaml --- Cargo.lock | 20 -------------------- Cargo.toml | 1 - crates/builder/op-rbuilder/Cargo.toml | 1 - 3 files changed, 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 408da8bb..5b5143d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7410,7 +7410,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serde_yaml", "sha3", "shellexpand", "tar", @@ -12833,19 +12832,6 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.13.0", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "serdect" version = "0.2.0" @@ -14259,12 +14245,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "unsigned-varint" version = "0.7.2" diff --git a/Cargo.toml b/Cargo.toml index 701a48d9..bbb4a343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -269,7 +269,6 @@ anyhow = "1" url = "2.5.7" lru = "0.16.3" rand = "0.9.2" -serde_yaml = "0.9" shellexpand = "3.1" strum = "0.27.2" backon = "1.6.0" diff --git a/crates/builder/op-rbuilder/Cargo.toml b/crates/builder/op-rbuilder/Cargo.toml index 623bf556..b93dca4e 100644 --- a/crates/builder/op-rbuilder/Cargo.toml +++ b/crates/builder/op-rbuilder/Cargo.toml @@ -126,7 +126,6 @@ tokio-tungstenite.workspace = true rand.workspace = true tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } shellexpand.workspace = true -serde_yaml.workspace = true moka.workspace = true http.workspace = true sha3.workspace = true