2020-09-03 23:25:56 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-08 20:54:56 +00:00
|
|
|
"time"
|
2020-09-03 23:25:56 +00:00
|
|
|
|
2020-12-18 18:03:24 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
validatorpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
2020-12-16 17:30:48 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
2020-09-03 23:25:56 +00:00
|
|
|
)
|
|
|
|
|
2020-09-08 20:02:12 +00:00
|
|
|
// GetBeaconNodeConnection retrieves the current beacon node connection
|
|
|
|
// information, as well as its sync status.
|
2023-02-23 15:24:06 +00:00
|
|
|
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
|
2021-08-18 21:24:01 +00:00
|
|
|
func (s *Server) GetBeaconNodeConnection(ctx context.Context, _ *emptypb.Empty) (*validatorpb.NodeConnectionResponse, error) {
|
2020-09-03 23:25:56 +00:00
|
|
|
syncStatus, err := s.syncChecker.Syncing(ctx)
|
2020-09-08 20:02:12 +00:00
|
|
|
if err != nil || s.validatorService.Status() != nil {
|
2023-04-18 20:53:16 +00:00
|
|
|
//nolint:nilerr
|
2021-08-18 21:24:01 +00:00
|
|
|
return &validatorpb.NodeConnectionResponse{
|
2020-09-08 22:35:31 +00:00
|
|
|
GenesisTime: 0,
|
|
|
|
BeaconNodeEndpoint: s.nodeGatewayEndpoint,
|
|
|
|
Connected: false,
|
|
|
|
Syncing: false,
|
2020-09-08 20:02:12 +00:00
|
|
|
}, nil
|
2020-09-03 23:25:56 +00:00
|
|
|
}
|
2020-10-01 18:53:36 +00:00
|
|
|
genesis, err := s.genesisFetcher.GenesisInfo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-18 21:24:01 +00:00
|
|
|
return &validatorpb.NodeConnectionResponse{
|
2020-09-08 20:54:56 +00:00
|
|
|
GenesisTime: uint64(time.Unix(genesis.GenesisTime.Seconds, 0).Unix()),
|
|
|
|
DepositContractAddress: genesis.DepositContractAddress,
|
|
|
|
BeaconNodeEndpoint: s.nodeGatewayEndpoint,
|
|
|
|
Connected: true,
|
|
|
|
Syncing: syncStatus,
|
2020-09-03 23:25:56 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2020-11-27 18:28:45 +00:00
|
|
|
|
|
|
|
// GetLogsEndpoints for the beacon and validator client.
|
2023-02-23 15:24:06 +00:00
|
|
|
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
|
2022-09-02 14:56:47 +00:00
|
|
|
func (*Server) GetLogsEndpoints(_ context.Context, _ *emptypb.Empty) (*validatorpb.LogsEndpointResponse, error) {
|
2020-12-18 18:03:24 +00:00
|
|
|
return nil, status.Error(codes.Unimplemented, "unimplemented")
|
2020-11-27 18:28:45 +00:00
|
|
|
}
|
2020-12-16 17:30:48 +00:00
|
|
|
|
2021-01-04 18:51:52 +00:00
|
|
|
// GetVersion --
|
2023-02-23 15:24:06 +00:00
|
|
|
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
|
2021-08-18 21:24:01 +00:00
|
|
|
func (s *Server) GetVersion(ctx context.Context, _ *emptypb.Empty) (*validatorpb.VersionResponse, error) {
|
2021-05-17 18:32:04 +00:00
|
|
|
beacon, err := s.beaconNodeClient.GetVersion(ctx, &emptypb.Empty{})
|
2021-01-04 18:51:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-18 21:24:01 +00:00
|
|
|
return &validatorpb.VersionResponse{
|
2021-01-04 18:51:52 +00:00
|
|
|
Beacon: beacon.Version,
|
2021-01-25 21:27:30 +00:00
|
|
|
Validator: version.Version(),
|
2021-01-04 18:51:52 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:03:24 +00:00
|
|
|
// StreamBeaconLogs from the beacon node via a gRPC server-side stream.
|
2023-02-23 15:24:06 +00:00
|
|
|
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
|
2021-08-18 21:24:01 +00:00
|
|
|
func (s *Server) StreamBeaconLogs(req *emptypb.Empty, stream validatorpb.Health_StreamBeaconLogsServer) error {
|
2021-02-24 17:10:25 +00:00
|
|
|
// Wrap service context with a cancel in order to propagate the exiting of
|
|
|
|
// this method properly to the beacon node server.
|
|
|
|
ctx, cancel := context.WithCancel(s.ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client, err := s.beaconNodeHealthClient.StreamBeaconLogs(ctx, req)
|
2020-12-18 18:03:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-s.ctx.Done():
|
|
|
|
return status.Error(codes.Canceled, "Context canceled")
|
|
|
|
case <-stream.Context().Done():
|
|
|
|
return status.Error(codes.Canceled, "Context canceled")
|
2021-02-24 17:10:25 +00:00
|
|
|
case <-client.Context().Done():
|
|
|
|
return status.Error(codes.Canceled, "Context canceled")
|
2020-12-18 18:03:24 +00:00
|
|
|
default:
|
|
|
|
resp, err := client.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not receive beacon logs from stream")
|
|
|
|
}
|
|
|
|
if err := stream.Send(resp); err != nil {
|
|
|
|
return status.Errorf(codes.Unavailable, "Could not send over stream: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-16 17:30:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 18:03:24 +00:00
|
|
|
// StreamValidatorLogs from the validator client via a gRPC server-side stream.
|
2023-02-23 15:24:06 +00:00
|
|
|
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
|
2021-08-18 21:24:01 +00:00
|
|
|
func (s *Server) StreamValidatorLogs(_ *emptypb.Empty, stream validatorpb.Health_StreamValidatorLogsServer) error {
|
2020-12-18 18:03:24 +00:00
|
|
|
ch := make(chan []byte, s.streamLogsBufferSize)
|
|
|
|
sub := s.logsStreamer.LogsFeed().Subscribe(ch)
|
2021-02-23 21:33:23 +00:00
|
|
|
defer func() {
|
|
|
|
sub.Unsubscribe()
|
|
|
|
defer close(ch)
|
|
|
|
}()
|
2020-12-18 18:03:24 +00:00
|
|
|
|
|
|
|
recentLogs := s.logsStreamer.GetLastFewLogs()
|
|
|
|
logStrings := make([]string, len(recentLogs))
|
|
|
|
for i, log := range recentLogs {
|
|
|
|
logStrings[i] = string(log)
|
|
|
|
}
|
|
|
|
if err := stream.Send(&pb.LogsResponse{
|
|
|
|
Logs: logStrings,
|
|
|
|
}); err != nil {
|
|
|
|
return status.Errorf(codes.Unavailable, "Could not send over stream: %v", err)
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case log := <-ch:
|
|
|
|
resp := &pb.LogsResponse{
|
|
|
|
Logs: []string{string(log)},
|
|
|
|
}
|
|
|
|
if err := stream.Send(resp); err != nil {
|
|
|
|
return status.Errorf(codes.Unavailable, "Could not send over stream: %v", err)
|
|
|
|
}
|
|
|
|
case <-s.ctx.Done():
|
|
|
|
return status.Error(codes.Canceled, "Context canceled")
|
2021-02-23 21:33:23 +00:00
|
|
|
case err := <-sub.Err():
|
|
|
|
return status.Errorf(codes.Canceled, "Subscriber error, closing: %v", err)
|
2020-12-18 18:03:24 +00:00
|
|
|
case <-stream.Context().Done():
|
|
|
|
return status.Error(codes.Canceled, "Context canceled")
|
|
|
|
}
|
|
|
|
}
|
2020-12-16 17:30:48 +00:00
|
|
|
}
|