From d12752dc8a432657765b8bef0f0c46b3d91ed6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=82=8A=E3=82=93=E3=81=A8=E3=81=86?= Date: Tue, 20 Jan 2026 22:06:11 +0100 Subject: [PATCH] feat(engine): add time_between_forkchoice_updated metric (#21227) --- crates/engine/tree/src/tree/metrics.rs | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/engine/tree/src/tree/metrics.rs b/crates/engine/tree/src/tree/metrics.rs index 303f3c6298..3d05cee8e0 100644 --- a/crates/engine/tree/src/tree/metrics.rs +++ b/crates/engine/tree/src/tree/metrics.rs @@ -210,6 +210,12 @@ pub(crate) struct EngineMetrics { #[derive(Metrics)] #[metrics(scope = "consensus.engine.beacon")] pub(crate) struct ForkchoiceUpdatedMetrics { + /// Finish time of the latest forkchoice updated call. + #[metric(skip)] + pub(crate) latest_finish_at: Option, + /// Start time of the latest forkchoice updated call. + #[metric(skip)] + pub(crate) latest_start_at: Option, /// The total count of forkchoice updated messages received. pub(crate) forkchoice_updated_messages: Counter, /// The total count of forkchoice updated messages with payload received. @@ -232,18 +238,35 @@ pub(crate) struct ForkchoiceUpdatedMetrics { pub(crate) forkchoice_updated_last: Gauge, /// Time diff between new payload call response and the next forkchoice updated call request. pub(crate) new_payload_forkchoice_updated_time_diff: Histogram, + /// Time from previous forkchoice updated finish to current forkchoice updated start (idle + /// time). + pub(crate) time_between_forkchoice_updated: Histogram, + /// Time from previous forkchoice updated start to current forkchoice updated start (total + /// interval). + pub(crate) forkchoice_updated_interval: Histogram, } impl ForkchoiceUpdatedMetrics { /// Increment the forkchoiceUpdated counter based on the given result pub(crate) fn update_response_metrics( - &self, + &mut self, start: Instant, latest_new_payload_at: &mut Option, has_attrs: bool, result: &Result, ProviderError>, ) { - let elapsed = start.elapsed(); + let finish = Instant::now(); + let elapsed = finish - start; + + if let Some(prev_finish) = self.latest_finish_at { + self.time_between_forkchoice_updated.record(start - prev_finish); + } + if let Some(prev_start) = self.latest_start_at { + self.forkchoice_updated_interval.record(start - prev_start); + } + self.latest_finish_at = Some(finish); + self.latest_start_at = Some(start); + match result { Ok(outcome) => match outcome.outcome.forkchoice_status() { ForkchoiceStatus::Valid => self.forkchoice_updated_valid.increment(1),