Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions simulators/ethereum/engine/clmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (cl *CLMocker) setTTDBlockClient(ec *EngineClient) {
if resp.Error != nil {
cl.Logf("CLMocker: forkchoiceUpdated Error: %v\n", resp.Error)
} else {
if resp.ForkchoiceResponse.PayloadStatus.Status == "VALID" {
if resp.ForkchoiceResponse.PayloadStatus.Status == Valid {
anySuccess = true
} else {
cl.Logf("CLMocker: forkchoiceUpdated Response: %v\n", resp.ForkchoiceResponse)
Expand Down Expand Up @@ -220,7 +220,7 @@ func (cl *CLMocker) getNextPayloadID() {
if err != nil {
cl.Fatalf("CLMocker: Could not send forkchoiceUpdatedV1 (%v): %v", cl.NextBlockProducer.Client.Container, err)
}
if resp.PayloadStatus.Status != "VALID" {
if resp.PayloadStatus.Status != Valid {
cl.Fatalf("CLMocker: Unexpected forkchoiceUpdated Response from Payload builder: %v", resp)
}
cl.NextPayloadID = resp.PayloadID
Expand All @@ -241,7 +241,7 @@ func (cl *CLMocker) broadcastNextNewPayload() {
cl.Logf("CLMocker: broadcastNewPayload Error (%v): %v\n", resp.Container, resp.Error)

} else {
if resp.ExecutePayloadResponse.Status == "VALID" {
if resp.ExecutePayloadResponse.Status == Valid {
// The client is synced and the payload was immediately validated
// https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md:
// - If validation succeeds, the response MUST contain {status: VALID, latestValidHash: payload.blockHash}
Expand All @@ -251,7 +251,7 @@ func (cl *CLMocker) broadcastNextNewPayload() {
if *resp.ExecutePayloadResponse.LatestValidHash != cl.LatestPayloadBuilt.BlockHash {
cl.Fatalf("CLMocker: NewPayload returned VALID status with incorrect LatestValidHash==%v, expected %v", resp.ExecutePayloadResponse.LatestValidHash, cl.LatestPayloadBuilt.BlockHash)
}
} else if resp.ExecutePayloadResponse.Status == "ACCEPTED" {
} else if resp.ExecutePayloadResponse.Status == Accepted {
// The client is not synced but the payload was accepted
// https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md:
// - {status: ACCEPTED, latestValidHash: null, validationError: null} if the following conditions are met:
Expand All @@ -275,7 +275,7 @@ func (cl *CLMocker) broadcastLatestForkchoice() {
for _, resp := range cl.broadcastForkchoiceUpdated(&cl.LatestForkchoice, nil) {
if resp.Error != nil {
cl.Logf("CLMocker: broadcastForkchoiceUpdated Error (%v): %v\n", resp.Container, resp.Error)
} else if resp.ForkchoiceResponse.PayloadStatus.Status != "VALID" {
} else if resp.ForkchoiceResponse.PayloadStatus.Status != Valid {
cl.Logf("CLMocker: broadcastForkchoiceUpdated Response (%v): %v\n", resp.Container, resp.ForkchoiceResponse)
}
}
Expand Down
63 changes: 60 additions & 3 deletions simulators/ethereum/engine/engineclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"net"
"net/http"
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -155,15 +156,71 @@ func (ec *EngineClient) Ctx() context.Context {

// Engine API Types
type PayloadStatusV1 struct {
Status string `json:"status"`
LatestValidHash *common.Hash `json:"latestValidHash"`
ValidationError *string `json:"validationError"`
Status PayloadStatus `json:"status"`
LatestValidHash *common.Hash `json:"latestValidHash"`
ValidationError *string `json:"validationError"`
}
type ForkChoiceResponse struct {
PayloadStatus PayloadStatusV1 `json:"payloadStatus"`
PayloadID *PayloadID `json:"payloadId"`
}

type PayloadStatus int
type PayloadStatusSlice []PayloadStatus

const (
Valid PayloadStatus = iota
Invalid
Accepted
Syncing
InvalidTerminalBlock
InvalidBlockHash
)

var PayloadStatuses = map[PayloadStatus]string{
Valid: "VALID",
Invalid: "INVALID",
Accepted: "ACCEPTED",
Syncing: "SYNCING",
InvalidTerminalBlock: "INVALID_TERMINAL_BLOCK",
InvalidBlockHash: "INVALID_BLOCK_HASH",
}

func (b PayloadStatus) String() string {
str, ok := PayloadStatuses[b]
if !ok {
return "UNKNOWN"
}
return str
}

func (b PayloadStatusSlice) String() string {
names := make([]string, 0)
for _, status := range b {
names = append(names, status.String())
}
return strings.Join(names, "|")
}

func (b PayloadStatus) MarshalText() ([]byte, error) {
str, ok := PayloadStatuses[b]
if !ok {
return nil, fmt.Errorf("invalid payload status")
}
return []byte(str), nil
}

func (b *PayloadStatus) UnmarshalText(input []byte) error {
s := string(input)
for p, status := range PayloadStatuses {
if status == s {
*b = p
return nil
}
}
return fmt.Errorf("invalid payload status: %s", s)
}

type PayloadID [8]byte

func (b PayloadID) MarshalText() ([]byte, error) {
Expand Down
Loading