Make stake sorting more deterministic for data plane

This commit is contained in:
Sagar Dhawan 2019-02-26 11:59:04 -08:00
parent 82c759b6cb
commit ee83a2ac29
1 changed files with 8 additions and 2 deletions

View File

@ -373,8 +373,14 @@ impl ClusterInfo {
.iter()
.map(|c| (*stakes.get(&c.id).unwrap_or(&0), c.clone()))
.collect();
peers_with_stakes.sort_unstable();
peers_with_stakes.reverse();
peers_with_stakes.sort_unstable_by(|(l_stake, l_info), (r_stake, r_info)| {
if r_stake == l_stake {
r_info.id.cmp(&l_info.id)
} else {
r_stake.cmp(&l_stake)
}
});
peers_with_stakes.dedup();
peers_with_stakes
}