2023-03-20 16:32:32 +00:00
|
|
|
package grpc_api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2024-03-13 13:01:05 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
|
2024-02-15 05:46:47 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/client/iface"
|
2024-03-13 13:01:05 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2023-03-20 16:32:32 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2024-03-13 13:01:05 +00:00
|
|
|
var (
|
|
|
|
_ = iface.NodeClient(&grpcNodeClient{})
|
|
|
|
)
|
|
|
|
|
2023-03-20 16:32:32 +00:00
|
|
|
type grpcNodeClient struct {
|
2024-03-13 13:01:05 +00:00
|
|
|
nodeClient ethpb.NodeClient
|
|
|
|
healthTracker *beacon.NodeHealthTracker
|
2023-03-20 16:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *grpcNodeClient) GetSyncStatus(ctx context.Context, in *empty.Empty) (*ethpb.SyncStatus, error) {
|
|
|
|
return c.nodeClient.GetSyncStatus(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *grpcNodeClient) GetGenesis(ctx context.Context, in *empty.Empty) (*ethpb.Genesis, error) {
|
|
|
|
return c.nodeClient.GetGenesis(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *grpcNodeClient) GetVersion(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) {
|
|
|
|
return c.nodeClient.GetVersion(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *grpcNodeClient) ListPeers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) {
|
|
|
|
return c.nodeClient.ListPeers(ctx, in)
|
|
|
|
}
|
|
|
|
|
2024-03-13 13:01:05 +00:00
|
|
|
func (c *grpcNodeClient) IsHealthy(ctx context.Context) bool {
|
|
|
|
_, err := c.nodeClient.GetHealth(ctx, ðpb.HealthRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Debug("failed to get health of node")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *grpcNodeClient) HealthTracker() *beacon.NodeHealthTracker {
|
|
|
|
return c.healthTracker
|
2024-01-18 14:27:41 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 16:32:32 +00:00
|
|
|
func NewNodeClient(cc grpc.ClientConnInterface) iface.NodeClient {
|
2024-03-13 13:01:05 +00:00
|
|
|
g := &grpcNodeClient{nodeClient: ethpb.NewNodeClient(cc)}
|
|
|
|
g.healthTracker = beacon.NewNodeHealthTracker(g)
|
|
|
|
return g
|
2023-03-20 16:32:32 +00:00
|
|
|
}
|