Skip to content

Commit

Permalink
chore(tree): add legacy tree metrics to new engine (#11175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Sep 25, 2024
1 parent 76a6e0d commit 3a5001a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
40 changes: 20 additions & 20 deletions crates/blockchain-tree/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/tree/src/tree/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use reth_blockchain_tree::metrics::TreeMetrics;
use reth_evm::metrics::ExecutorMetrics;
use reth_metrics::{
metrics::{Counter, Gauge, Histogram},
Expand All @@ -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`.
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3a5001a

Please sign in to comment.