Skip to content

Commit

Permalink
beacon: Fix OP Legacy block hash checks
Browse files Browse the repository at this point in the history
  • Loading branch information
trianglesphere committed Jan 27, 2024
1 parent 5c6f10d commit d4e12b3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions consensus/beacon/oplegacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,37 @@ func (o *OpLegacy) Author(header *types.Header) (common.Address, error) {
}

func (o *OpLegacy) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error {
// redundant check to guarantee DB consistency
parent := chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
// Short circuit if the header is known, or its parent not
number := header.Number.Uint64()
if chain.GetHeader(header.Hash(), number) != nil {
return nil
}
parent := chain.GetHeader(header.ParentHash, number-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) {
quit := make(chan struct{}, 1)
result := make(chan error, len(headers))
for _, h := range headers {
result <- o.VerifyHeader(chain, h)
abort := make(chan struct{})
results := make(chan error, len(headers))
for i, header := range headers {
var parent *types.Header
if i == 0 {
parent = chain.GetHeader(headers[0].ParentHash, headers[0].Number.Uint64()-1)
} else if headers[i-1].Hash() == headers[i].ParentHash {
parent = headers[i-1]
}
var err error
if parent == nil {
err = consensus.ErrUnknownAncestor
} else {
err = o.VerifyHeader(chain, header)
}
results <- err
}
return quit, result
return abort, results
}

func (o *OpLegacy) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
Expand Down

0 comments on commit d4e12b3

Please sign in to comment.