consensus/clique: choose valid votes

This commit is contained in:
mark.lin
2017-06-14 16:49:33 +08:00
parent 6171d01b11
commit db6e695002
2 changed files with 23 additions and 11 deletions

View File

@ -126,11 +126,17 @@ func (s *Snapshot) copy() *Snapshot {
return cpy
}
// validVote returns whether it makes sense to cast the specified vote in the
// given snapshot context (e.g. don't try to add an already authorized signer).
func (s *Snapshot) validVote(address common.Address, authorize bool) bool {
_, signer := s.Signers[address]
return (signer && !authorize) || (!signer && authorize)
}
// cast adds a new vote into the tally.
func (s *Snapshot) cast(address common.Address, authorize bool) bool {
// Ensure the vote is meaningful
_, signer := s.Signers[address]
if (signer && authorize) || (!signer && !authorize) {
if !s.validVote(address, authorize) {
return false
}
// Cast the vote into an existing or new tally