From c848b7f12231f9e2d604e3bf41a98464dc4a49a4 Mon Sep 17 00:00:00 2001 From: Sishan Long Date: Mon, 11 Dec 2023 11:08:21 -0800 Subject: [PATCH 1/2] fix metrics: block height --- crates/task-impls/src/consensus.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/task-impls/src/consensus.rs b/crates/task-impls/src/consensus.rs index 98eaca2369..1e88904b94 100644 --- a/crates/task-impls/src/consensus.rs +++ b/crates/task-impls/src/consensus.rs @@ -582,6 +582,7 @@ impl, A: ConsensusApi + let mut current_chain_length = 0usize; if parent_view + 1 == view { current_chain_length += 1; + let mut is_ancestor = false; // For metrics use: mark whether we're going to the ancestor of the leaf, only assign block_height for the most recent one. if let Err(e) = consensus.visit_leaf_ancestors( parent_view, Terminator::Exclusive(old_anchor_view), @@ -609,11 +610,13 @@ impl, A: ConsensusApi + // starting from the first iteration with a three chain, e.g. right after the else if case nested in the if case above if new_decide_reached { let mut leaf = leaf.clone(); - consensus - .metrics - .last_synced_block_height - .set(usize::try_from(leaf.get_height()).unwrap_or(0)); - + if !is_ancestor { + consensus + .metrics + .last_synced_block_height + .set(usize::try_from(leaf.get_height()).unwrap_or(0)); + } + is_ancestor = true; // If the block payload is available for this leaf, include it in // the leaf chain that we send to the client. if let Some(encoded_txns) = From 2b0dd9c61e0b9f4f518a3d3167902c5eec5a8f02 Mon Sep 17 00:00:00 2001 From: Sishan Long Date: Mon, 11 Dec 2023 11:49:26 -0800 Subject: [PATCH 2/2] update if condition --- crates/task-impls/src/consensus.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/task-impls/src/consensus.rs b/crates/task-impls/src/consensus.rs index 1e88904b94..77e50ef3ce 100644 --- a/crates/task-impls/src/consensus.rs +++ b/crates/task-impls/src/consensus.rs @@ -582,7 +582,6 @@ impl, A: ConsensusApi + let mut current_chain_length = 0usize; if parent_view + 1 == view { current_chain_length += 1; - let mut is_ancestor = false; // For metrics use: mark whether we're going to the ancestor of the leaf, only assign block_height for the most recent one. if let Err(e) = consensus.visit_leaf_ancestors( parent_view, Terminator::Exclusive(old_anchor_view), @@ -610,13 +609,12 @@ impl, A: ConsensusApi + // starting from the first iteration with a three chain, e.g. right after the else if case nested in the if case above if new_decide_reached { let mut leaf = leaf.clone(); - if !is_ancestor { + if leaf.view_number == new_anchor_view { consensus .metrics .last_synced_block_height .set(usize::try_from(leaf.get_height()).unwrap_or(0)); } - is_ancestor = true; // If the block payload is available for this leaf, include it in // the leaf chain that we send to the client. if let Some(encoded_txns) =