aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/clique/clique.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/clique.go
parent6171d01b1195abd7ac75044dcd507d4758d83cde (diff)
downloadgo-tangerine-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.gz
go-tangerine-db6e6950029e97be34b9aa27c5a05ba44495091d.tar.zst
go-tangerine-db6e6950029e97be34b9aa27c5a05ba44495091d.zip
consensus/clique: choose valid votes
Diffstat (limited to 'consensus/clique/clique.go')
-rw-r--r--consensus/clique/clique.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go
index 87a983377..7af881ab8 100644
--- a/consensus/clique/clique.go
+++ b/consensus/clique/clique.go
@@ -504,14 +504,23 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
header.Nonce = types.BlockNonce{}
number := header.Number.Uint64()
+ // Assemble the voting snapshot
+ snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
+ if err != nil {
+ return err
+ }
if number%c.config.Epoch != 0 {
+ // Get valid votes
c.lock.RLock()
- if len(c.proposals) > 0 {
- addresses := make([]common.Address, 0, len(c.proposals))
- for address := range c.proposals {
+ var addresses []common.Address
+ for address, authorize := range c.proposals {
+ if snap.validVote(address, authorize) {
addresses = append(addresses, address)
}
- header.Coinbase = addresses[rand.Intn(len(addresses))]
+ }
+ if len(addresses) > 0 {
+ index := rand.Intn(len(addresses))
+ header.Coinbase = addresses[index]
if c.proposals[header.Coinbase] {
copy(header.Nonce[:], nonceAuthVote)
} else {
@@ -520,11 +529,8 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
}
c.lock.RUnlock()
}
- // Assemble the voting snapshot and set the correct difficulty
- snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
- if err != nil {
- return err
- }
+
+ // Set the correct difficulty
header.Difficulty = diffNoTurn
if snap.inturn(header.Number.Uint64(), c.signer) {
header.Difficulty = diffInTurn