From 653c0898a869c0d2a60cc1c5711c2cdded99e700 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:49:27 -0400 Subject: [PATCH] chore(tree): add legacy tree metrics to new engine (#11175) --- crates/blockchain-tree/src/metrics.rs | 40 +++++++++++++------------- crates/engine/tree/src/tree/metrics.rs | 3 ++ crates/engine/tree/src/tree/mod.rs | 4 +++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/crates/blockchain-tree/src/metrics.rs b/crates/blockchain-tree/src/metrics.rs index 5d44a6391178..121d0a69786f 100644 --- a/crates/blockchain-tree/src/metrics.rs +++ b/crates/blockchain-tree/src/metrics.rs @@ -5,26 +5,6 @@ use reth_metrics::{ }; use std::time::{Duration, Instant}; -/// Metrics for the entire blockchain tree -#[derive(Metrics)] -#[metrics(scope = "blockchain_tree")] -pub struct TreeMetrics { - /// Total number of sidechains (not including the canonical chain) - pub sidechains: Gauge, - /// The highest block number in the canonical chain - pub canonical_chain_height: Gauge, - /// The number of reorgs - pub reorgs: Counter, - /// The latest reorg depth - pub latest_reorg_depth: Gauge, - /// Longest sidechain height - pub longest_sidechain_height: Gauge, - /// The number of times cached trie updates were used for insert. - pub trie_updates_insert_cached: Counter, - /// The number of times trie updates were recomputed for insert. - pub trie_updates_insert_recomputed: Counter, -} - /// Metrics for the blockchain tree block buffer #[derive(Metrics)] #[metrics(scope = "blockchain_tree.block_buffer")] @@ -65,6 +45,26 @@ impl MakeCanonicalDurationsRecorder { } } +/// Metrics for the entire blockchain tree +#[derive(Metrics)] +#[metrics(scope = "blockchain_tree")] +pub struct TreeMetrics { + /// Total number of sidechains (not including the canonical chain) + pub sidechains: Gauge, + /// The highest block number in the canonical chain + pub canonical_chain_height: Gauge, + /// The number of reorgs + pub reorgs: Counter, + /// The latest reorg depth + pub latest_reorg_depth: Gauge, + /// Longest sidechain height + pub longest_sidechain_height: Gauge, + /// The number of times cached trie updates were used for insert. + pub trie_updates_insert_cached: Counter, + /// The number of times trie updates were recomputed for insert. + pub trie_updates_insert_recomputed: Counter, +} + /// Represents actions for making a canonical chain. #[derive(Debug, Copy, Clone)] pub(crate) enum MakeCanonicalAction { diff --git a/crates/engine/tree/src/tree/metrics.rs b/crates/engine/tree/src/tree/metrics.rs index 2df1fbdac700..922041ae7151 100644 --- a/crates/engine/tree/src/tree/metrics.rs +++ b/crates/engine/tree/src/tree/metrics.rs @@ -1,3 +1,4 @@ +use reth_blockchain_tree::metrics::TreeMetrics; use reth_evm::metrics::ExecutorMetrics; use reth_metrics::{ metrics::{Counter, Gauge, Histogram}, @@ -13,6 +14,8 @@ pub(crate) struct EngineApiMetrics { pub(crate) executor: ExecutorMetrics, /// Metrics for block validation pub(crate) block_validation: BlockValidationMetrics, + /// A copy of legacy blockchain tree metrics, to be replaced when we replace the old tree + pub(crate) tree: TreeMetrics, } /// Metrics for the `EngineApi`. diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 3dd736cdc10f..10654223ca41 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -1291,6 +1291,7 @@ where backfill_num_hash, ); self.metrics.engine.executed_blocks.set(self.state.tree_state.block_count() as f64); + self.metrics.tree.canonical_chain_height.set(backfill_height as f64); // remove all buffered blocks below the backfill height self.state.buffer.remove_old_blocks(backfill_height); @@ -1956,6 +1957,9 @@ where self.canonical_in_memory_state.update_chain(chain_update); self.canonical_in_memory_state.set_canonical_head(tip.clone()); + // Update metrics based on new tip + self.metrics.tree.canonical_chain_height.set(tip.number as f64); + // sends an event to all active listeners about the new canonical chain self.canonical_in_memory_state.notify_canon_state(notification);