From 67d48bc7c0840b77b1a326cf9b64cc825cc3cdbe Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 16 Aug 2024 17:28:11 +0000 Subject: [PATCH 1/2] filter out unstaked NodeInstance from sent PullRequests --- gossip/src/cluster_info.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index d3b0a9857481cb..2f60550b00f24e 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -419,7 +419,14 @@ 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, stakes: &HashMap) { +fn retain_staked( + values: &mut Vec, + stakes: &HashMap, + drop_unstaked_node_instance: bool, +) { + let has_min_stake_for_gossip = + |pubkey: &Pubkey| stakes.get(pubkey).copied().unwrap_or_default() >= MIN_STAKE_FOR_GOSSIP; + values.retain(|value| { match value.data { CrdsData::ContactInfo(_) => true, @@ -438,10 +445,13 @@ fn retain_staked(values: &mut Vec, stakes: &HashMap) { | CrdsData::LegacyVersion(_) | CrdsData::DuplicateShred(_, _) | CrdsData::RestartHeaviestFork(_) - | CrdsData::RestartLastVotedForkSlots(_) - | CrdsData::NodeInstance(_) => { - let stake = stakes.get(&value.pubkey()).copied(); - stake.unwrap_or_default() >= MIN_STAKE_FOR_GOSSIP + | CrdsData::RestartLastVotedForkSlots(_) => has_min_stake_for_gossip(&value.pubkey()), + CrdsData::NodeInstance(_) => { + if drop_unstaked_node_instance { + has_min_stake_for_gossip(&value.pubkey()) + } else { + true + } } } }) @@ -1646,7 +1656,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, false); !data.is_empty() }) } @@ -2138,7 +2148,7 @@ impl ClusterInfo { }; if self.require_stake_for_gossip(stakes) { for resp in &mut pull_responses { - retain_staked(resp, stakes); + retain_staked(resp, stakes, true); } } let (responses, scores): (Vec<_>, Vec<_>) = addrs @@ -2544,9 +2554,9 @@ impl ClusterInfo { } } if self.require_stake_for_gossip(stakes) { - retain_staked(&mut pull_responses, stakes); + retain_staked(&mut pull_responses, stakes, false); for (_, data) in &mut push_messages { - retain_staked(data, stakes); + retain_staked(data, stakes, false); } push_messages.retain(|(_, data)| !data.is_empty()); } From e99fa194f9d229aef225a2e91783473cd4412147 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 19 Aug 2024 22:28:04 +0000 Subject: [PATCH 2/2] add descriptor, refactor retain_staked() --- gossip/src/cluster_info.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index 2f60550b00f24e..033a0b4658e639 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -424,9 +424,6 @@ fn retain_staked( stakes: &HashMap, drop_unstaked_node_instance: bool, ) { - let has_min_stake_for_gossip = - |pubkey: &Pubkey| stakes.get(pubkey).copied().unwrap_or_default() >= MIN_STAKE_FOR_GOSSIP; - values.retain(|value| { match value.data { CrdsData::ContactInfo(_) => true, @@ -441,17 +438,15 @@ fn retain_staked( // the various dashboards. CrdsData::Version(_) => true, CrdsData::AccountsHashes(_) => true, + CrdsData::NodeInstance(_) if !drop_unstaked_node_instance => true, CrdsData::LowestSlot(_, _) | CrdsData::LegacyVersion(_) | CrdsData::DuplicateShred(_, _) | CrdsData::RestartHeaviestFork(_) - | CrdsData::RestartLastVotedForkSlots(_) => has_min_stake_for_gossip(&value.pubkey()), - CrdsData::NodeInstance(_) => { - if drop_unstaked_node_instance { - has_min_stake_for_gossip(&value.pubkey()) - } else { - true - } + | CrdsData::RestartLastVotedForkSlots(_) + | CrdsData::NodeInstance(_) => { + let stake = stakes.get(&value.pubkey()).copied(); + stake.unwrap_or_default() >= MIN_STAKE_FOR_GOSSIP } } }) @@ -1656,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, false); + retain_staked(data, stakes, /* drop_unstaked_node_instance */ false); !data.is_empty() }) } @@ -2148,7 +2143,7 @@ impl ClusterInfo { }; if self.require_stake_for_gossip(stakes) { for resp in &mut pull_responses { - retain_staked(resp, stakes, true); + retain_staked(resp, stakes, /* drop_unstaked_node_instance */ true); } } let (responses, scores): (Vec<_>, Vec<_>) = addrs @@ -2554,9 +2549,13 @@ impl ClusterInfo { } } if self.require_stake_for_gossip(stakes) { - retain_staked(&mut pull_responses, stakes, false); + retain_staked( + &mut pull_responses, + stakes, + /* drop_unstaked_node_instance */ false, + ); for (_, data) in &mut push_messages { - retain_staked(data, stakes, false); + retain_staked(data, stakes, /* drop_unstaked_node_instance */ false); } push_messages.retain(|(_, data)| !data.is_empty()); }