Skip to content

Commit

Permalink
Engine API PR 498 (clarify payloadAttributes checks) (#8982)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored Dec 14, 2023
1 parent 3b68d57 commit b26d0f2
Showing 1 changed file with 7 additions and 25 deletions.
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

0 comments on commit b26d0f2

Please sign in to comment.