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

Ignore Gossip messages from my own pubkey. #1678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions wen-restart/src/heaviest_fork_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ impl HeaviestForkAggregate {
);
return None;
}
if from == &self.my_pubkey {
return None;
}
if received_heaviest_fork.shred_version != self.my_shred_version {
warn!(
"Gossip should not accept RestartLastVotedFork with different shred version {} from {:?}",
Expand Down Expand Up @@ -445,6 +448,23 @@ mod tests {
.total_active_stake_seen_supermajority(),
1500
);

// test that message from my pubkey is ignored.
assert_eq!(
test_state
.heaviest_fork_aggregate
.aggregate(RestartHeaviestFork {
from: test_state.validator_voting_keypairs[MY_INDEX]
.node_keypair
.pubkey(),
wallclock: timestamp(),
last_slot: test_state.heaviest_slot,
last_slot_hash: test_state.heaviest_hash,
observed_stake: 100,
shred_version: SHRED_VERSION,
},),
None,
);
}

#[test]
Expand Down Expand Up @@ -535,6 +555,27 @@ mod tests {
);
// percentage doesn't change since the previous aggregate is ignored.
assert_eq!(test_state.heaviest_fork_aggregate.total_active_stake(), 200);

// Record from my pubkey should be ignored.
assert_eq!(
test_state
.heaviest_fork_aggregate
.aggregate_from_record(
&test_state.validator_voting_keypairs[MY_INDEX]
.node_keypair
.pubkey()
.to_string(),
&HeaviestForkRecord {
wallclock: timestamp(),
slot: test_state.heaviest_slot,
bankhash: test_state.heaviest_hash.to_string(),
shred_version: SHRED_VERSION as u32,
total_active_stake: 100,
}
)
.unwrap(),
None,
);
}

#[test]
Expand Down
45 changes: 45 additions & 0 deletions wen-restart/src/last_voted_fork_slots_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) struct LastVotedForkSlotsAggregate {
slots_stake_map: HashMap<Slot, u64>,
active_peers: HashSet<Pubkey>,
slots_to_repair: HashSet<Slot>,
my_pubkey: Pubkey,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -53,6 +54,7 @@ impl LastVotedForkSlotsAggregate {
slots_stake_map,
active_peers,
slots_to_repair: HashSet::new(),
my_pubkey: *my_pubkey,
}
}

Expand All @@ -70,6 +72,9 @@ impl LastVotedForkSlotsAggregate {
record: &LastVotedForkSlotsRecord,
) -> Result<Option<LastVotedForkSlotsRecord>> {
let from = Pubkey::from_str(key_string)?;
if from == self.my_pubkey {
return Ok(None);
}
let last_voted_hash = Hash::from_str(&record.last_vote_bankhash)?;
let converted_record = RestartLastVotedForkSlots::new(
from,
Expand All @@ -88,6 +93,9 @@ impl LastVotedForkSlotsAggregate {
let total_stake = self.epoch_stakes.total_stake();
let threshold_stake = (total_stake as f64 * self.repair_threshold) as u64;
let from = &new_slots.from;
if from == &self.my_pubkey {
return None;
}
let sender_stake = Self::validator_stake(&self.epoch_stakes, from);
if sender_stake == 0 {
warn!(
Expand Down Expand Up @@ -354,6 +362,23 @@ mod tests {
Vec::from_iter(test_state.slots_aggregate.slots_to_repair_iter().cloned());
actual_slots.sort();
assert_eq!(actual_slots, vec![root_slot + 1]);

// test that message from my pubkey is ignored.
assert_eq!(
test_state.slots_aggregate.aggregate(
RestartLastVotedForkSlots::new(
test_state.validator_voting_keypairs[MY_INDEX]
.node_keypair
.pubkey(),
timestamp(),
&[root_slot + 1, root_slot + 4, root_slot + 5],
Hash::default(),
SHRED_VERSION,
)
.unwrap(),
),
None,
);
}

#[test]
Expand Down Expand Up @@ -446,6 +471,26 @@ mod tests {
);
// percentage doesn't change since the previous aggregate is ignored.
assert_eq!(test_state.slots_aggregate.active_percent(), 20.0);

// Record from my pubkey should be ignored.
assert_eq!(
test_state
.slots_aggregate
.aggregate_from_record(
&test_state.validator_voting_keypairs[MY_INDEX]
.node_keypair
.pubkey()
.to_string(),
&LastVotedForkSlotsRecord {
wallclock: timestamp(),
last_voted_fork_slots: vec![root_slot + 10, root_slot + 300],
last_vote_bankhash: Hash::new_unique().to_string(),
shred_version: SHRED_VERSION as u32,
}
)
.unwrap(),
None,
);
}

#[test]
Expand Down