From cc03579301472ed069597ad905c3e3facc333c59 Mon Sep 17 00:00:00 2001 From: Somnath Date: Fri, 10 Jan 2025 18:49:44 +0400 Subject: [PATCH] Implement GetClientVersionV1 (#13071) (#13364) A rather simple implementation for `engine_getClientVersionV1` Cherry pick https://github.com/erigontech/erigon/pull/13071 --- params/version.go | 2 ++ turbo/engineapi/engine_server.go | 23 +++++++++++++++++++++++ turbo/engineapi/engine_types/jsonrpc.go | 12 ++++++++++++ turbo/engineapi/interface.go | 1 + 4 files changed, 38 insertions(+) diff --git a/params/version.go b/params/version.go index 0d4e9cc0554..e1b3cf666b8 100644 --- a/params/version.go +++ b/params/version.go @@ -37,6 +37,8 @@ const ( VersionModifier = "" // Modifier component of the current release VersionKeyCreated = "ErigonVersionCreated" VersionKeyFinished = "ErigonVersionFinished" + ClientName = "erigon" + ClientCode = "EG" ) // Version holds the textual version string. diff --git a/turbo/engineapi/engine_server.go b/turbo/engineapi/engine_server.go index 92f3e24fc31..5d7c73456a9 100644 --- a/turbo/engineapi/engine_server.go +++ b/turbo/engineapi/engine_server.go @@ -32,6 +32,7 @@ import ( "github.com/erigontech/erigon/consensus" "github.com/erigontech/erigon/consensus/merge" "github.com/erigontech/erigon/core/types" + "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" @@ -761,6 +762,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", @@ -776,6 +798,7 @@ var ourCapabilities = []string{ "engine_exchangeTransitionConfigurationV1", "engine_getPayloadBodiesByHashV1", "engine_getPayloadBodiesByRangeV1", + "engine_getClientVersionV1", } func (e *EngineServer) ExchangeCapabilities(fromCl []string) []string { diff --git a/turbo/engineapi/engine_types/jsonrpc.go b/turbo/engineapi/engine_types/jsonrpc.go index 83e8c1c19b6..b099eaf1d82 100644 --- a/turbo/engineapi/engine_types/jsonrpc.go +++ b/turbo/engineapi/engine_types/jsonrpc.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "encoding/json" "errors" + "fmt" "github.com/erigontech/erigon-lib/common/hexutil" @@ -91,6 +92,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 { diff --git a/turbo/engineapi/interface.go b/turbo/engineapi/interface.go index 96253c9654a..97de1135917 100644 --- a/turbo/engineapi/interface.go +++ b/turbo/engineapi/interface.go @@ -24,4 +24,5 @@ type EngineAPI interface { ExchangeTransitionConfigurationV1(ctx context.Context, transitionConfiguration *engine_types.TransitionConfiguration) (*engine_types.TransitionConfiguration, 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) }