behzad nouri 2023-08-31 22:35:47 +00:00 committed by GitHub
parent c87f9cdfc9
commit 39615bd075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 64 deletions

View File

@ -1107,19 +1107,18 @@ impl ClusterInfo {
self.time_gossip_read_lock("gossip_read_push_vote", &self.stats.push_vote_read);
(0..MAX_LOCKOUT_HISTORY as u8).find(|ix| {
let vote = CrdsValueLabel::Vote(*ix, self_pubkey);
if let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) {
match &vote {
CrdsData::Vote(_, prev_vote) => match prev_vote.slot() {
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
None => {
error!("crds vote with no slots!");
false
}
},
_ => panic!("this should not happen!"),
let Some(vote) = gossip_crds.get::<&CrdsData>(&vote) else {
return false;
};
let CrdsData::Vote(_, prev_vote) = &vote else {
panic!("this should not happen!");
};
match prev_vote.slot() {
Some(prev_vote_slot) => prev_vote_slot == vote_slot,
None => {
error!("crds vote with no slots!");
false
}
} else {
false
}
})
};
@ -1153,11 +1152,10 @@ impl ClusterInfo {
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
.get_votes(cursor)
.map(|vote| {
let transaction = match &vote.value.data {
CrdsData::Vote(_, vote) => vote.transaction().clone(),
_ => panic!("this should not happen!"),
let CrdsData::Vote(_, vote) = &vote.value.data else {
panic!("this should not happen!");
};
transaction
vote.transaction().clone()
})
.collect();
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
@ -1173,11 +1171,11 @@ impl ClusterInfo {
.time_gossip_read_lock("get_votes", &self.stats.get_votes)
.get_votes(cursor)
.map(|vote| {
let transaction = match &vote.value.data {
CrdsData::Vote(_, vote) => vote.transaction().clone(),
_ => panic!("this should not happen!"),
let label = vote.value.label();
let CrdsData::Vote(_, vote) = &vote.value.data else {
panic!("this should not happen!");
};
(vote.value.label(), transaction)
(label, vote.transaction().clone())
})
.unzip();
self.stats.get_votes_count.add_relaxed(txs.len() as u64);
@ -3898,12 +3896,10 @@ mod tests {
let gossip_crds = cluster_info.gossip.crds.read().unwrap();
let mut vote_slots = HashSet::new();
for label in labels {
match &gossip_crds.get::<&CrdsData>(&label).unwrap() {
CrdsData::Vote(_, vote) => {
assert!(vote_slots.insert(vote.slot().unwrap()));
}
_ => panic!("this should not happen!"),
}
let CrdsData::Vote(_, vote) = &gossip_crds.get::<&CrdsData>(&label).unwrap() else {
panic!("this should not happen!");
};
assert!(vote_slots.insert(vote.slot().unwrap()));
}
vote_slots.into_iter().collect()
};

View File

@ -549,9 +549,8 @@ impl Crds {
self.entries.remove(&value.ordinal);
// Remove the index from records associated with the value's pubkey.
let pubkey = value.value.pubkey();
let mut records_entry = match self.records.entry(pubkey) {
hash_map::Entry::Vacant(_) => panic!("this should not happen!"),
hash_map::Entry::Occupied(entry) => entry,
let hash_map::Entry::Occupied(mut records_entry) = self.records.entry(pubkey) else {
panic!("this should not happen!");
};
records_entry.get_mut().swap_remove(&index);
if records_entry.get().is_empty() {
@ -905,10 +904,7 @@ mod tests {
let other = NodeInstance::new(&mut rng, pubkey, now + k);
let other = other.with_wallclock(now - 1);
let other = make_crds_value(other);
match crds.insert(other, now, GossipRoute::LocalMessage) {
Ok(()) => (),
_ => panic!(),
}
assert_matches!(crds.insert(other, now, GossipRoute::LocalMessage), Ok(()));
}
}
@ -1148,10 +1144,7 @@ mod tests {
);
for value in crds.get_epoch_slots(&mut Cursor(since)) {
assert!(value.ordinal >= since);
match value.value.data {
CrdsData::EpochSlots(_, _) => (),
_ => panic!("not an epoch-slot!"),
}
assert_matches!(value.value.data, CrdsData::EpochSlots(_, _));
}
let num_votes = crds
.table
@ -1174,10 +1167,7 @@ mod tests {
);
for value in crds.get_votes(&mut Cursor(since)) {
assert!(value.ordinal >= since);
match value.value.data {
CrdsData::Vote(_, _) => (),
_ => panic!("not a vote!"),
}
assert_matches!(value.value.data, CrdsData::Vote(_, _));
}
let num_entries = crds
.table
@ -1224,16 +1214,10 @@ mod tests {
crds.get_epoch_slots(&mut Cursor::default()).count()
);
for vote in crds.get_votes(&mut Cursor::default()) {
match vote.value.data {
CrdsData::Vote(_, _) => (),
_ => panic!("not a vote!"),
}
assert_matches!(vote.value.data, CrdsData::Vote(_, _));
}
for epoch_slots in crds.get_epoch_slots(&mut Cursor::default()) {
match epoch_slots.value.data {
CrdsData::EpochSlots(_, _) => (),
_ => panic!("not an epoch-slot!"),
}
assert_matches!(epoch_slots.value.data, CrdsData::EpochSlots(_, _));
}
(num_nodes, num_votes, num_epoch_slots)
}

View File

@ -209,18 +209,16 @@ impl BankForks {
pub fn remove(&mut self, slot: Slot) -> Option<Arc<Bank>> {
let bank = self.banks.remove(&slot)?;
for parent in bank.proper_ancestors() {
let mut entry = match self.descendants.entry(parent) {
Entry::Vacant(_) => panic!("this should not happen!"),
Entry::Occupied(entry) => entry,
let Entry::Occupied(mut entry) = self.descendants.entry(parent) else {
panic!("this should not happen!");
};
entry.get_mut().remove(&slot);
if entry.get().is_empty() && !self.banks.contains_key(&parent) {
entry.remove_entry();
}
}
let entry = match self.descendants.entry(slot) {
Entry::Vacant(_) => panic!("this should not happen!"),
Entry::Occupied(entry) => entry,
let Entry::Occupied(entry) = self.descendants.entry(slot) else {
panic!("this should not happen!");
};
if entry.get().is_empty() {
entry.remove_entry();

View File

@ -198,15 +198,15 @@ impl VoteAccounts {
return;
};
if let Some(node_pubkey) = vote_account.node_pubkey() {
match Arc::make_mut(staked_nodes).entry(node_pubkey) {
Entry::Vacant(_) => panic!("this should not happen!"),
Entry::Occupied(mut entry) => match entry.get().cmp(&stake) {
Ordering::Less => panic!("subtraction value exceeds node's stake"),
Ordering::Equal => {
entry.remove_entry();
}
Ordering::Greater => *entry.get_mut() -= stake,
},
let Entry::Occupied(mut entry) = Arc::make_mut(staked_nodes).entry(node_pubkey) else {
panic!("this should not happen!");
};
match entry.get().cmp(&stake) {
Ordering::Less => panic!("subtraction value exceeds node's stake"),
Ordering::Equal => {
entry.remove_entry();
}
Ordering::Greater => *entry.get_mut() -= stake,
}
}
}