Skip to content

Commit

Permalink
prevent double counting from same endorser (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi committed Nov 7, 2018
1 parent a4c1d6d commit b2bda59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions endorsement/endorsementset.go
Expand Up @@ -111,6 +111,7 @@ func (s *Set) NumOfValidEndorsements(topics map[ConsensusVoteTopic]bool, endorse
if _, ok := endorserSet[endorsement.endorser]; !ok {
continue
}
delete(endorserSet, endorsement.endorser)
cnt++
}

Expand Down
24 changes: 24 additions & 0 deletions endorsement/endorsementset_test.go
Expand Up @@ -44,4 +44,28 @@ func TestAddEndorsement(t *testing.T) {
en = NewEndorsement(cv, testaddress.Addrinfo["producer"])
require.Equal(nil, set.AddEndorsement(en))
require.Equal(2, len(set.endorsements))
// Add an endorsement of an existing endorser
cv = NewConsensusVote(hash1, 1, 2, LOCK)
en = NewEndorsement(cv, testaddress.Addrinfo["alfa"])
require.Equal(nil, set.AddEndorsement(en))
require.Equal(3, len(set.endorsements))
require.Equal(1, set.NumOfValidEndorsements(map[ConsensusVoteTopic]bool{
LOCK: true,
}, []string{
testaddress.Addrinfo["producer"].RawAddress,
testaddress.Addrinfo["alfa"].RawAddress,
}))
require.Equal(2, set.NumOfValidEndorsements(map[ConsensusVoteTopic]bool{
PROPOSAL: true,
}, []string{
testaddress.Addrinfo["producer"].RawAddress,
testaddress.Addrinfo["alfa"].RawAddress,
}))
require.Equal(2, set.NumOfValidEndorsements(map[ConsensusVoteTopic]bool{
LOCK: true,
PROPOSAL: true,
}, []string{
testaddress.Addrinfo["producer"].RawAddress,
testaddress.Addrinfo["alfa"].RawAddress,
}))
}

0 comments on commit b2bda59

Please sign in to comment.