eth/catalyst,beacon/engine: implement GetClientVersionV1 (#28915)

This commit is contained in:
lightclient
2024-02-15 12:01:30 +01:00
committed by GitHub
parent 2a1d94bd1d
commit 9e3e46671e
3 changed files with 60 additions and 0 deletions
+19
View File
@@ -30,9 +30,11 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/internal/version"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params/forks"
"github.com/ethereum/go-ethereum/rpc"
)
@@ -813,6 +815,23 @@ func (api *ConsensusAPI) ExchangeCapabilities([]string) []string {
return caps
}
// GetClientVersionV1 exchanges client version data of this node.
func (api *ConsensusAPI) GetClientVersionV1(info engine.ClientVersionV1) []engine.ClientVersionV1 {
log.Trace("Engine API request received", "method", "GetClientVersionV1", "info", info.String())
commit := make([]byte, 4)
if vcs, ok := version.VCS(); ok {
commit = common.FromHex(vcs.Commit)[0:4]
}
return []engine.ClientVersionV1{
{
Code: engine.ClientCode,
Name: engine.ClientName,
Version: params.VersionWithMeta,
Commit: hexutil.Encode(commit),
},
}
}
// GetPayloadBodiesByHashV1 implements engine_getPayloadBodiesByHashV1 which allows for retrieval of a list
// of block bodies by the engine api.
func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*engine.ExecutionPayloadBodyV1 {
+23
View File
@@ -1663,3 +1663,26 @@ func TestParentBeaconBlockRoot(t *testing.T) {
t.Fatalf("incorrect root stored: want %s, got %s", *blockParams.BeaconRoot, root)
}
}
// TestGetClientVersion verifies the expected version info is returned.
func TestGetClientVersion(t *testing.T) {
genesis, preMergeBlocks := generateMergeChain(10, false)
n, ethservice := startEthService(t, genesis, preMergeBlocks)
defer n.Close()
api := NewConsensusAPI(ethservice)
info := engine.ClientVersionV1{
Code: "TT",
Name: "test",
Version: "1.1.1",
Commit: "0x12345678",
}
infos := api.GetClientVersionV1(info)
if len(infos) != 1 {
t.Fatalf("expected only one returned client version, got %d", len(infos))
}
info = infos[0]
if info.Code != engine.ClientCode || info.Name != engine.ClientName || info.Version != params.VersionWithMeta {
t.Fatalf("client info does match expected, got %s", info.String())
}
}