Tie-break with sync distance for non-synced nodes

This commit is contained in:
Mac L
2023-06-13 17:35:18 +10:00
parent 52f2be5cf2
commit ce4df50af5

View File

@@ -98,7 +98,19 @@ impl Display for BeaconNodeHealthTier {
impl Ord for BeaconNodeHealthTier {
fn cmp(&self, other: &Self) -> Ordering {
self.tier.cmp(&other.tier)
let ordering = self.tier.cmp(&other.tier);
if ordering == Ordering::Equal {
// These tiers represent `synced`.
if [1, 3, 5, 6].contains(&self.tier) {
// Don't tie-break on sync distance in these cases.
// This ensures validator clients don't artificially prefer one node.
ordering
} else {
self.sync_distance.cmp(&other.sync_distance)
}
} else {
ordering
}
}
}