feat: metric of reorg depth of blockchain tree (#3860)

This commit is contained in:
int88
2023-07-27 07:00:38 +08:00
committed by GitHub
parent 9adab0ba7c
commit b5a44aeb37
3 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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,
}