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