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

Implement GetClientVersionV1 #13071

Merged
merged 5 commits into from
Dec 11, 2024
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
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 @@ -777,6 +778,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 @@ -791,6 +813,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)
}
Loading