Skip to content

Engine API PR 498 (clarify payloadAttributes checks) #8982

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

Merged
merged 2 commits into from
Dec 14, 2023
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
32 changes: 7 additions & 25 deletions turbo/engineapi/engine_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,25 +452,20 @@ func (s *EngineServer) forkchoiceUpdated(ctx context.Context, forkchoiceState *e
}

if payloadAttributes != nil {
if version < clparams.DenebVersion && payloadAttributes.ParentBeaconBlockRoot != nil {
return nil, &engine_helpers.InvalidPayloadAttributesErr // Unexpected Beacon Root
}
if version >= clparams.DenebVersion && payloadAttributes.ParentBeaconBlockRoot == nil {
return nil, &engine_helpers.InvalidPayloadAttributesErr // Beacon Root missing
}

timestamp := uint64(payloadAttributes.Timestamp)
if !s.config.IsCancun(timestamp) && version >= clparams.DenebVersion { // V3 before cancun
if payloadAttributes.ParentBeaconBlockRoot == nil {
return nil, &rpc.InvalidParamsError{Message: "Beacon Root missing"}
}
return nil, &rpc.UnsupportedForkError{Message: "Unsupported fork"}
}
if s.config.IsCancun(timestamp) && version < clparams.DenebVersion { // Not V3 after cancun
if payloadAttributes.ParentBeaconBlockRoot != nil {
return nil, &rpc.InvalidParamsError{Message: "Unexpected Beacon Root"}
}
return nil, &rpc.UnsupportedForkError{Message: "Unsupported fork"}
}

if s.config.IsCancun(timestamp) && version >= clparams.DenebVersion {
if payloadAttributes.ParentBeaconBlockRoot == nil {
return nil, &rpc.InvalidParamsError{Message: "Beacon Root missing"}
}
}
}

// No need for payload building
Expand All @@ -484,19 +479,6 @@ func (s *EngineServer) forkchoiceUpdated(ctx context.Context, forkchoiceState *e

headHeader := s.chainRW.GetHeaderByHash(forkchoiceState.HeadHash)

if headHeader.Hash() != forkchoiceState.HeadHash {
// Per Item 2 of https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.9/src/engine/specification.md#specification-1:
// Client software MAY skip an update of the forkchoice state and
// MUST NOT begin a payload build process if forkchoiceState.headBlockHash doesn't reference a leaf of the block tree.
// That is, the block referenced by forkchoiceState.headBlockHash is neither the head of the canonical chain nor a block at the tip of any other chain.
// In the case of such an event, client software MUST return
// {payloadStatus: {status: VALID, latestValidHash: forkchoiceState.headBlockHash, validationError: null}, payloadId: null}.

s.logger.Warn("Skipping payload building because forkchoiceState.headBlockHash is not the head of the canonical chain",
"forkChoice.HeadBlockHash", forkchoiceState.HeadHash, "headHeader.Hash", headHeader.Hash())
return &engine_types.ForkChoiceUpdatedResponse{PayloadStatus: status}, nil
}

timestamp := uint64(payloadAttributes.Timestamp)
if headHeader.Time >= timestamp {
return nil, &engine_helpers.InvalidPayloadAttributesErr
Expand Down