aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/clique/snapshot.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-06-23 16:21:38 +0800
committerGitHub <noreply@github.com>2017-06-23 16:21:38 +0800
commitcd88f697150b61193a191196ec27e0b128f05690 (patch)
treed760f31eb20188872b30724dcaa51913ec162809 /consensus/clique/snapshot.go
parent46d0d04f97681b47a3be1dd3523848d387f2c3bf (diff)
parent514659a023dc5d7bf8bac002d72c38a1ad1e3bbd (diff)
downloadgo-tangerine-cd88f697150b61193a191196ec27e0b128f05690.tar.gz
go-tangerine-cd88f697150b61193a191196ec27e0b128f05690.tar.zst
go-tangerine-cd88f697150b61193a191196ec27e0b128f05690.zip
Merge pull request #14596 from markya0616/valid_clique_vote
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 8eaf3b62e..32a1191db 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