From b7d2ee25666ac21034664c9cd6704d388e3d7c07 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Wed, 21 Jan 2026 12:17:45 -0800 Subject: [PATCH] feat(engine): add metric for execution cache unavailability due to concurrent use (#21265) Co-authored-by: Tempo AI Co-authored-by: Alexey Shekhirin --- .../tree/src/tree/payload_processor/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/engine/tree/src/tree/payload_processor/mod.rs b/crates/engine/tree/src/tree/payload_processor/mod.rs index 1fa4232b0e..6d61578f63 100644 --- a/crates/engine/tree/src/tree/payload_processor/mod.rs +++ b/crates/engine/tree/src/tree/payload_processor/mod.rs @@ -19,6 +19,7 @@ use alloy_evm::{block::StateChangeSource, ToTxEnv}; use alloy_primitives::B256; use crossbeam_channel::Sender as CrossbeamSender; use executor::WorkloadExecutor; +use metrics::Counter; use multiproof::{SparseTrieUpdate, *}; use parking_lot::RwLock; use prewarm::PrewarmMetrics; @@ -28,6 +29,7 @@ use reth_evm::{ ConfigureEvm, EvmEnvFor, ExecutableTxIterator, ExecutableTxTuple, OnStateHook, SpecFor, TxEnvFor, }; +use reth_metrics::Metrics; use reth_primitives_traits::NodePrimitives; use reth_provider::{ BlockExecutionOutput, BlockReader, DatabaseProviderROFactory, StateProvider, @@ -788,6 +790,8 @@ impl Drop for CacheTaskHandle { struct ExecutionCache { /// Guarded cloneable cache identified by a block hash. inner: Arc>>, + /// Metrics for cache operations. + metrics: ExecutionCacheMetrics, } impl ExecutionCache { @@ -829,6 +833,10 @@ impl ExecutionCache { if hash_matches && available { return Some(c.clone()); } + + if hash_matches && !available { + self.metrics.execution_cache_in_use.increment(1); + } } else { debug!(target: "engine::caching", %parent_hash, "No cache found"); } @@ -864,6 +872,15 @@ impl ExecutionCache { } } +/// Metrics for execution cache operations. +#[derive(Metrics, Clone)] +#[metrics(scope = "consensus.engine.beacon")] +pub(crate) struct ExecutionCacheMetrics { + /// Counter for when the execution cache was unavailable because other threads + /// (e.g., prewarming) are still using it. + pub(crate) execution_cache_in_use: Counter, +} + /// EVM context required to execute a block. #[derive(Debug, Clone)] pub struct ExecutionEnv {