@@ -504,14 +504,23 @@ 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
508
+ snap , err := c .snapshot (chain , number - 1 , header .ParentHash , nil )
509
+ if err != nil {
510
+ return err
511
+ }
507
512
if number % c .config .Epoch != 0 {
513
+ // Get valid votes
508
514
c .lock .RLock ()
509
- if len ( c . proposals ) > 0 {
510
- addresses := make ([]common. Address , 0 , len ( c .proposals ))
511
- for address := range c . proposals {
515
+ var addresses []common. Address
516
+ for address , authorize := range c .proposals {
517
+ if snap . validVote ( address , authorize ) {
512
518
addresses = append (addresses , address )
513
519
}
514
- header .Coinbase = addresses [rand .Intn (len (addresses ))]
520
+ }
521
+ if len (addresses ) > 0 {
522
+ index := rand .Intn (len (addresses ))
523
+ header .Coinbase = addresses [index ]
515
524
if c .proposals [header .Coinbase ] {
516
525
copy (header .Nonce [:], nonceAuthVote )
517
526
} else {
@@ -520,11 +529,8 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
520
529
}
521
530
c .lock .RUnlock ()
522
531
}
523
- // Assemble the voting snapshot and set the correct difficulty
524
- snap , err := c .snapshot (chain , number - 1 , header .ParentHash , nil )
525
- if err != nil {
526
- return err
527
- }
532
+
533
+ // Set the correct difficulty
528
534
header .Difficulty = diffNoTurn
529
535
if snap .inturn (header .Number .Uint64 (), c .signer ) {
530
536
header .Difficulty = diffInTurn
0 commit comments