Skip to content

Commit 514659a

Browse files
committed
consensus/clique: minor cleanups
1 parent db6e695 commit 514659a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

consensus/clique/clique.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,23 +504,25 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
504504
header.Nonce = types.BlockNonce{}
505505

506506
number := header.Number.Uint64()
507-
// Assemble the voting snapshot
507+
508+
// Assemble the voting snapshot to check which votes make sense
508509
snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
509510
if err != nil {
510511
return err
511512
}
512513
if number%c.config.Epoch != 0 {
513-
// Get valid votes
514514
c.lock.RLock()
515-
var addresses []common.Address
515+
516+
// Gather all the proposals that make sense voting on
517+
addresses := make([]common.Address, 0, len(c.proposals))
516518
for address, authorize := range c.proposals {
517519
if snap.validVote(address, authorize) {
518520
addresses = append(addresses, address)
519521
}
520522
}
523+
// If there's pending proposals, cast a vote on them
521524
if len(addresses) > 0 {
522-
index := rand.Intn(len(addresses))
523-
header.Coinbase = addresses[index]
525+
header.Coinbase = addresses[rand.Intn(len(addresses))]
524526
if c.proposals[header.Coinbase] {
525527
copy(header.Nonce[:], nonceAuthVote)
526528
} else {
@@ -529,7 +531,6 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
529531
}
530532
c.lock.RUnlock()
531533
}
532-
533534
// Set the correct difficulty
534535
header.Difficulty = diffNoTurn
535536
if snap.inturn(header.Number.Uint64(), c.signer) {

0 commit comments

Comments
 (0)