Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter out unstaked NodeInstance from sent PullRequests #2637

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
fn retain_staked(
values: &mut Vec<CrdsValue>,
stakes: &HashMap<Pubkey, u64>,
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,
Expand All @@ -438,10 +445,13 @@ fn retain_staked(values: &mut Vec<CrdsValue>, stakes: &HashMap<Pubkey, u64>) {
| 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave this part as is, but add an extra branch before line 437:

CrdsData::NodeInstance(_) if !drop_unstaked_node_instance => true,

| 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
}
}
}
})
Expand Down Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for someone reading this code later, it is not clear what each of these false/true means.
I think it would be good to add some inline comments as in:

retain_staked(data, stakes, /*drop_unstaked_node_instance:*/ false);

!data.is_empty()
})
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand Down