From fb9c707ad3cc0a605aa63174970a6815a27c65ac Mon Sep 17 00:00:00 2001 From: Sebastian Stammler Date: Thu, 11 Jan 2024 20:19:22 +0100 Subject: [PATCH] consensus/beacon: Add parent hash check to OpLegacy.VerifyHeader VerifyHeaders will be dealt with in a follow-up. --- consensus/beacon/consensus.go | 1 + consensus/beacon/oplegacy.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 619f3c6b69..c716ba4dcc 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -58,6 +58,7 @@ var ( // is only used for necessary consensus checks. The legacy consensus engine can be any // engine implements the consensus interface (except the beacon itself). type Beacon struct { + // For migrated OP chains (OP mainnet, OP Goerli), ethone is a dummy legacy pre-Bedrock consensus ethone consensus.Engine // Original consensus engine used in eth1, e.g. ethash or clique } diff --git a/consensus/beacon/oplegacy.go b/consensus/beacon/oplegacy.go index 41fa3373d7..3c30cd24dc 100644 --- a/consensus/beacon/oplegacy.go +++ b/consensus/beacon/oplegacy.go @@ -2,23 +2,28 @@ package beacon import ( "fmt" + "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" - "math/big" ) -type OpLegacy struct { -} +type OpLegacy struct{} func (o *OpLegacy) Author(header *types.Header) (common.Address, error) { return header.Coinbase, nil } func (o *OpLegacy) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error { - return nil // legacy chain is verified by block-hash reverse sync + // redundant check to guarantee DB consistency + parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) + if parent == nil { + return consensus.ErrUnknownAncestor + } + return nil // legacy chain is verified by block-hash reverse sync otherwise } func (o *OpLegacy) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) {