aboutsummaryrefslogtreecommitdiffstats
path: root/consensus
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-06-23 16:05:20 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-06-23 16:06:38 +0800
commit514659a023dc5d7bf8bac002d72c38a1ad1e3bbd (patch)
tree2f03740ac6ad9a40c89cce0bbb49c46491345a1d /consensus
parentdb6e6950029e97be34b9aa27c5a05ba44495091d (diff)
downloadgo-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar.gz
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar.bz2
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar.lz
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar.xz
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.tar.zst
go-tangerine-514659a023dc5d7bf8bac002d72c38a1ad1e3bbd.zip
consensus/clique: minor cleanups
Diffstat (limited to 'consensus')
-rw-r--r--consensus/clique/clique.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go
index 7af881ab8..b3bb1b290 100644
--- a/consensus/clique/clique.go
+++ b/consensus/clique/clique.go
@@ -504,23 +504,25 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
header.Nonce = types.BlockNonce{}
number := header.Number.Uint64()
- // Assemble the voting snapshot
+
+ // 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 {
- // Get valid votes
c.lock.RLock()
- var addresses []common.Address
+
+ // 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 {
- index := rand.Intn(len(addresses))
- header.Coinbase = addresses[index]
+ header.Coinbase = addresses[rand.Intn(len(addresses))]
if c.proposals[header.Coinbase] {
copy(header.Nonce[:], nonceAuthVote)
} else {
@@ -529,7 +531,6 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
}
c.lock.RUnlock()
}
-
// Set the correct difficulty
header.Difficulty = diffNoTurn
if snap.inturn(header.Number.Uint64(), c.signer) {