Skip to content

Commit ef0f911

Browse files
committed
apollo_network: add BadPeerReport and PenaltyCard
1 parent 09f23a2 commit ef0f911

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

crates/apollo_consensus/src/manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,17 @@ impl<ContextT: ConsensusContext> ConsensusCache<ContextT> {
276276
let votes = self.future_votes.entry(vote.height).or_default();
277277
// Find a vote in the list with the same type, round, and voter. If found, do not add it to
278278
// list.
279-
let duplicate_vote = votes.iter().find(|v| {
279+
let existing_vote = votes.iter().find(|v| {
280280
v.vote_type == vote.vote_type && v.round == vote.round && v.voter == vote.voter
281281
});
282-
if let Some(duplicate_vote) = duplicate_vote {
282+
if let Some(existing_vote) = existing_vote {
283283
// If the two votes are identical, we just ignore this.
284-
if duplicate_vote == &vote {
284+
if existing_vote == &vote {
285285
Ok(())
286286
} else {
287287
// Otherwise, we report equivocation.
288288
Err(Box::new(EquivocationVoteReport {
289-
cached_vote: duplicate_vote.clone(),
289+
cached_vote: existing_vote.clone(),
290290
new_vote: vote,
291291
}))
292292
}

crates/apollo_network_types/src/network_types.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,22 @@ impl OpaquePeerId {
2323
self.0
2424
}
2525
}
26+
27+
// TODO(guyn): remove allow dead code once we use the duplicate vote report.
28+
#[allow(dead_code)]
29+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
30+
pub struct BadPeerReport {
31+
pub peer_id: OpaquePeerId,
32+
pub reason: String,
33+
pub penalty_card: PenaltyCard,
34+
}
35+
36+
// TODO(guyn): need to decide how much misconduct score to add when getting each yellow card.
37+
/// Represents the severity of the bad peer behavior.
38+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
39+
pub enum PenaltyCard {
40+
/// Overtly malicious behavior.
41+
Red,
42+
/// Possibly sent malicious data on accident, will be considered malicious on repeat offenses.
43+
Yellow,
44+
}

0 commit comments

Comments
 (0)