diff --git a/examples/trusted-sync/src/main.rs b/examples/trusted-sync/src/main.rs index dba762a41..09468559a 100644 --- a/examples/trusted-sync/src/main.rs +++ b/examples/trusted-sync/src/main.rs @@ -97,10 +97,25 @@ async fn sync(cli: cli::Cli) -> Result<()> { // Update the reference l2 head. match l2_provider.latest_block_number().await { Ok(latest) => { + let prev = metrics::REFERENCE_L2_HEAD.get(); metrics::REFERENCE_L2_HEAD.set(latest as i64); + if latest as i64 > prev { + let time = match std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|s| s.as_secs()) + { + Ok(time) => time, + Err(e) => { + error!(target: LOG_TARGET, "Failed to get latest timestamp in seconds: {:?}", e); + continue; + } + }; + metrics::LATEST_REF_SAFE_HEAD_UPDATE.set(time as i64); + } } Err(e) => { warn!(target: LOG_TARGET, "Failed to fetch latest reference l2 safe head: {:?}", e); + continue; // retry the reference fetch. } } if advance_cursor_flag { diff --git a/examples/trusted-sync/src/metrics.rs b/examples/trusted-sync/src/metrics.rs index 0d35bd7ca..c93db32c9 100644 --- a/examples/trusted-sync/src/metrics.rs +++ b/examples/trusted-sync/src/metrics.rs @@ -44,6 +44,13 @@ lazy_static! { pub static ref REFERENCE_L2_HEAD: IntGauge = register_int_gauge!("trusted_sync_reference_l2_head", "Reference L2 head").expect("Failed to register reference L2 head metric"); + /// Tracks the latest reference l2 safe head update. + pub static ref LATEST_REF_SAFE_HEAD_UPDATE: IntGauge = register_int_gauge!( + "trusted_sync_latest_ref_safe_head_update", + "Latest reference L2 safe head update" + ) + .expect("Failed to register latest reference L2 safe head update metric"); + /// Tracks the number of pipeline steps. pub static ref PIPELINE_STEPS: GaugeVec = { let opts = opts!("trusted_sync_pipeline_steps", "Number of pipeline steps");