Skip to content

Commit

Permalink
feat(tree): introduce reorg count metrics in new engine (#11226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Sep 26, 2024
1 parent ad64de8 commit f4cbfbc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,7 @@ where
let old_first = old.first().map(|first| first.block.num_hash());
trace!(target: "engine::tree", ?new_first, ?old_first, "Reorg detected, new and old first blocks");

self.update_reorg_metrics(old.len());
self.reinsert_reorged_blocks(new.clone());
self.reinsert_reorged_blocks(old.clone());
}
Expand All @@ -1973,6 +1974,12 @@ where
));
}

/// This updates metrics based on the given reorg length.
fn update_reorg_metrics(&self, old_chain_length: usize) {
self.metrics.tree.reorgs.increment(1);
self.metrics.tree.latest_reorg_depth.set(old_chain_length as f64);
}

/// This reinserts any blocks in the new chain that do not already exist in the tree
fn reinsert_reorged_blocks(&mut self, new_chain: Vec<ExecutedBlock>) {
for block in new_chain {
Expand Down

0 comments on commit f4cbfbc

Please sign in to comment.