mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-29 06:37:17 +00:00
0326be86b5
* starting on patch * finish determining all required patches * properly redefine the patch rules * new patch * rem double semicolon * fix patch file * Merge branch 'master' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * building the deps * test target passes using ethereumapis * compile gateway * attempting to build everything * e2e use ethereumapis * more fixes for slasher * other item * getting closer to compiling slasher * build slasher package * Merge branch 'master' into deprecate-eth-protos * Merge branch 'master' into deprecate-eth-protos * fix benches * lint gazelle * Merge branch 'deprecate-eth-protos' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * proper gateway * lint * Merge branch 'master' into deprecate-eth-protos * fix build * Merge branch 'deprecate-eth-protos' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * use swag * resolve * ignore change * include new patch changes * fix test * builds * fix e2e * gaz
75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
|
"github.com/prysmaticlabs/prysm/shared/version"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// Server defines a server implementation of the gRPC Node service,
|
|
// providing RPC endpoints for verifying a beacon node's sync status, genesis and
|
|
// version information, and services the node implements and runs.
|
|
type Server struct {
|
|
SyncChecker sync.Checker
|
|
Server *grpc.Server
|
|
BeaconDB db.Database
|
|
GenesisTimeFetcher blockchain.GenesisTimeFetcher
|
|
}
|
|
|
|
// GetSyncStatus checks the current network sync status of the node.
|
|
func (ns *Server) GetSyncStatus(ctx context.Context, _ *ptypes.Empty) (*ethpb.SyncStatus, error) {
|
|
return ðpb.SyncStatus{
|
|
Syncing: ns.SyncChecker.Syncing(),
|
|
}, nil
|
|
}
|
|
|
|
// GetGenesis fetches genesis chain information of Ethereum 2.0.
|
|
func (ns *Server) GetGenesis(ctx context.Context, _ *ptypes.Empty) (*ethpb.Genesis, error) {
|
|
contractAddr, err := ns.BeaconDB.DepositContractAddress(ctx)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not retrieve contract address from db: %v", err)
|
|
}
|
|
genesisTime := ns.GenesisTimeFetcher.GenesisTime()
|
|
gt, err := ptypes.TimestampProto(genesisTime)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not convert genesis time to proto: %v", err)
|
|
}
|
|
return ðpb.Genesis{
|
|
GenesisTime: gt,
|
|
DepositContractAddress: contractAddr,
|
|
}, nil
|
|
}
|
|
|
|
// GetVersion checks the version information of the beacon node.
|
|
func (ns *Server) GetVersion(ctx context.Context, _ *ptypes.Empty) (*ethpb.Version, error) {
|
|
return ðpb.Version{
|
|
Version: version.GetVersion(),
|
|
}, nil
|
|
}
|
|
|
|
// ListImplementedServices lists the services implemented and enabled by this node.
|
|
//
|
|
// Any service not present in this list may return UNIMPLEMENTED or
|
|
// PERMISSION_DENIED. The server may also support fetching services by grpc
|
|
// reflection.
|
|
func (ns *Server) ListImplementedServices(ctx context.Context, _ *ptypes.Empty) (*ethpb.ImplementedServices, error) {
|
|
serviceInfo := ns.Server.GetServiceInfo()
|
|
serviceNames := make([]string, 0, len(serviceInfo))
|
|
for svc := range serviceInfo {
|
|
serviceNames = append(serviceNames, svc)
|
|
}
|
|
sort.Strings(serviceNames)
|
|
return ðpb.ImplementedServices{
|
|
Services: serviceNames,
|
|
}, nil
|
|
}
|