Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beacon: Fix OP Legacy block hash checks #228

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions consensus/beacon/oplegacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,38 @@ 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
// legacy chain is verified by block-hash reverse sync otherwise
return nil
}

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 := range headers {
// legacy chain is verified by block-hash reverse sync
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
}
results <- err
}
return quit, result
return abort, results
}

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