aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/clique/snapshot.go
diff options
context:
space:
mode:
authormark.lin <mark@maicoin.com>2017-06-14 16:49:33 +0800
committermark.lin <mark@maicoin.com>2017-06-14 16:49:33 +0800
commitdb6e6950029e97be34b9aa27c5a05ba44495091d (patch)
tree758146e2e300a3078c25d5c9ca705bbce6bb2224 /consensus/clique/snapshot.go
parent6171d01b1195abd7ac75044dcd507d4758d83cde (diff)
downloaddexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.gz
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.bz2
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.lz
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.xz
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.zst
dexon-db6e6950029e97be34b9aa27c5a05ba44495091d.zip
consensus/clique: choose valid votes
Diffstat (limited to 'consensus/clique/snapshot.go')
-rw-r--r--consensus/clique/snapshot.go10
1 files changed, 8 insertions, 2 deletions
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