@@ -93,27 +93,33 @@ var (
9393
9494 // errMissingSignature is returned if a block's extra-data section doesn't seem
9595 // to contain a 65 byte secp256k1 signature.
96- errMissingSignature = errors .New ("extra-data 65 byte suffix signature missing" )
96+ errMissingSignature = errors .New ("extra-data 65 byte signature suffix missing" )
9797
9898 // errExtraSigners is returned if non-checkpoint block contain signer data in
9999 // their extra-data fields.
100100 errExtraSigners = errors .New ("non-checkpoint block contains extra signer list" )
101101
102102 // errInvalidCheckpointSigners is returned if a checkpoint block contains an
103- // invalid list of signers (i.e. non divisible by 20 bytes, or not the correct
104- // ones).
103+ // invalid list of signers (i.e. non divisible by 20 bytes).
105104 errInvalidCheckpointSigners = errors .New ("invalid signer list on checkpoint block" )
106105
106+ // errMismatchingCheckpointSigners is returned if a checkpoint block contains a
107+ // list of signers different than the one the local node calculated.
108+ errMismatchingCheckpointSigners = errors .New ("mismatching signer list on checkpoint block" )
109+
107110 // errInvalidMixDigest is returned if a block's mix digest is non-zero.
108111 errInvalidMixDigest = errors .New ("non-zero mix digest" )
109112
110113 // errInvalidUncleHash is returned if a block contains an non-empty uncle list.
111114 errInvalidUncleHash = errors .New ("non empty uncle hash" )
112115
113- // errInvalidDifficulty is returned if the difficulty of a block is not either
114- // of 1 or 2, or if the value does not match the turn of the signer.
116+ // errInvalidDifficulty is returned if the difficulty of a block neither 1 or 2.
115117 errInvalidDifficulty = errors .New ("invalid difficulty" )
116118
119+ // errWrongDifficulty is returned if the difficulty of a block doesn't match the
120+ // turn of the signer.
121+ errWrongDifficulty = errors .New ("wrong difficulty" )
122+
117123 // ErrInvalidTimestamp is returned if the timestamp of a block is lower than
118124 // the previous block's timestamp + the minimum block period.
119125 ErrInvalidTimestamp = errors .New ("invalid timestamp" )
@@ -122,8 +128,12 @@ var (
122128 // be modified via out-of-range or non-contiguous headers.
123129 errInvalidVotingChain = errors .New ("invalid voting chain" )
124130
125- // errUnauthorized is returned if a header is signed by a non-authorized entity.
126- errUnauthorized = errors .New ("unauthorized" )
131+ // errUnauthorizedSigner is returned if a header is signed by a non-authorized entity.
132+ errUnauthorizedSigner = errors .New ("unauthorized signer" )
133+
134+ // errRecentlySigned is returned if a header is signed by an authorized entity
135+ // that already signed a header recently, thus is temporarily not allowed to.
136+ errRecentlySigned = errors .New ("recently signed" )
127137
128138 // errWaitTransactions is returned if an empty block is attempted to be sealed
129139 // on an instant chain (0 second period). It's important to refuse these as the
@@ -205,6 +215,9 @@ type Clique struct {
205215 signer common.Address // Ethereum address of the signing key
206216 signFn SignerFn // Signer function to authorize hashes with
207217 lock sync.RWMutex // Protects the signer fields
218+
219+ // The fields below are for testing only
220+ fakeDiff bool // Skip difficulty verifications
208221}
209222
210223// New creates a Clique proof-of-authority consensus engine with the initial
@@ -359,7 +372,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
359372 }
360373 extraSuffix := len (header .Extra ) - extraSeal
361374 if ! bytes .Equal (header .Extra [extraVanity :extraSuffix ], signers ) {
362- return errInvalidCheckpointSigners
375+ return errMismatchingCheckpointSigners
363376 }
364377 }
365378 // All basic checks passed, verify the seal and return
@@ -481,23 +494,25 @@ func (c *Clique) verifySeal(chain consensus.ChainReader, header *types.Header, p
481494 return err
482495 }
483496 if _ , ok := snap .Signers [signer ]; ! ok {
484- return errUnauthorized
497+ return errUnauthorizedSigner
485498 }
486499 for seen , recent := range snap .Recents {
487500 if recent == signer {
488501 // Signer is among recents, only fail if the current block doesn't shift it out
489502 if limit := uint64 (len (snap .Signers )/ 2 + 1 ); seen > number - limit {
490- return errUnauthorized
503+ return errRecentlySigned
491504 }
492505 }
493506 }
494507 // Ensure that the difficulty corresponds to the turn-ness of the signer
495- inturn := snap .inturn (header .Number .Uint64 (), signer )
496- if inturn && header .Difficulty .Cmp (diffInTurn ) != 0 {
497- return errInvalidDifficulty
498- }
499- if ! inturn && header .Difficulty .Cmp (diffNoTurn ) != 0 {
500- return errInvalidDifficulty
508+ if ! c .fakeDiff {
509+ inturn := snap .inturn (header .Number .Uint64 (), signer )
510+ if inturn && header .Difficulty .Cmp (diffInTurn ) != 0 {
511+ return errWrongDifficulty
512+ }
513+ if ! inturn && header .Difficulty .Cmp (diffNoTurn ) != 0 {
514+ return errWrongDifficulty
515+ }
501516 }
502517 return nil
503518}
@@ -613,7 +628,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
613628 return err
614629 }
615630 if _ , authorized := snap .Signers [signer ]; ! authorized {
616- return errUnauthorized
631+ return errUnauthorizedSigner
617632 }
618633 // If we're amongst the recent signers, wait for the next block
619634 for seen , recent := range snap .Recents {
0 commit comments