From d54dc685a3cbf03e2d5b5f153b10124c514d51e2 Mon Sep 17 00:00:00 2001 From: chonghe <44791194+chong-he@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:26:20 +0800 Subject: [PATCH] Add `optimistic_sync` metric (#8059) * #7974 Display `0` if optimistic sync and `1` for normal sync Co-Authored-By: Tan Chee Keong Co-Authored-By: chonghe <44791194+chong-he@users.noreply.github.com> --- beacon_node/client/src/metrics.rs | 7 +++++++ beacon_node/client/src/notifier.rs | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/beacon_node/client/src/metrics.rs b/beacon_node/client/src/metrics.rs index 605a734688..6ff3eb6a70 100644 --- a/beacon_node/client/src/metrics.rs +++ b/beacon_node/client/src/metrics.rs @@ -15,6 +15,13 @@ pub static IS_SYNCED: LazyLock> = LazyLock::new(|| { ) }); +pub static IS_OPTIMISTIC_SYNC: LazyLock> = LazyLock::new(|| { + try_create_int_gauge( + "optimistic_sync", + "Metric to check if the beacon chain is in optimistic sync mode. 0 if synced and 1 if optimistic sync", + ) +}); + pub static NOTIFIER_HEAD_SLOT: LazyLock> = LazyLock::new(|| { try_create_int_gauge( "notifier_head_slot", diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index b1cf1bd7f5..52a3b92cb6 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -369,8 +369,12 @@ pub fn spawn_notifier( let block_hash = match beacon_chain.canonical_head.head_execution_status() { Ok(ExecutionStatus::Irrelevant(_)) => "n/a".to_string(), - Ok(ExecutionStatus::Valid(hash)) => format!("{} (verified)", hash), + Ok(ExecutionStatus::Valid(hash)) => { + metrics::set_gauge(&metrics::IS_OPTIMISTIC_SYNC, 0); + format!("{} (verified)", hash) + } Ok(ExecutionStatus::Optimistic(hash)) => { + metrics::set_gauge(&metrics::IS_OPTIMISTIC_SYNC, 1); warn!( info = "chain not fully verified, \ block and attestation production disabled until execution engine syncs",