Skip to content

Commit

Permalink
fix(consensus): not increase the vote-box power on duplicated votes (#…
Browse files Browse the repository at this point in the history
themantre authored Oct 26, 2023
1 parent 1804fd3 commit 741492c
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions consensus/voteset/vote_box.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@ func newVoteBox() *voteBox {
}

func (vs *voteBox) addVote(vote *vote.Vote, power int64) {
vs.votes[vote.Signer()] = vote
vs.votedPower += power
if vs.votes[vote.Signer()] == nil {
vs.votes[vote.Signer()] = vote
vs.votedPower += power
}
}
28 changes: 28 additions & 0 deletions consensus/voteset/vote_box_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package voteset

import (
"testing"

"github.com/pactus-project/pactus/types/vote"
"github.com/pactus-project/pactus/util/testsuite"
"github.com/stretchr/testify/assert"
)

func TestDuplicateVote(t *testing.T) {
ts := testsuite.NewTestSuite(t)

hash := ts.RandHash()
height := ts.RandHeight()
round := ts.RandRound()
signer := ts.RandValAddress()
power := ts.RandInt64(1000)

v := vote.NewPrepareVote(hash, height, round, signer)

vb := newVoteBox()

vb.addVote(v, power)
vb.addVote(v, power)

assert.Equal(t, vb.votedPower, power)
}

0 comments on commit 741492c

Please sign in to comment.