From 302e85ba1e2f92db8e7caae40741773fc4c319e4 Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Sun, 25 Apr 2021 14:36:38 +0100 Subject: [PATCH] Fix for nil parent (#1802) Co-authored-by: Alexey Sharp --- consensus/clique/verifier.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/consensus/clique/verifier.go b/consensus/clique/verifier.go index 14879d425..c1a7dda7e 100644 --- a/consensus/clique/verifier.go +++ b/consensus/clique/verifier.go @@ -2,7 +2,6 @@ package clique import ( "bytes" - "fmt" "time" "github.com/ledgerwatch/turbo-geth/common" @@ -18,22 +17,6 @@ import ( // looking those up from the database. This is useful for concurrently verifying // a batch of new headers. func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parents []*types.Header) error { - // Verify the header's EIP-1559 attributes. - if chain.Config().IsAleut(header.Number.Uint64()) { - var parent *types.Header - if len(parents) > 0 { - parent = parents[len(parents)-1] - } else { - parent = chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) - if parent == nil { - return fmt.Errorf("could not find parent with hash %x and number %x in db", header.ParentHash, header.Number.Uint64()-1) - } - } - - if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64())); err != nil { - return err - } - } if header.Number == nil { return errUnknownBlock } @@ -118,7 +101,15 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header parent = parents[len(parents)-1] } else { parent = chain.GetHeader(header.ParentHash, number-1) - parents = []*types.Header{parent} + } + if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash { + return consensus.ErrUnknownAncestor + } + // Verify the header's EIP-1559 attributes. + if chain.Config().IsAleut(header.Number.Uint64()) { + if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64())); err != nil { + return err + } } if parent.Time+c.config.Period > header.Time {