diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-06-23 16:21:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-23 16:21:38 +0800 |
commit | cd88f697150b61193a191196ec27e0b128f05690 (patch) | |
tree | d760f31eb20188872b30724dcaa51913ec162809 /consensus/clique/clique.go | |
parent | 46d0d04f97681b47a3be1dd3523848d387f2c3bf (diff) | |
parent | 514659a023dc5d7bf8bac002d72c38a1ad1e3bbd (diff) | |
download | go-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/clique.go')
-rw-r--r-- | consensus/clique/clique.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index b9a3fe244..d2fb6934b 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -503,13 +503,24 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro header.Nonce = types.BlockNonce{} number := header.Number.Uint64() + + // Assemble the voting snapshot to check which votes make sense + snap, err := c.snapshot(chain, number-1, header.ParentHash, nil) + if err != nil { + return err + } if number%c.config.Epoch != 0 { c.lock.RLock() - if len(c.proposals) > 0 { - addresses := make([]common.Address, 0, len(c.proposals)) - for address := range c.proposals { + + // Gather all the proposals that make sense voting on + addresses := make([]common.Address, 0, len(c.proposals)) + for address, authorize := range c.proposals { + if snap.validVote(address, authorize) { addresses = append(addresses, address) } + } + // If there's pending proposals, cast a vote on them + if len(addresses) > 0 { header.Coinbase = addresses[rand.Intn(len(addresses))] if c.proposals[header.Coinbase] { copy(header.Nonce[:], nonceAuthVote) @@ -519,11 +530,7 @@ 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 |