Skip to content

Commit

Permalink
filter out unstaked NodeInstance from sent PullRequests (#2637)
Browse files Browse the repository at this point in the history
* filter out unstaked NodeInstance from sent PullRequests

* add descriptor, refactor retain_staked()

---------

Co-authored-by: greg <[email protected]>
  • Loading branch information
gregcusack and gregcusack authored Aug 20, 2024
1 parent acaf5b7 commit 485216b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ impl Sanitize for Protocol {

// Retains only CRDS values associated with nodes with enough stake.
// (some crds types are exempted)
fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
fn retain_staked(
values: &mut Vec<CrdsValue>,
stakes: &HashMap<Pubkey, u64>,
drop_unstaked_node_instance: bool,
) {
values.retain(|value| {
match value.data {
CrdsData::ContactInfo(_) => true,
Expand All @@ -434,6 +438,7 @@ fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
// the various dashboards.
CrdsData::Version(_) => true,
CrdsData::AccountsHashes(_) => true,
CrdsData::NodeInstance(_) if !drop_unstaked_node_instance => true,
CrdsData::LowestSlot(_, _)
| CrdsData::LegacyVersion(_)
| CrdsData::DuplicateShred(_, _)
Expand Down Expand Up @@ -1646,7 +1651,7 @@ impl ClusterInfo {
.add_relaxed(num_nodes as u64);
if self.require_stake_for_gossip(stakes) {
push_messages.retain(|_, data| {
retain_staked(data, stakes);
retain_staked(data, stakes, /* drop_unstaked_node_instance */ false);
!data.is_empty()
})
}
Expand Down Expand Up @@ -2138,7 +2143,7 @@ impl ClusterInfo {
};
if self.require_stake_for_gossip(stakes) {
for resp in &mut pull_responses {
retain_staked(resp, stakes);
retain_staked(resp, stakes, /* drop_unstaked_node_instance */ true);
}
}
let (responses, scores): (Vec<_>, Vec<_>) = addrs
Expand Down Expand Up @@ -2544,9 +2549,13 @@ impl ClusterInfo {
}
}
if self.require_stake_for_gossip(stakes) {
retain_staked(&mut pull_responses, stakes);
retain_staked(
&mut pull_responses,
stakes,
/* drop_unstaked_node_instance */ false,
);
for (_, data) in &mut push_messages {
retain_staked(data, stakes);
retain_staked(data, stakes, /* drop_unstaked_node_instance */ false);
}
push_messages.retain(|(_, data)| !data.is_empty());
}
Expand Down

0 comments on commit 485216b

Please sign in to comment.