From 155eea759eca7cc51b86e9edcd1551d203dfc807 Mon Sep 17 00:00:00 2001 From: refcell Date: Tue, 29 Oct 2024 12:48:37 -0400 Subject: [PATCH] feat(derive): Remove metrics (#743) * feat(derive): remove metrics * not(test) --- Cargo.lock | 58 ++++++------ crates/derive/Cargo.toml | 8 -- crates/derive/src/batch/mod.rs | 1 + .../src/batch/span_batch/transactions.rs | 1 + crates/derive/src/lib.rs | 7 +- crates/derive/src/macros.rs | 61 ------------- crates/derive/src/metrics.rs | 88 ------------------- crates/derive/src/pipeline/core.rs | 2 +- crates/derive/src/sources/calldata.rs | 1 + crates/derive/src/stages/attributes_queue.rs | 7 +- .../derive/src/stages/batch/batch_provider.rs | 2 +- crates/derive/src/stages/batch/batch_queue.rs | 33 +++---- .../derive/src/stages/batch/batch_stream.rs | 2 +- .../src/stages/batch/batch_validator.rs | 7 +- .../src/stages/channel/channel_assembler.rs | 12 +-- .../derive/src/stages/channel/channel_bank.rs | 29 +----- .../src/stages/channel/channel_provider.rs | 2 +- .../src/stages/channel/channel_reader.rs | 19 +--- crates/derive/src/stages/frame_queue.rs | 7 +- crates/derive/src/stages/l1_retrieval.rs | 4 +- crates/derive/src/stages/l1_traversal.rs | 4 - 21 files changed, 56 insertions(+), 299 deletions(-) delete mode 100644 crates/derive/src/macros.rs delete mode 100644 crates/derive/src/metrics.rs diff --git a/Cargo.lock b/Cargo.lock index d0c752307..0962f0fd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,9 +53,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy-chains" -version = "0.1.41" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60888eb8eb66f26aecf96d8a3aeb1a3a05ebc179025a7f98ed1d8051988969ac" +checksum = "c660915971620592abe2c292c859957eb60e73a60c0eba34a6793eea60512cff" dependencies = [ "alloy-primitives", "num_enum", @@ -210,9 +210,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71738eb20c42c5fb149571e76536a0f309d142f3957c28791662b96baf77a3d" +checksum = "8edae627382349b56cd6a7a2106f4fd69b243a9233e560c55c2e03cabb7e1d3c" dependencies = [ "alloy-rlp", "arbitrary", @@ -409,9 +409,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0900b83f4ee1f45c640ceee596afbc118051921b9438fdb5a3175c1a7e05f8b" +checksum = "841eabaa4710f719fddbc24c95d386eae313f07e6da4babc25830ee37945be0c" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -423,9 +423,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41b1e78dde06b5e12e6702fa8c1d30621bf07728ba75b801fb801c9c6a0ba10" +checksum = "6672337f19d837b9f7073c45853aeb528ed9f7dd6a4154ce683e9e5cb7794014" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -441,9 +441,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91dc311a561a306664393407b88d3e53ae58581624128afd8a15faa5de3627dc" +checksum = "0dff37dd20bfb118b777c96eda83b2067f4226d2644c5cfa00187b3bc01770ba" dependencies = [ "const-hex", "dunce", @@ -456,9 +456,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086f41bc6ebcd8cb15f38ba20e47be38dd03692149681ce8061c35d960dbf850" +checksum = "aa828bb1b9a6dc52208fbb18084fb9ce2c30facc2bfda6a5d922349b4990354f" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -1957,9 +1957,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-channel", @@ -2249,13 +2249,11 @@ dependencies = [ "async-trait", "brotli", "derive_more", - "lazy_static", "miniz_oxide", "op-alloy-consensus", "op-alloy-genesis", "op-alloy-protocol", "op-alloy-rpc-types-engine", - "prometheus", "proptest", "serde", "serde_json", @@ -2428,9 +2426,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "librocksdb-sys" @@ -3398,9 +3396,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.8" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64", "bytes", @@ -3672,9 +3670,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a" dependencies = [ "bitflags 2.6.0", "errno", @@ -3685,9 +3683,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.15" +version = "0.23.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" dependencies = [ "once_cell", "rustls-pki-types", @@ -3863,18 +3861,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", @@ -4183,9 +4181,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5e0c2ea8db64b2898b62ea2fbd60204ca95e0b2c6bdf53ff768bbe916fbe4d" +checksum = "16320d4a2021ba1a32470b3759676114a918885e9800e68ad60f2c67969fba62" dependencies = [ "paste", "proc-macro2", diff --git a/crates/derive/Cargo.toml b/crates/derive/Cargo.toml index 68f55f77b..58d25c22f 100644 --- a/crates/derive/Cargo.toml +++ b/crates/derive/Cargo.toml @@ -37,10 +37,6 @@ derive_more = { workspace = true, features = ["full"] } # `serde` feature dependencies serde = { workspace = true, optional = true, features = ["derive"] } -# `metrics` feature dependencies -lazy_static = { workspace = true, optional = true } -prometheus = { workspace = true, optional = true, features = ["process"] } - # `test-utils` feature dependencies spin = { workspace = true, optional = true } anyhow = { workspace = true, optional = true } @@ -63,10 +59,6 @@ alloy-primitives = { workspace = true, features = ["rlp", "k256", "map", "arbitr [features] default = ["serde"] -metrics = [ - "dep:prometheus", - "dep:lazy_static", -] serde = [ "dep:serde", "alloy-primitives/serde", diff --git a/crates/derive/src/batch/mod.rs b/crates/derive/src/batch/mod.rs index 376f10d46..49fbf213b 100644 --- a/crates/derive/src/batch/mod.rs +++ b/crates/derive/src/batch/mod.rs @@ -114,6 +114,7 @@ impl Batch { #[cfg(test)] mod tests { use super::*; + use alloc::vec; #[test] fn test_timestamp() { diff --git a/crates/derive/src/batch/span_batch/transactions.rs b/crates/derive/src/batch/span_batch/transactions.rs index 41967e34c..2802e1b25 100644 --- a/crates/derive/src/batch/span_batch/transactions.rs +++ b/crates/derive/src/batch/span_batch/transactions.rs @@ -373,6 +373,7 @@ impl SpanBatchTransactions { #[cfg(test)] mod tests { use super::*; + use alloc::vec; use alloy_consensus::{Signed, TxEip1559, TxEip2930, TxLegacy}; use alloy_primitives::{address, Signature, TxKind}; diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index e88fd238f..ad603141c 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -4,8 +4,8 @@ html_favicon_url = "https://raw.githubusercontent.com/anton-rs/kona/main/assets/favicon.ico" )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![cfg_attr(not(any(test, feature = "metrics")), no_std)] #![cfg_attr(not(any(test, feature = "test-utils")), warn(unused_crate_dependencies))] +#![cfg_attr(not(test), no_std)] extern crate alloc; @@ -28,10 +28,5 @@ pub mod sources; pub mod stages; pub mod traits; -mod macros; - -#[cfg(feature = "metrics")] -pub mod metrics; - #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; diff --git a/crates/derive/src/macros.rs b/crates/derive/src/macros.rs deleted file mode 100644 index a6ce974e1..000000000 --- a/crates/derive/src/macros.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Macros for use across derive. - -/// Starts the timer with a label value. -#[macro_export] -macro_rules! timer { - (START, $metric:ident, $labels:expr, $timer:ident) => { - #[cfg(feature = "metrics")] - let $timer = $crate::metrics::$metric.with_label_values($labels).start_timer(); - }; - (DISCARD, $timer:ident) => { - #[cfg(feature = "metrics")] - $timer.stop_and_discard(); - }; - (STOP, $timer:ident) => { - #[cfg(feature = "metrics")] - $timer.stop_and_record(); - }; -} - -/// Increments a metric with a label value. -#[macro_export] -macro_rules! inc { - ($metric:ident) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.inc(); - }; - ($metric:ident, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).inc(); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).add($value); - }; -} - -/// Observes a metric with a label value. -#[macro_export] -macro_rules! observe { - ($metric:ident, $value:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.observe($value); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($label).observe($value); - }; -} - -/// Sets a metric value. -#[macro_export] -macro_rules! set { - ($metric:ident, $value:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.set($value); - }; - ($metric:ident, $value:expr, $labels:expr) => { - #[cfg(feature = "metrics")] - $crate::metrics::$metric.with_label_values($labels).set($value as f64); - }; -} diff --git a/crates/derive/src/metrics.rs b/crates/derive/src/metrics.rs deleted file mode 100644 index 4cea01072..000000000 --- a/crates/derive/src/metrics.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! Metrics for derivation pipeline stages. - -use alloc::{boxed::Box, string::String}; -use lazy_static::lazy_static; -use prometheus::{ - self, opts, register_counter_vec, register_gauge_vec, register_histogram, - register_histogram_vec, register_int_gauge, CounterVec, GaugeVec, Histogram, HistogramVec, - IntGauge, -}; - -const RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 18] = &[ - 0.00001, 0.00005, 0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.008, 0.01, 0.02, 0.05, 0.08, - 0.1, 0.2, 0.5, 0.8, 1.0, -]; - -const FRAME_COUNT_BUCKETS: &[f64; 10] = &[1.0, 2.0, 3.0, 5.0, 8.0, 10.0, 12.0, 15.0, 18.0, 20.0]; - -lazy_static! { - /// Tracks stage resets. - pub static ref STAGE_RESETS: GaugeVec = { - let opts = opts!("kona_derive_stage_resets", "Number of times various stages are reset"); - register_gauge_vec!(opts, &["stage"]).expect("Stage reset metric failed to register") - }; - - /// Tracks the L1 origin for the L1 Traversal Stage. - pub static ref ORIGIN_GAUGE: IntGauge = register_int_gauge!( - "kona_derive_origin_gauge", - "Tracks the L1 origin for the L1 Traversal Stage" - ).expect("Origin Gauge failed to register"); - - /// Tracks the number of frames in the current channel. - pub static ref CURRENT_CHANNEL_FRAMES: IntGauge = register_int_gauge!( - "kona_derive_current_channel_frames", - "Tracks the number of frames in the current channel." - ).expect("Current channel frames failed to register"); - - /// Tracks the number of channels that have the bucket amount of frames. - pub static ref CHANNEL_FRAME_COUNT: Histogram = register_histogram!( - "kona_derive_channel_frame_count", - "Tracks the number of channels that have the bucket amount of frames.", - FRAME_COUNT_BUCKETS.to_vec() - ).expect("Channel frame count failed to register"); - - /// Tracks batch reader errors. - pub static ref BATCH_READER_ERRORS: CounterVec = register_counter_vec!( - "kona_derive_batch_reader_errors", - "Number of batch reader errors", - &["error"] - ).expect("Batch Reader Errors failed to register"); - - /// Tracks the number of times the channel queue was detected - /// non-empty during a frame ingestion, and new channel creation - /// was attempted post-holocene. - pub static ref CHANNEL_QUEUE_NON_EMPTY: IntGauge = register_int_gauge!( - "kona_derive_channel_queue_non_empty", - "Number of times a channel was attempted to be created in the channel bank, but the queue is non-empty post-holocene." - ).expect("Channel Queue Non Empty failed to register"); - - /// Tracks the compression ratio of batches. - pub static ref BATCH_COMPRESSION_RATIO: IntGauge = register_int_gauge!( - "kona_derive_batch_compression_ratio", - "Compression ratio of batches" - ).expect("Batch Compression Ratio failed to register"); - - /// Tracks the time taken for stage advance methods. - pub static ref STAGE_ADVANCE_RESPONSE_TIME: HistogramVec = register_histogram_vec!( - "kona_derive_stage_advance_response_time_seconds", - "Stage advance response times", - &["stage"], - RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() - ).expect("Failed to register histogram vec"); - - /// Tracks the number of derived frames. - pub static ref DERIVED_FRAMES_COUNT: GaugeVec = { - let opts = opts!("kona_derive_derived_frames_count", "Number of derived frames"); - register_gauge_vec!(opts, &["status"]).expect("Derived Frames Count failed to register") - }; - - /// Tracks the number of channel timeouts. - pub static ref CHANNEL_TIMEOUTS: Histogram = { - let channel_timeout_buckets: [f64; 100] = core::array::from_fn(|i| (i * 10) as f64); - register_histogram!( - "kona_derive_channel_timeouts", - "Channel timeouts", - channel_timeout_buckets.to_vec() - ).expect("Failed to register histogram vec") - }; -} diff --git a/crates/derive/src/pipeline/core.rs b/crates/derive/src/pipeline/core.rs index 068b46950..6d3f09f09 100644 --- a/crates/derive/src/pipeline/core.rs +++ b/crates/derive/src/pipeline/core.rs @@ -178,7 +178,7 @@ mod tests { test_utils::{TestL2ChainProvider, *}, traits::{ActivationSignal, Pipeline, ResetSignal, Signal, SignalReceiver}, }; - use alloc::sync::Arc; + use alloc::{string::ToString, sync::Arc}; use alloy_rpc_types_engine::PayloadAttributes; use op_alloy_genesis::{RollupConfig, SystemConfig}; use op_alloy_protocol::L2BlockInfo; diff --git a/crates/derive/src/sources/calldata.rs b/crates/derive/src/sources/calldata.rs index 5f2c97805..71f442f38 100644 --- a/crates/derive/src/sources/calldata.rs +++ b/crates/derive/src/sources/calldata.rs @@ -104,6 +104,7 @@ impl AsyncIterator for CalldataSource { mod tests { use super::*; use crate::{errors::PipelineErrorKind, test_utils::TestChainProvider}; + use alloc::{vec, vec::Vec}; use alloy_consensus::{Signed, TxEip2930, TxEip4844, TxEip4844Variant, TxLegacy}; use alloy_primitives::{address, Address, Signature, TxKind}; diff --git a/crates/derive/src/stages/attributes_queue.rs b/crates/derive/src/stages/attributes_queue.rs index 24e119128..4546ba7bf 100644 --- a/crates/derive/src/stages/attributes_queue.rs +++ b/crates/derive/src/stages/attributes_queue.rs @@ -53,8 +53,7 @@ where AB: AttributesBuilder + Debug, { /// Create a new [AttributesQueue] stage. - pub fn new(cfg: Arc, prev: P, builder: AB) -> Self { - crate::set!(STAGE_RESETS, 0, &["attributes-queue"]); + pub const fn new(cfg: Arc, prev: P, builder: AB) -> Self { Self { cfg, prev, is_last_in_span: false, batch: None, builder } } @@ -73,11 +72,9 @@ where &mut self, parent: L2BlockInfo, ) -> PipelineResult { - crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["attributes_queue"], timer); let batch = match self.load_batch(parent).await { Ok(batch) => batch, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; @@ -86,7 +83,6 @@ where let attributes = match self.create_next_attributes(batch, parent).await { Ok(attributes) => attributes, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; @@ -187,7 +183,6 @@ where self.prev.signal(s).await?; self.batch = None; self.is_last_in_span = false; - crate::inc!(STAGE_RESETS, &["attributes-queue"]); } s @ Signal::FlushChannel => { self.batch = None; diff --git a/crates/derive/src/stages/batch/batch_provider.rs b/crates/derive/src/stages/batch/batch_provider.rs index b480a9e96..b30093390 100644 --- a/crates/derive/src/stages/batch/batch_provider.rs +++ b/crates/derive/src/stages/batch/batch_provider.rs @@ -182,9 +182,9 @@ mod test { test_utils::{TestL2ChainProvider, TestNextBatchProvider}, traits::{OriginProvider, ResetSignal, SignalReceiver}, }; + use alloc::{sync::Arc, vec}; use op_alloy_genesis::RollupConfig; use op_alloy_protocol::BlockInfo; - use std::sync::Arc; #[test] fn test_batch_provider_validator_active() { diff --git a/crates/derive/src/stages/batch/batch_queue.rs b/crates/derive/src/stages/batch/batch_queue.rs index 85363223f..f6ab8087b 100644 --- a/crates/derive/src/stages/batch/batch_queue.rs +++ b/crates/derive/src/stages/batch/batch_queue.rs @@ -65,15 +65,15 @@ where BF: L2ChainProvider + Debug, { /// Creates a new [BatchQueue] stage. + #[allow(clippy::missing_const_for_fn)] pub fn new(cfg: Arc, prev: P, fetcher: BF) -> Self { - crate::set!(STAGE_RESETS, 0, &["batch-queue"]); Self { cfg, prev, origin: None, - l1_blocks: Vec::new(), - batches: Vec::new(), - next_spans: Vec::new(), + l1_blocks: Default::default(), + batches: Default::default(), + next_spans: Default::default(), fetcher, } } @@ -281,12 +281,10 @@ where /// Returns the next valid batch upon the given safe head. /// Also returns the boolean that indicates if the batch is the last block in the batch. async fn next_batch(&mut self, parent: L2BlockInfo) -> PipelineResult { - crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["batch_queue"], timer); if !self.next_spans.is_empty() { // There are cached singular batches derived from the span batch. // Check if the next cached batch matches the given parent block. if self.next_spans[0].timestamp == parent.block_info.timestamp + self.cfg.block_time { - crate::timer!(DISCARD, timer); return self.pop_next_batch(parent).ok_or(PipelineError::BatchQueueEmpty.crit()); } // Parent block does not match the next batch. @@ -332,7 +330,6 @@ where let origin = match self.origin.as_ref().ok_or(PipelineError::MissingOrigin.crit()) { Ok(o) => o, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; @@ -361,7 +358,6 @@ where if let PipelineErrorKind::Temporary(PipelineError::Eof) = e { out_of_data = true; } else { - crate::timer!(DISCARD, timer); return Err(e); } } @@ -370,7 +366,6 @@ where // Skip adding the data unless up to date with the origin, // but still fully empty the previous stages. if origin_behind { - crate::timer!(DISCARD, timer); if out_of_data { return Err(PipelineError::Eof.temp()); } @@ -380,18 +375,15 @@ where // Attempt to derive more batches. let batch = match self.derive_next_batch(out_of_data, parent).await { Ok(b) => b, - Err(e) => { - crate::timer!(DISCARD, timer); - match e { - PipelineErrorKind::Temporary(PipelineError::Eof) => { - if out_of_data { - return Err(PipelineError::Eof.temp()); - } - return Err(PipelineError::NotEnoughData.temp()); + Err(e) => match e { + PipelineErrorKind::Temporary(PipelineError::Eof) => { + if out_of_data { + return Err(PipelineError::Eof.temp()); } - _ => return Err(e), + return Err(PipelineError::NotEnoughData.temp()); } - } + _ => return Err(e), + }, }; // If the next batch is derived from the span batch, it's the last batch of the span. @@ -404,7 +396,6 @@ where }) { Ok(b) => b, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; @@ -415,7 +406,6 @@ where { Ok(b) => b, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; @@ -458,7 +448,6 @@ where self.l1_blocks.clear(); self.l1_blocks.push(l1_origin); self.next_spans.clear(); - crate::inc!(STAGE_RESETS, &["batch-queue"]); } s @ Signal::Activation(_) | s @ Signal::FlushChannel => { self.prev.signal(s).await?; diff --git a/crates/derive/src/stages/batch/batch_stream.rs b/crates/derive/src/stages/batch/batch_stream.rs index fdfb61f56..8999ca126 100644 --- a/crates/derive/src/stages/batch/batch_stream.rs +++ b/crates/derive/src/stages/batch/batch_stream.rs @@ -212,7 +212,6 @@ where self.prev.signal(signal).await?; self.buffer.clear(); self.span.take(); - crate::inc!(STAGE_RESETS, &["batch-span"]); Ok(()) } } @@ -225,6 +224,7 @@ mod test { test_utils::{CollectingLayer, TestBatchStreamProvider, TestL2ChainProvider, TraceStorage}, traits::ResetSignal, }; + use alloc::vec; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::test] diff --git a/crates/derive/src/stages/batch/batch_validator.rs b/crates/derive/src/stages/batch/batch_validator.rs index 5fdf7019c..906a11ee4 100644 --- a/crates/derive/src/stages/batch/batch_validator.rs +++ b/crates/derive/src/stages/batch/batch_validator.rs @@ -300,7 +300,6 @@ where // During normal resets we will later throw out this block. self.l1_blocks.clear(); self.l1_blocks.push(l1_origin); - crate::inc!(STAGE_RESETS, &["batch-validator"]); } s @ Signal::Activation(_) | s @ Signal::FlushChannel => { self.prev.signal(s).await?; @@ -312,15 +311,14 @@ where #[cfg(test)] mod test { - use super::BatchValidator; use crate::{ batch::{Batch, SingleBatch, SpanBatch}, errors::{PipelineError, PipelineErrorKind, PipelineResult, ResetError}, - stages::NextBatchProvider, + stages::{BatchValidator, NextBatchProvider}, test_utils::{CollectingLayer, TestNextBatchProvider, TraceStorage}, traits::{AttributesProvider, OriginAdvancer, ResetSignal, Signal, SignalReceiver}, }; - use alloc::sync::Arc; + use alloc::{sync::Arc, vec, vec::Vec}; use alloy_eips::{BlockNumHash, NumHash}; use alloy_primitives::B256; use op_alloy_genesis::RollupConfig; @@ -614,7 +612,6 @@ mod test { assert_eq!(bv.next_batch(mock_parent).await.unwrap_err(), PipelineError::Eof.temp()); let trace_lock = trace_store.lock(); - dbg!(&trace_lock); assert_eq!(trace_lock.iter().filter(|(l, _)| matches!(l, &Level::DEBUG)).count(), 2); assert!(trace_lock[0].1.contains("Advancing batch validator origin")); assert!(trace_lock[1].1.contains("Advancing batch validator epoch")); diff --git a/crates/derive/src/stages/channel/channel_assembler.rs b/crates/derive/src/stages/channel/channel_assembler.rs index 5b19c3b42..002ae70b4 100644 --- a/crates/derive/src/stages/channel/channel_assembler.rs +++ b/crates/derive/src/stages/channel/channel_assembler.rs @@ -39,8 +39,7 @@ where P: NextFrameProvider + OriginAdvancer + OriginProvider + SignalReceiver + Debug, { /// Creates a new [ChannelAssembler] stage with the given configuration and previous stage. - pub fn new(cfg: Arc, prev: P) -> Self { - crate::set!(STAGE_RESETS, 0, &["channel-assembly"]); + pub const fn new(cfg: Arc, prev: P) -> Self { Self { cfg, prev, channel: None } } @@ -70,12 +69,6 @@ where // Time out the channel if it has timed out. if let Some(channel) = self.channel.as_ref() { if self.is_timed_out()? { - #[cfg(feature = "metrics")] - { - let open_block_number = - self.channel.as_ref().map(|c| c.open_block_number()).unwrap_or_default(); - crate::observe!(CHANNEL_TIMEOUTS, (origin.number - open_block_number) as f64); - } warn!( target: "channel-assembler", "Channel (ID: {}) timed out at L1 origin #{}, open block #{}. Discarding channel.", @@ -185,7 +178,6 @@ where async fn signal(&mut self, signal: Signal) -> PipelineResult<()> { self.prev.signal(signal).await?; self.channel = None; - crate::inc!(STAGE_RESETS, &["channel-assembly"]); Ok(()) } } @@ -198,7 +190,7 @@ mod test { stages::ChannelReaderProvider, test_utils::{CollectingLayer, TestNextFrameProvider, TraceStorage}, }; - use alloc::sync::Arc; + use alloc::{sync::Arc, vec}; use op_alloy_genesis::{ RollupConfig, MAX_RLP_BYTES_PER_CHANNEL_BEDROCK, MAX_RLP_BYTES_PER_CHANNEL_FJORD, }; diff --git a/crates/derive/src/stages/channel/channel_bank.rs b/crates/derive/src/stages/channel/channel_bank.rs index 68d19d680..47937e9da 100644 --- a/crates/derive/src/stages/channel/channel_bank.rs +++ b/crates/derive/src/stages/channel/channel_bank.rs @@ -52,7 +52,6 @@ where { /// Create a new [ChannelBank] stage. pub fn new(cfg: Arc, prev: P) -> Self { - crate::set!(STAGE_RESETS, 0, &["channel-bank"]); Self { cfg, channels: HashMap::default(), channel_queue: VecDeque::new(), prev } } @@ -112,18 +111,6 @@ where warn!(target: "channel-bank", "Failed to add frame to channel: {:?}", frame_id); return Ok(()); } - // Only increment the channel frames if the channel is current. - if self.channel_queue.front().map_or(false, |id| *id == current_channel.id()) { - crate::inc!(CURRENT_CHANNEL_FRAMES); - } - #[cfg(feature = "metrics")] - { - // For each channel, get the number of frames and record it in the CHANNEL_FRAME_COUNT - // histogram metric. - for channel in self.channels.values() { - crate::observe!(CHANNEL_FRAME_COUNT, channel.len() as f64); - } - } self.prune() } @@ -150,17 +137,8 @@ where target: "channel-bank", "Channel (ID: {}) timed out", hex::encode(first) ); - crate::observe!(CHANNEL_TIMEOUTS, (origin.number - channel.open_block_number()) as f64); self.channels.remove(&first); self.channel_queue.pop_front(); - crate::set!( - CURRENT_CHANNEL_FRAMES, - self.channel_queue.front().map_or(0, |id| self - .channels - .get(id) - .map_or(0, |c| c.len()) - as i64) - ); return Ok(None); } @@ -218,11 +196,9 @@ where P: NextFrameProvider + OriginAdvancer + OriginProvider + SignalReceiver + Send + Debug, { async fn next_data(&mut self) -> PipelineResult> { - crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["channel_bank"], timer); match self.read() { Err(e) => { if !matches!(e, PipelineErrorKind::Temporary(PipelineError::Eof)) { - crate::timer!(DISCARD, timer); return Err(PipelineError::ChannelProviderEmpty.crit()); } } @@ -233,12 +209,10 @@ where let frame = match self.prev.next_frame().await { Ok(f) => f, Err(e) => { - crate::timer!(DISCARD, timer); return Err(e); } }; let res = self.ingest_frame(frame); - crate::timer!(DISCARD, timer); res?; Err(PipelineError::NotEnoughData.temp()) } @@ -262,7 +236,6 @@ where self.prev.signal(signal).await?; self.channels.clear(); self.channel_queue = VecDeque::with_capacity(10); - crate::inc!(STAGE_RESETS, &["channel-bank"]); Ok(()) } } @@ -274,7 +247,7 @@ mod tests { test_utils::{CollectingLayer, TestNextFrameProvider, TraceStorage}, traits::ResetSignal, }; - use alloc::vec; + use alloc::{vec, vec::Vec}; use op_alloy_genesis::{BASE_MAINNET_CONFIG, OP_MAINNET_CONFIG}; use tracing::Level; use tracing_subscriber::layer::SubscriberExt; diff --git a/crates/derive/src/stages/channel/channel_provider.rs b/crates/derive/src/stages/channel/channel_provider.rs index 75bbcf399..1dc868ac1 100644 --- a/crates/derive/src/stages/channel/channel_provider.rs +++ b/crates/derive/src/stages/channel/channel_provider.rs @@ -160,7 +160,7 @@ mod test { test_utils::TestNextFrameProvider, traits::{ResetSignal, SignalReceiver}, }; - use alloc::sync::Arc; + use alloc::{sync::Arc, vec}; use op_alloy_genesis::RollupConfig; use op_alloy_protocol::BlockInfo; diff --git a/crates/derive/src/stages/channel/channel_reader.rs b/crates/derive/src/stages/channel/channel_reader.rs index 49cf630c7..f8a722138 100644 --- a/crates/derive/src/stages/channel/channel_reader.rs +++ b/crates/derive/src/stages/channel/channel_reader.rs @@ -64,8 +64,7 @@ where P: ChannelReaderProvider + OriginAdvancer + OriginProvider + SignalReceiver + Debug, { /// Create a new [ChannelReader] stage. - pub fn new(prev: P, cfg: Arc) -> Self { - crate::set!(STAGE_RESETS, 0, &["channel-reader"]); + pub const fn new(prev: P, cfg: Arc) -> Self { Self { prev, next_batch: None, cfg } } @@ -122,11 +121,9 @@ where } async fn next_batch(&mut self) -> PipelineResult { - crate::timer!(START, STAGE_ADVANCE_RESPONSE_TIME, &["channel_reader"], timer); if let Err(e) = self.set_batch_reader().await { debug!(target: "channel-reader", "Failed to set batch reader: {:?}", e); self.next_channel(); - crate::timer!(DISCARD, timer); return Err(e); } match self @@ -139,7 +136,6 @@ where Ok(batch) => Ok(batch), Err(e) => { self.next_channel(); - crate::timer!(DISCARD, timer); Err(e) } } @@ -170,7 +166,6 @@ where s => { self.prev.signal(s).await?; self.next_channel(); - crate::inc!(STAGE_RESETS, &["channel-reader"]); } } Ok(()) @@ -212,9 +207,6 @@ impl BatchReader { // If the data is not already decompressed, decompress it. let mut brotli_used = false; - #[cfg(feature = "metrics")] - let mut raw_len = 0; - if let Some(data) = self.data.take() { // Peek at the data to determine the compression type. if data.is_empty() { @@ -222,11 +214,6 @@ impl BatchReader { return None; } - #[cfg(feature = "metrics")] - { - raw_len = data.len(); - } - let compression_type = data[0]; if (compression_type & 0x0F) == ZLIB_DEFLATE_COMPRESSION_METHOD || (compression_type & 0x0F) == ZLIB_RESERVED_COMPRESSION_METHOD @@ -243,7 +230,6 @@ impl BatchReader { decompress_brotli(&data[1..], self.max_rlp_bytes_per_channel).ok()?; } else { error!(target: "batch-reader", "Unsupported compression type: {:x}, skipping batch", compression_type); - crate::inc!(BATCH_READER_ERRORS, &["unsupported_compression_type"]); return None; } } @@ -251,17 +237,14 @@ impl BatchReader { // Decompress and RLP decode the batch data, before finally decoding the batch itself. let decompressed_reader = &mut self.decompressed.as_slice()[self.cursor..].as_ref(); let bytes = Bytes::decode(decompressed_reader).ok()?; - crate::set!(BATCH_COMPRESSION_RATIO, (raw_len as i64) * 100 / bytes.len() as i64); let Ok(batch) = Batch::decode(&mut bytes.as_ref(), cfg) else { error!(target: "batch-reader", "Failed to decode batch, skipping batch"); - crate::inc!(BATCH_READER_ERRORS, &["failed_to_decode_batch"]); return None; }; // Confirm that brotli decompression was performed *after* the Fjord hardfork. if brotli_used && !cfg.is_fjord_active(batch.timestamp()) { warn!(target: "batch-reader", "Brotli compression used before Fjord hardfork, skipping batch"); - crate::inc!(BATCH_READER_ERRORS, &["brotli_used_before_fjord"]); return None; } diff --git a/crates/derive/src/stages/frame_queue.rs b/crates/derive/src/stages/frame_queue.rs index 945dedcd3..6e103785c 100644 --- a/crates/derive/src/stages/frame_queue.rs +++ b/crates/derive/src/stages/frame_queue.rs @@ -49,8 +49,7 @@ where /// Create a new [FrameQueue] stage with the given previous [L1Retrieval] stage. /// /// [L1Retrieval]: crate::stages::L1Retrieval - pub fn new(prev: P, cfg: Arc) -> Self { - crate::set!(STAGE_RESETS, 0, &["frame-queue"]); + pub const fn new(prev: P, cfg: Arc) -> Self { Self { prev, queue: VecDeque::new(), rollup_config: cfg } } @@ -125,7 +124,6 @@ where }; let Ok(frames) = Frame::parse_frames(&data.into()) else { - crate::inc!(DERIVED_FRAMES_COUNT, &["failed"]); // There may be more frames in the queue for the // pipeline to advance, so don't return an error here. error!(target: "frame-queue", "Failed to parse frames from data."); @@ -139,8 +137,6 @@ where let origin = self.origin().ok_or(PipelineError::MissingOrigin.crit())?; self.prune(origin); - crate::inc!(DERIVED_FRAMES_COUNT, self.queue.len() as f64, &["success"]); - Ok(()) } } @@ -190,7 +186,6 @@ where async fn signal(&mut self, signal: Signal) -> PipelineResult<()> { self.prev.signal(signal).await?; self.queue = VecDeque::default(); - crate::inc!(STAGE_RESETS, &["frame-queue"]); Ok(()) } } diff --git a/crates/derive/src/stages/l1_retrieval.rs b/crates/derive/src/stages/l1_retrieval.rs index 4886627b9..7fc7c298c 100644 --- a/crates/derive/src/stages/l1_retrieval.rs +++ b/crates/derive/src/stages/l1_retrieval.rs @@ -60,8 +60,7 @@ where /// [DataAvailabilityProvider]. /// /// [L1Traversal]: crate::stages::L1Traversal - pub fn new(prev: P, provider: DAP) -> Self { - crate::set!(STAGE_RESETS, 0, &["l1-retrieval"]); + pub const fn new(prev: P, provider: DAP) -> Self { Self { prev, provider, data: None } } } @@ -129,7 +128,6 @@ where Signal::Reset(ResetSignal { l1_origin, .. }) | Signal::Activation(ActivationSignal { l1_origin, .. }) => { self.data = Some(self.provider.open_data(&l1_origin).await?); - crate::inc!(STAGE_RESETS, &["l1-retrieval"]); } _ => {} } diff --git a/crates/derive/src/stages/l1_traversal.rs b/crates/derive/src/stages/l1_traversal.rs index 31fb83b79..f43e3cbb9 100644 --- a/crates/derive/src/stages/l1_traversal.rs +++ b/crates/derive/src/stages/l1_traversal.rs @@ -55,7 +55,6 @@ impl L1RetrievalProvider for L1Traversal { impl L1Traversal { /// Creates a new [L1Traversal] instance. pub fn new(data_source: F, cfg: Arc) -> Self { - crate::set!(STAGE_RESETS, 0, &["l1-traversal"]); Self { block: Some(BlockInfo::default()), data_source, @@ -105,8 +104,6 @@ impl OriginAdvancer for L1Traversal { return Err(PipelineError::SystemConfigUpdate(e).crit()); } - crate::set!(ORIGIN_GAUGE, next_l1_origin.number as i64); - let prev_block_holocene = self.rollup_config.is_holocene_active(block.timestamp); let next_block_holocene = self.rollup_config.is_holocene_active(next_l1_origin.timestamp); @@ -139,7 +136,6 @@ impl SignalReceiver for L1Traversal { self.block = Some(l1_origin); self.done = false; self.system_config = system_config.expect("System config must be provided."); - crate::inc!(STAGE_RESETS, &["l1-traversal"]); } _ => {} }