Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixed sync target detection (#11817)
Browse files Browse the repository at this point in the history
* Fixed sync target detection

* Always report sync_target metric

* Clamp median across all peers
  • Loading branch information
arkpar authored Jul 15, 2022
1 parent 66d2023 commit 4a19d40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>();

Expand All @@ -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
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions client/service/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit 4a19d40

Please sign in to comment.