feat: add metrics for safe and finalized block heights (#18987)

This commit is contained in:
Ivan Wang
2025-10-15 17:07:42 +08:00
committed by GitHub
parent 2f82b7c771
commit ee6cac72de
2 changed files with 10 additions and 2 deletions

View File

@@ -122,6 +122,10 @@ pub(crate) struct TreeMetrics {
pub reorgs: Counter,
/// The latest reorg depth
pub latest_reorg_depth: Gauge,
/// The current safe block height (this is required by optimism)
pub safe_block_height: Gauge,
/// The current finalized block height (this is required by optimism)
pub finalized_block_height: Gauge,
}
/// Metrics for the `EngineApi`.

View File

@@ -2805,7 +2805,9 @@ where
// we're also persisting the finalized block on disk so we can reload it on
// restart this is required by optimism which queries the finalized block: <https://github.com/ethereum-optimism/optimism/blob/c383eb880f307caa3ca41010ec10f30f08396b2e/op-node/rollup/sync/start.go#L65-L65>
let _ = self.persistence.save_finalized_block_number(finalized.number());
self.canonical_in_memory_state.set_finalized(finalized);
self.canonical_in_memory_state.set_finalized(finalized.clone());
// Update finalized block height metric
self.metrics.tree.finalized_block_height.set(finalized.number() as f64);
}
}
Err(err) => {
@@ -2833,7 +2835,9 @@ where
// we're also persisting the safe block on disk so we can reload it on
// restart this is required by optimism which queries the safe block: <https://github.com/ethereum-optimism/optimism/blob/c383eb880f307caa3ca41010ec10f30f08396b2e/op-node/rollup/sync/start.go#L65-L65>
let _ = self.persistence.save_safe_block_number(safe.number());
self.canonical_in_memory_state.set_safe(safe);
self.canonical_in_memory_state.set_safe(safe.clone());
// Update safe block height metric
self.metrics.tree.safe_block_height.set(safe.number() as f64);
}
}
Err(err) => {