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