From db6e6950029e97be34b9aa27c5a05ba44495091d Mon Sep 17 00:00:00 2001 From: "mark.lin" Date: Wed, 14 Jun 2017 16:49:33 +0800 Subject: consensus/clique: choose valid votes --- consensus/clique/snapshot.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'consensus/clique/snapshot.go') diff --git a/consensus/clique/snapshot.go b/consensus/clique/snapshot.go index fb86bc5e6..a17395f3c 100644 --- a/consensus/clique/snapshot.go +++ b/consensus/clique/snapshot.go @@ -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 -- cgit v1.2.3