@@ -504,23 +504,25 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
504
504
header .Nonce = types.BlockNonce {}
505
505
506
506
number := header .Number .Uint64 ()
507
- // Assemble the voting snapshot
507
+
508
+ // Assemble the voting snapshot to check which votes make sense
508
509
snap , err := c .snapshot (chain , number - 1 , header .ParentHash , nil )
509
510
if err != nil {
510
511
return err
511
512
}
512
513
if number % c .config .Epoch != 0 {
513
- // Get valid votes
514
514
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 ))
516
518
for address , authorize := range c .proposals {
517
519
if snap .validVote (address , authorize ) {
518
520
addresses = append (addresses , address )
519
521
}
520
522
}
523
+ // If there's pending proposals, cast a vote on them
521
524
if len (addresses ) > 0 {
522
- index := rand .Intn (len (addresses ))
523
- header .Coinbase = addresses [index ]
525
+ header .Coinbase = addresses [rand .Intn (len (addresses ))]
524
526
if c .proposals [header .Coinbase ] {
525
527
copy (header .Nonce [:], nonceAuthVote )
526
528
} else {
@@ -529,7 +531,6 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
529
531
}
530
532
c .lock .RUnlock ()
531
533
}
532
-
533
534
// Set the correct difficulty
534
535
header .Difficulty = diffNoTurn
535
536
if snap .inturn (header .Number .Uint64 (), c .signer ) {
0 commit comments