mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-07 15:28:02 +00:00
Fixed sync target detection (#11817)
* Fixed sync target detection * Always report sync_target metric * Clamp median across all peers
This commit is contained in:
@@ -1719,7 +1719,7 @@ where
|
||||
Ok(sync)
|
||||
}
|
||||
|
||||
/// Returns the best seen block.
|
||||
/// Returns the best seen block number if we don't have that block yet, `None` otherwise.
|
||||
fn best_seen(&self) -> Option<NumberFor<B>> {
|
||||
let mut best_seens = self.peers.values().map(|p| p.best_number).collect::<Vec<_>>();
|
||||
|
||||
@@ -1729,7 +1729,12 @@ where
|
||||
let middle = best_seens.len() / 2;
|
||||
|
||||
// Not the "perfect median" when we have an even number of peers.
|
||||
Some(*best_seens.select_nth_unstable(middle).1)
|
||||
let median = *best_seens.select_nth_unstable(middle).1;
|
||||
if median > self.best_queued_number {
|
||||
Some(median)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,9 +298,10 @@ impl MetricsService {
|
||||
UniqueSaturatedInto::<u64>::unique_saturated_into(num)
|
||||
});
|
||||
|
||||
if let Some(best_seen_block) = best_seen_block {
|
||||
metrics.block_height.with_label_values(&["sync_target"]).set(best_seen_block);
|
||||
}
|
||||
metrics
|
||||
.block_height
|
||||
.with_label_values(&["sync_target"])
|
||||
.set(best_seen_block.unwrap_or(best_number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user