mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user