Skip to content

Commit

Permalink
improve: drop dumplicate votes when assembling attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC committed Jul 31, 2023
1 parent a4f1728 commit 837ec8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,9 @@ func (p *Parlia) assembleVoteAttestation(chain consensus.ChainHeaderReader, head
voteAddrSet := make(map[types.BLSPublicKey]struct{}, len(votes))
signatures := make([][]byte, 0, len(votes))
for _, vote := range votes {
// In some corner case, one vote may be included twice.
if _, ok := voteAddrSet[vote.VoteAddress]; ok {
return fmt.Errorf("assemble VoteAttestation failed, double sign by %s", common.Bytes2Hex(vote.VoteAddress[:]))
continue
}
voteAddrSet[vote.VoteAddress] = struct{}{}
signatures = append(signatures, vote.Signature[:])
Expand All @@ -885,8 +886,7 @@ func (p *Parlia) assembleVoteAttestation(chain consensus.ChainHeaderReader, head
attestation.VoteAddressSet |= 1 << (valInfo.Index - 1) //Index is offset by 1
}
}
// The valid voted validators should be no less than 2/3 validators,
// In some corner case, one vote may be included twice, so here need check again.
// The valid voted validators should be no less than 2/3 validators.
validatorsBitSet := bitset.From([]uint64{uint64(attestation.VoteAddressSet)})
if validatorsBitSet.Count() < uint(cmath.CeilDiv(len(snap.Validators)*2, 3)) {
return fmt.Errorf("invalid attestation, not enough validators voted")
Expand Down

0 comments on commit 837ec8e

Please sign in to comment.