Skip to content

Commit

Permalink
modify for multiple double-voting in vetomint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongseup committed Aug 27, 2023
1 parent ff72378 commit 31b7f14
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions vetomint/src/misbehavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) fn check_double_prevote(
state: &ConsensusState,
target_round: Round,
) -> Vec<ConsensusResponse> {
let mut response = Vec::new();
let mut validators_map = HashMap::new();
let prevotes_in_target_round: Vec<_> = state
.prevotes
Expand All @@ -21,29 +22,30 @@ pub(crate) fn check_double_prevote(
.or_insert((0, vote.proposal));
*count += 1;

if *count == 2 {
if *count >= 2 {
let byzantine_validator = vote.signer;
let double_proposal = vote.proposal;

return vec![ConsensusResponse::ViolationReport {
response.extend(vec![ConsensusResponse::ViolationReport {
violator: byzantine_validator,
misbehavior: Misbehavior::DoublePrevote {
byzantine_node: byzantine_validator,
round: target_round,
proposals: (*origin_proposal, double_proposal),
},
}];
}]);
}
}

Vec::new()
response
}

/// Check whether there are double precommits in target round
pub(crate) fn check_double_precommit(
state: &ConsensusState,
target_round: Round,
) -> Vec<ConsensusResponse> {
let mut response = Vec::new();
let mut validators_map = HashMap::new();
let precommits_in_target_round: Vec<_> = state
.precommits
Expand All @@ -57,20 +59,19 @@ pub(crate) fn check_double_precommit(
.or_insert((0, vote.proposal));
*count += 1;

if *count == 2 {
if *count >= 2 {
let byzantine_validator = vote.signer;
let double_proposal = vote.proposal;

return vec![ConsensusResponse::ViolationReport {
response.extend(vec![ConsensusResponse::ViolationReport {
violator: byzantine_validator,
misbehavior: Misbehavior::DoublePrecommit {
byzantine_node: byzantine_validator,
round: target_round,
proposals: (*origin_proposal, double_proposal),
},
}];
}]);
}
}

Vec::new()
response
}

0 comments on commit 31b7f14

Please sign in to comment.