Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add tip height metric #3964

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -799,13 +799,16 @@ where B: BlockchainBackend + 'static

match block_add_result {
BlockAddResult::Ok(ref block) => {
metrics::tip_height().set(block.height() as i64);
update_target_difficulty(block);
let utxo_set_size = self.blockchain_db.utxo_count().await?;
metrics::utxo_set_size().set(utxo_set_size.try_into().unwrap_or(i64::MAX));
},
BlockAddResult::ChainReorg { added, removed } => {
let fork_height = added.last().map(|b| b.height() - 1).unwrap_or_default();
metrics::reorg(fork_height, added.len(), removed.len()).inc();
if let Some(fork_height) = added.last().map(|b| b.height()) {
metrics::tip_height().set(fork_height as i64);
metrics::reorg(fork_height, added.len(), removed.len()).inc();
}
for block in added {
update_target_difficulty(block);
}
Expand Down
8 changes: 8 additions & 0 deletions base_layer/core/src/base_node/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ use once_cell::sync::Lazy;
use tari_metrics::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec};
use tari_utilities::hex::to_hex;

pub fn tip_height() -> IntGauge {
static METER: Lazy<IntGauge> = Lazy::new(|| {
tari_metrics::register_int_gauge("base_node::blockchain::tip_height", "The current tip height").unwrap()
});

METER.clone()
}

pub fn target_difficulty_sha(height: u64) -> IntGauge {
static METER: Lazy<IntGaugeVec> = Lazy::new(|| {
tari_metrics::register_int_gauge_vec(
Expand Down
4 changes: 3 additions & 1 deletion base_layer/core/src/chain_storage/block_add_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub enum BlockAddResult {
Ok(Arc<ChainBlock>),
BlockExists,
OrphanBlock,
/// Indicates the new block caused a chain reorg. This contains removed blocks followed by added blocks.
/// Indicates the new block caused a chain reorg.
/// This contains added blocks ordered from lowest to highest block height, and
/// the removed blocks ordered from highest to lowest block height.
ChainReorg {
added: Vec<Arc<ChainBlock>>,
removed: Vec<Arc<ChainBlock>>,
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ fn handle_possible_reorg<T: BlockchainBackend>(
}

/// Reorganize the main chain with the provided fork chain, starting at the specified height.
/// Returns the blocks that were removed (if any), ordered from tip to fork (ie. height desc).
/// Returns the blocks that were removed (if any), ordered from tip to fork (ie. height highest to lowest).
fn reorganize_chain<T: BlockchainBackend>(
backend: &mut T,
block_validator: &dyn PostOrphanBodyValidation<T>,
Expand Down