@@ -287,40 +287,44 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
287287 if header .UncleHash != uncleHash {
288288 return errInvalidUncleHash
289289 }
290+ var parent * types.Header
290291 // Ensure that the block's difficulty is meaningful (may not be correct at this point)
291292 if number > 0 {
293+ if len (parents ) > 0 {
294+ parent = parents [len (parents )- 1 ]
295+ } else {
296+ parent = chain .GetHeader (header .ParentHash , number - 1 )
297+ }
298+ if parent == nil || parent .Number .Uint64 () != number - 1 || parent .Hash () != header .ParentHash {
299+ return consensus .ErrUnknownAncestor
300+ }
292301 if header .Difficulty == nil || (header .Difficulty .Cmp (diffInTurn ) != 0 && header .Difficulty .Cmp (diffNoTurn ) != 0 ) {
293302 return errInvalidDifficulty
294303 }
304+ // If we are past the genesis block, validate the basefee is valid according to the parent
305+ if err := misc .VerifyEIP1559BaseFee (chain .Config (), header , parent ); err != nil {
306+ return err
307+ }
295308 }
296309 // If all checks passed, validate any special fields for hard forks
297310 if err := misc .VerifyForkHashes (chain .Config (), header , false ); err != nil {
298311 return err
299312 }
300313 // All basic checks passed, verify cascading fields
301- return c .verifyCascadingFields (chain , header , parents )
314+ return c .verifyCascadingFields (chain , header , parents , parent )
302315}
303316
304317// verifyCascadingFields verifies all the header fields that are not standalone,
305318// rather depend on a batch of previous headers. The caller may optionally pass
306319// in a batch of parents (ascending order) to avoid looking those up from the
307320// database. This is useful for concurrently verifying a batch of new headers.
308- func (c * Clique ) verifyCascadingFields (chain consensus.ChainReader , header * types.Header , parents []* types.Header ) error {
321+ func (c * Clique ) verifyCascadingFields (chain consensus.ChainReader , header * types.Header , parents []* types.Header , parent * types. Header ) error {
309322 // The genesis block is the always valid dead-end
310323 number := header .Number .Uint64 ()
311324 if number == 0 {
312325 return nil
313326 }
314327 // Ensure that the block's timestamp isn't too close to its parent
315- var parent * types.Header
316- if len (parents ) > 0 {
317- parent = parents [len (parents )- 1 ]
318- } else {
319- parent = chain .GetHeader (header .ParentHash , number - 1 )
320- }
321- if parent == nil || parent .Number .Uint64 () != number - 1 || parent .Hash () != header .ParentHash {
322- return consensus .ErrUnknownAncestor
323- }
324328 if parent .Time + c .config .Period > header .Time {
325329 return errInvalidTimestamp
326330 }
0 commit comments