mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Implement GetVersion in the node API (#8207)
* initial implementation * implement GetVersion * remove implementation of GetIdentity * remove MetadataProvider from server * gzl
This commit is contained in:
@@ -23,6 +23,7 @@ go_library(
|
||||
"//beacon-chain/rpc/beaconv1:go_default_library",
|
||||
"//beacon-chain/rpc/debug:go_default_library",
|
||||
"//beacon-chain/rpc/node:go_default_library",
|
||||
"//beacon-chain/rpc/nodev1:go_default_library",
|
||||
"//beacon-chain/rpc/validator:go_default_library",
|
||||
"//beacon-chain/state/stategen:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
|
||||
@@ -14,6 +14,7 @@ go_library(
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/p2p:go_default_library",
|
||||
"//beacon-chain/sync:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1:go_default_library",
|
||||
@@ -23,7 +24,16 @@ go_library(
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["server_test.go"],
|
||||
srcs = [
|
||||
"node_test.go",
|
||||
"server_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_prysmaticlabs_ethereumapis//eth/v1:go_default_library"],
|
||||
deps = [
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"@com_github_gogo_protobuf//types:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,10 +2,13 @@ package nodev1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
)
|
||||
|
||||
// GetIdentity retrieves data about the node's network presence.
|
||||
@@ -25,8 +28,13 @@ func (ns *Server) ListPeers(ctx context.Context, _ *ptypes.Empty) (*ethpb.PeersR
|
||||
|
||||
// GetVersion requests that the beacon node identify information about its implementation in a
|
||||
// format similar to a HTTP User-Agent field.
|
||||
func (ns *Server) GetVersion(ctx context.Context, _ *ptypes.Empty) (*ethpb.VersionResponse, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
func (ns *Server) GetVersion(_ context.Context, _ *ptypes.Empty) (*ethpb.VersionResponse, error) {
|
||||
v := fmt.Sprintf("Prysm/%s (%s %s)", version.GetSemanticVersion(), runtime.GOOS, runtime.GOARCH)
|
||||
return ðpb.VersionResponse{
|
||||
Data: ðpb.Version{
|
||||
Version: v,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetSyncStatus requests the beacon node to describe if it's currently syncing or not, and
|
||||
|
||||
25
beacon-chain/rpc/nodev1/node_test.go
Normal file
25
beacon-chain/rpc/nodev1/node_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package nodev1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
)
|
||||
|
||||
func TestGetVersion(t *testing.T) {
|
||||
semVer := version.GetSemanticVersion()
|
||||
os := runtime.GOOS
|
||||
arch := runtime.GOARCH
|
||||
res, err := (&Server{}).GetVersion(context.Background(), &ptypes.Empty{})
|
||||
require.NoError(t, err)
|
||||
v := res.Data.Version
|
||||
assert.Equal(t, true, strings.Contains(v, semVer))
|
||||
assert.Equal(t, true, strings.Contains(v, os))
|
||||
assert.Equal(t, true, strings.Contains(v, arch))
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/nodev1"
|
||||
|
||||
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
|
||||
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||
@@ -272,6 +274,15 @@ func (s *Service) Start() {
|
||||
BeaconMonitoringHost: s.beaconMonitoringHost,
|
||||
BeaconMonitoringPort: s.beaconMonitoringPort,
|
||||
}
|
||||
nodeServerV1 := &nodev1.Server{
|
||||
BeaconDB: s.beaconDB,
|
||||
Server: s.grpcServer,
|
||||
SyncChecker: s.syncService,
|
||||
GenesisTimeFetcher: s.genesisTimeFetcher,
|
||||
PeersFetcher: s.peersFetcher,
|
||||
PeerManager: s.peerManager,
|
||||
GenesisFetcher: s.genesisFetcher,
|
||||
}
|
||||
beaconChainServer := &beacon.Server{
|
||||
Ctx: s.ctx,
|
||||
BeaconDB: s.beaconDB,
|
||||
@@ -313,6 +324,7 @@ func (s *Service) Start() {
|
||||
SyncChecker: s.syncService,
|
||||
}
|
||||
ethpb.RegisterNodeServer(s.grpcServer, nodeServer)
|
||||
ethpbv1.RegisterBeaconNodeServer(s.grpcServer, nodeServerV1)
|
||||
pbrpc.RegisterHealthServer(s.grpcServer, nodeServer)
|
||||
ethpb.RegisterBeaconChainServer(s.grpcServer, beaconChainServer)
|
||||
ethpbv1.RegisterBeaconChainServer(s.grpcServer, beaconChainServerV1)
|
||||
|
||||
@@ -24,6 +24,11 @@ func GetVersion() string {
|
||||
return fmt.Sprintf("%s. Built at: %s", GetBuildData(), buildDate)
|
||||
}
|
||||
|
||||
// GetSemanticVersion returns the Major.Minor.Patch version of this build.
|
||||
func GetSemanticVersion() string {
|
||||
return gitTag
|
||||
}
|
||||
|
||||
// GetBuildData returns the git tag and commit of the current build.
|
||||
func GetBuildData() string {
|
||||
// if doing a local build, these values are not interpolated
|
||||
|
||||
Reference in New Issue
Block a user