Skip to content

Commit

Permalink
Implement GetClientVersionV1 (#13071)
Browse files Browse the repository at this point in the history
A rather simple implementation for `engine_getClientVersionV1`
  • Loading branch information
somnathb1 authored Dec 11, 2024
1 parent f22317e commit f3e688f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
VersionModifier = "alpha6" // Modifier component of the current release
VersionKeyCreated = "ErigonVersionCreated"
VersionKeyFinished = "ErigonVersionFinished"
ClientName = "erigon"
ClientCode = "EG"
)

// Version holds the textual version string.
Expand Down
23 changes: 23 additions & 0 deletions turbo/engineapi/engine_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/erigontech/erigon/consensus/merge"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/eth/ethutils"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/turbo/engineapi/engine_block_downloader"
"github.com/erigontech/erigon/turbo/engineapi/engine_helpers"
Expand Down Expand Up @@ -793,6 +794,27 @@ func (e *EngineServer) GetPayloadBodiesByRangeV1(ctx context.Context, start, cou
return e.getPayloadBodiesByRange(ctx, uint64(start), uint64(count))
}

// Returns the node's code and commit details in a slice
// See https://github.com/ethereum/execution-apis/blob/main/src/engine/identification.md#engine_getclientversionv1
func (e *EngineServer) GetClientVersionV1(ctx context.Context, callerVersion *engine_types.ClientVersionV1) ([]engine_types.ClientVersionV1, error) {
if callerVersion != nil {
e.logger.Info("[GetClientVersionV1] Received request from" + callerVersion.String())
}
commitBytes := [4]byte{}
c := []byte(params.GitCommit)
if len(c) >= 4 {
copy(commitBytes[:], c[0:4])
}
result := make([]engine_types.ClientVersionV1, 1)
result[0] = engine_types.ClientVersionV1{
Code: params.ClientCode,
Name: params.ClientName,
Version: params.Version,
Commit: commitBytes,
}
return result, nil
}

var ourCapabilities = []string{
"engine_forkchoiceUpdatedV1",
"engine_forkchoiceUpdatedV2",
Expand All @@ -807,6 +829,7 @@ var ourCapabilities = []string{
"engine_getPayloadV4",
"engine_getPayloadBodiesByHashV1",
"engine_getPayloadBodiesByRangeV1",
"engine_getClientVersionV1",
}

func (e *EngineServer) ExchangeCapabilities(fromCl []string) []string {
Expand Down
12 changes: 12 additions & 0 deletions turbo/engineapi/engine_types/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"

"github.com/erigontech/erigon-lib/common/hexutil"

Expand Down Expand Up @@ -107,6 +108,17 @@ type GetPayloadResponse struct {
ShouldOverrideBuilder bool `json:"shouldOverrideBuilder"`
}

type ClientVersionV1 struct {
Code string `json:"code" gencodec:"required"`
Name string `json:"name" gencodec:"required"`
Version string `json:"version" gencodec:"required"`
Commit [4]byte `json:"commit" gencodec:"required"`
}

func (c ClientVersionV1) String() string {
return fmt.Sprintf("ClientCode: %s, %s-%s-%s", c.Code, c.Name, c.Version, c.Commit)
}

type StringifiedError struct{ err error }

func NewStringifiedError(err error) *StringifiedError {
Expand Down
1 change: 1 addition & 0 deletions turbo/engineapi/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ type EngineAPI interface {
GetPayloadV4(ctx context.Context, payloadID hexutility.Bytes) (*engine_types.GetPayloadResponse, error)
GetPayloadBodiesByHashV1(ctx context.Context, hashes []common.Hash) ([]*engine_types.ExecutionPayloadBody, error)
GetPayloadBodiesByRangeV1(ctx context.Context, start, count hexutil.Uint64) ([]*engine_types.ExecutionPayloadBody, error)
GetClientVersionV1(ctx context.Context, callerVersion *engine_types.ClientVersionV1) ([]engine_types.ClientVersionV1, error)
}

0 comments on commit f3e688f

Please sign in to comment.