mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: metric of reorg depth of blockchain tree (#3860)
This commit is contained in:
@ -1001,9 +1001,12 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
|
||||
old: Arc::new(old_canon_chain.clone()),
|
||||
new: Arc::new(new_canon_chain.clone()),
|
||||
};
|
||||
let reorg_depth = old_canon_chain.len();
|
||||
|
||||
// insert old canon chain
|
||||
self.insert_chain(AppendableChain::new(old_canon_chain));
|
||||
self.metrics.reorgs.increment(1);
|
||||
|
||||
self.update_reorg_metrics(reorg_depth as f64);
|
||||
} else {
|
||||
// error here to confirm that we are reverting nothing from db.
|
||||
error!(target: "blockchain_tree", "Reverting nothing from db on block: #{:?}", block_hash);
|
||||
@ -1094,6 +1097,11 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
|
||||
}
|
||||
}
|
||||
|
||||
fn update_reorg_metrics(&mut self, reorg_depth: f64) {
|
||||
self.metrics.reorgs.increment(1);
|
||||
self.metrics.latest_reorg_depth.set(reorg_depth);
|
||||
}
|
||||
|
||||
/// Update blockchain tree chains (canonical and sidechains) and sync metrics.
|
||||
///
|
||||
/// NOTE: this method should not be called during the pipeline sync, because otherwise the sync
|
||||
|
||||
@ -13,6 +13,8 @@ pub struct TreeMetrics {
|
||||
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user