adjust normalized stake calculation in compute_weight (#29694)
This commit is contained in:
parent
e1d38c8315
commit
f6fcb14a3e
|
@ -195,7 +195,7 @@ impl ClusterSlots {
|
|||
.iter()
|
||||
.map(|peer| slot_peers.get(&peer.id).cloned().unwrap_or(0))
|
||||
.zip(stakes)
|
||||
.map(|(a, b)| a + b)
|
||||
.map(|(a, b)| (a / 2 + b / 2).max(1u64))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -204,16 +204,16 @@ impl ClusterSlots {
|
|||
slot: Slot,
|
||||
repair_peers: &[ContactInfo],
|
||||
) -> Vec<(u64, usize)> {
|
||||
let slot_peers = self.lookup(slot);
|
||||
self.lookup(slot)
|
||||
.map(|slot_peers| {
|
||||
let slot_peers = slot_peers.read().unwrap();
|
||||
repair_peers
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, x)| {
|
||||
slot_peers
|
||||
.as_ref()
|
||||
.and_then(|v| v.read().unwrap().get(&x.id).map(|stake| (*stake + 1, i)))
|
||||
})
|
||||
.filter_map(|(i, ci)| Some((slot_peers.get(&ci.id)? + 1, i)))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,10 +293,7 @@ mod tests {
|
|||
.insert(0, Arc::new(RwLock::new(map)));
|
||||
c1.id = k1;
|
||||
c2.id = k2;
|
||||
assert_eq!(
|
||||
cs.compute_weights(0, &[c1, c2]),
|
||||
vec![std::u64::MAX / 2 + 1, 1]
|
||||
);
|
||||
assert_eq!(cs.compute_weights(0, &[c1, c2]), vec![std::u64::MAX / 4, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -327,7 +324,7 @@ mod tests {
|
|||
c2.id = k2;
|
||||
assert_eq!(
|
||||
cs.compute_weights(0, &[c1, c2]),
|
||||
vec![std::u64::MAX / 2 + 1, 1]
|
||||
vec![std::u64::MAX / 4 + 1, 1]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue