Hoist keypair() out of some loops

This commit is contained in:
Michael Vines
2021-06-29 09:17:05 -07:00
parent b6792a3328
commit 71efac46cb

View File

@ -955,6 +955,7 @@ impl ClusterInfo {
None => 0, None => 0,
}; };
let mut entries = Vec::default(); let mut entries = Vec::default();
let keypair = self.keypair();
while !update.is_empty() { while !update.is_empty() {
let ix = (epoch_slot_index % crds_value::MAX_EPOCH_SLOTS) as u8; let ix = (epoch_slot_index % crds_value::MAX_EPOCH_SLOTS) as u8;
let now = timestamp(); let now = timestamp();
@ -967,7 +968,7 @@ impl ClusterInfo {
update = &update[n..]; update = &update[n..];
if n > 0 { if n > 0 {
let epoch_slots = CrdsData::EpochSlots(ix, slots); let epoch_slots = CrdsData::EpochSlots(ix, slots);
let entry = CrdsValue::new_signed(epoch_slots, &self.keypair()); let entry = CrdsValue::new_signed(epoch_slots, &keypair);
entries.push(entry); entries.push(entry);
} }
epoch_slot_index += 1; epoch_slot_index += 1;
@ -2286,10 +2287,11 @@ impl ClusterInfo {
where where
I: IntoIterator<Item = (SocketAddr, Ping)>, I: IntoIterator<Item = (SocketAddr, Ping)>,
{ {
let keypair = self.keypair();
let packets: Vec<_> = pings let packets: Vec<_> = pings
.into_iter() .into_iter()
.filter_map(|(addr, ping)| { .filter_map(|(addr, ping)| {
let pong = Pong::new(&ping, &self.keypair()).ok()?; let pong = Pong::new(&ping, &keypair).ok()?;
let pong = Protocol::PongMessage(pong); let pong = Protocol::PongMessage(pong);
match Packet::from_data(Some(&addr), pong) { match Packet::from_data(Some(&addr), pong) {
Ok(packet) => Some(packet), Ok(packet) => Some(packet),