Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ workspace = true
[dependencies]
# workspace
kona-rpc.workspace = true
kona-derive.workspace = true
kona-genesis.workspace = true
kona-protocol.workspace = true

kona-cli = { workspace = true, features = ["secrets"] }
kona-engine = { workspace = true, features = ["metrics"] }
kona-p2p = { workspace = true, features = ["metrics"] }
kona-derive = { workspace = true, features = ["metrics"] }
kona-engine = { workspace = true, features = ["metrics"] }
kona-registry = { workspace = true, features = ["tabled"] }
kona-node-service = { workspace = true, features = ["metrics"] }
kona-sources = { workspace = true, features = ["metrics"] }
kona-node-service = { workspace = true, features = ["metrics"] }

# alloy
alloy-provider.workspace = true
Expand Down
1 change: 1 addition & 0 deletions bin/node/src/flags/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn init_unified_metrics(args: &MetricsArgs) -> anyhow::Result<()> {
kona_p2p::Metrics::init();
kona_engine::Metrics::init();
kona_node_service::Metrics::init();
kona_derive::metrics::Metrics::init();
VersionInfo::from_build().register_version_metrics();
}
Ok(())
Expand Down
5 changes: 5 additions & 0 deletions crates/protocol/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true

[dependencies]
# Protocol
kona-macros.workspace = true
kona-genesis.workspace = true
kona-protocol.workspace = true
kona-hardforks.workspace = true
Expand All @@ -38,6 +39,9 @@ serde = { workspace = true, optional = true }
spin = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true, features = ["fmt"] }

# `metrics` feature
metrics = { workspace = true, optional = true }

[dev-dependencies]
kona-derive = { workspace = true, features = ["test-utils"] }
spin.workspace = true
Expand All @@ -52,6 +56,7 @@ op-alloy-consensus = { workspace = true, features = ["k256"] }

[features]
default = []
metrics = ["dep:metrics"]
serde = [
"dep:serde",
"kona-protocol/serde",
Expand Down
3 changes: 2 additions & 1 deletion crates/protocol/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
issue_tracker_base_url = "https://github.com/op-rs/kona/issues/"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![no_std]
#![cfg_attr(not(feature = "metrics"), no_std)]

extern crate alloc;

Expand All @@ -21,6 +21,7 @@ pub mod prelude {

pub mod attributes;
pub mod errors;
pub mod metrics;
pub mod pipeline;
pub mod sources;
pub mod stages;
Expand Down
51 changes: 51 additions & 0 deletions crates/protocol/derive/src/metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Metrics for the derivation pipeline.

/// Container for metrics.
#[derive(Debug, Clone)]
pub struct Metrics;

impl Metrics {
/// Identifier for the pipeline origin gauge.
pub const PIPELINE_ORIGIN: &str = "kona_derive_pipeline_origin";

/// Identifier to track the amount of time it takes to advance the pipeline origin.
pub const PIPELINE_ORIGIN_ADVANCE: &str = "kona_derive_pipeline_origin_advance";

/// Identifier for the histogram that tracks when the system config is updated.
pub const SYSTEM_CONFIG_UPDATE: &str = "kona_derive_system_config_update";
}

impl Metrics {
/// Initializes metrics for the P2P stack.
///
/// This does two things:
/// * Describes various metrics.
/// * Initializes metrics to 0 so they can be queried immediately.
#[cfg(feature = "metrics")]
pub fn init() {
Self::describe();
Self::zero();
}

Check warning on line 28 in crates/protocol/derive/src/metrics/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/protocol/derive/src/metrics/mod.rs#L25-L28

Added lines #L25 - L28 were not covered by tests

/// Describes metrics used in [`kona_p2p`][crate].
#[cfg(feature = "metrics")]
pub fn describe() {
metrics::describe_gauge!(
Self::PIPELINE_ORIGIN,
"The block height of the pipeline l1 origin"
);
metrics::describe_histogram!(
Self::PIPELINE_ORIGIN_ADVANCE,
"The amount of time it takes to advance the pipeline origin"
);
metrics::describe_histogram!(
Self::SYSTEM_CONFIG_UPDATE,
"The time it takes to update the system config"
);
}

Check warning on line 45 in crates/protocol/derive/src/metrics/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/protocol/derive/src/metrics/mod.rs#L32-L45

Added lines #L32 - L45 were not covered by tests

/// Initializes metrics to 0 so they can be queried immediately.
#[allow(clippy::missing_const_for_fn)]
#[cfg(feature = "metrics")]
pub fn zero() {}

Check warning on line 50 in crates/protocol/derive/src/metrics/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/protocol/derive/src/metrics/mod.rs#L50

Added line #L50 was not covered by tests
}
28 changes: 24 additions & 4 deletions crates/protocol/derive/src/stages/l1_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ impl<F: ChainProvider> L1Traversal<F> {
rollup_config: cfg,
}
}

/// Update the origin block in the traversal stage.
fn update_origin(&mut self, block: BlockInfo) {
self.done = false;
self.block = Some(block);
kona_macros::set!(gauge, crate::metrics::Metrics::PIPELINE_ORIGIN, block.number as f64);
}
}

#[async_trait]
Expand All @@ -68,6 +75,10 @@ impl<F: ChainProvider + Send> OriginAdvancer for L1Traversal<F> {
/// This function fetches the next L1 [BlockInfo] from the data source and updates the
/// [SystemConfig] with the receipts from the block.
async fn advance_origin(&mut self) -> PipelineResult<()> {
// Advance start time for metrics.
#[cfg(feature = "metrics")]
let start_time = std::time::Instant::now();

// Pull the next block or return EOF.
// PipelineError::EOF has special handling further up the pipeline.
let block = match self.block {
Expand Down Expand Up @@ -101,8 +112,18 @@ impl<F: ChainProvider + Send> OriginAdvancer for L1Traversal<F> {
let next_block_holocene = self.rollup_config.is_holocene_active(next_l1_origin.timestamp);

// Update the block origin regardless of if a holocene activation is required.
self.block = Some(next_l1_origin);
self.done = false;
self.update_origin(next_l1_origin);

// Record the origin as advanced.
#[cfg(feature = "metrics")]
{
let duration = start_time.elapsed();
kona_macros::record!(
histogram,
crate::metrics::Metrics::PIPELINE_ORIGIN_ADVANCE,
duration.as_secs_f64()
);
}

// If the prev block is not holocene, but the next is, we need to flag this
// so the pipeline driver will reset the pipeline for holocene activation.
Expand All @@ -126,8 +147,7 @@ impl<F: ChainProvider + Send> SignalReceiver for L1Traversal<F> {
match signal {
Signal::Reset(ResetSignal { l1_origin, system_config, .. }) |
Signal::Activation(ActivationSignal { l1_origin, system_config, .. }) => {
self.block = Some(l1_origin);
self.done = false;
self.update_origin(l1_origin);
self.system_config = system_config.expect("System config must be provided.");
}
_ => {}
Expand Down
1 change: 1 addition & 0 deletions crates/utilities/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![no_std]

mod metrics;
Loading