Skip to content

Commit 98d410a

Browse files
authored
fix(code/core-consensus): Only persist votes in the WAL if they have not yet been seen (#902)
1 parent 088151f commit 98d410a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

code/crates/core-consensus/src/handle/vote.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ where
7777

7878
debug_assert_eq!(consensus_height, vote_height);
7979

80-
// Only append to WAL and store precommits if we're in the validator set
81-
if state.is_validator() {
80+
// Only append to WAL and store precommits if we're in the validator set,
81+
// and we have not yet seen this vote.
82+
if state.is_validator() && !state.driver.votes().has_vote(&signed_vote) {
8283
// Append the vote to the Write-ahead Log
8384
perform!(
8485
co,

code/crates/core-votekeeper/src/keeper.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
}
9797
}
9898

99-
// Add the vote to the round
99+
// Tally this vote
100100
self.votes.add_vote(&vote, weight);
101101

102102
// Update the weight of the validator
@@ -205,6 +205,13 @@ where
205205
&self.evidence
206206
}
207207

208+
/// Check if we have already seen a vote.
209+
pub fn has_vote(&self, vote: &SignedVote<Ctx>) -> bool {
210+
self.per_round
211+
.get(&vote.round())
212+
.is_some_and(|per_round| per_round.received_votes().contains(vote))
213+
}
214+
208215
/// Apply a vote with a given weight, potentially triggering an output.
209216
pub fn apply_vote(
210217
&mut self,

0 commit comments

Comments
 (0)