2020-12-17 16:26:32 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
2022-06-27 13:34:38 +00:00
|
|
|
grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
|
|
|
|
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
|
|
|
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
2020-12-17 16:26:32 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/validator/client"
|
2023-03-20 16:32:32 +00:00
|
|
|
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory"
|
|
|
|
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
2023-03-17 18:52:56 +00:00
|
|
|
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
|
|
|
|
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
2020-12-17 16:26:32 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Initialize a client connect to a beacon node gRPC endpoint.
|
|
|
|
func (s *Server) registerBeaconClient() error {
|
|
|
|
streamInterceptor := grpc.WithStreamInterceptor(middleware.ChainStreamClient(
|
2022-06-27 13:34:38 +00:00
|
|
|
grpcopentracing.StreamClientInterceptor(),
|
|
|
|
grpcprometheus.StreamClientInterceptor,
|
|
|
|
grpcretry.StreamClientInterceptor(),
|
2020-12-17 16:26:32 +00:00
|
|
|
))
|
|
|
|
dialOpts := client.ConstructDialOptions(
|
|
|
|
s.clientMaxCallRecvMsgSize,
|
|
|
|
s.clientWithCert,
|
|
|
|
s.clientGrpcRetries,
|
|
|
|
s.clientGrpcRetryDelay,
|
|
|
|
streamInterceptor,
|
|
|
|
)
|
|
|
|
if dialOpts == nil {
|
|
|
|
return errors.New("no dial options for beacon chain gRPC client")
|
|
|
|
}
|
2021-01-28 14:58:32 +00:00
|
|
|
|
2021-09-16 19:55:51 +00:00
|
|
|
s.ctx = grpcutil.AppendHeaders(s.ctx, s.clientGrpcHeaders)
|
2021-01-28 14:58:32 +00:00
|
|
|
|
2022-11-11 17:33:48 +00:00
|
|
|
grpcConn, err := grpc.DialContext(s.ctx, s.beaconClientEndpoint, dialOpts...)
|
2020-12-17 16:26:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "could not dial endpoint: %s", s.beaconClientEndpoint)
|
|
|
|
}
|
|
|
|
if s.clientWithCert != "" {
|
|
|
|
log.Info("Established secure gRPC connection")
|
|
|
|
}
|
2022-11-11 17:33:48 +00:00
|
|
|
s.beaconNodeHealthClient = ethpb.NewHealthClient(grpcConn)
|
|
|
|
|
|
|
|
conn := validatorHelpers.NewNodeConnection(
|
|
|
|
grpcConn,
|
|
|
|
s.beaconApiEndpoint,
|
|
|
|
s.beaconApiTimeout,
|
|
|
|
)
|
|
|
|
|
2023-03-20 16:32:32 +00:00
|
|
|
s.beaconChainClient = beaconChainClientFactory.NewBeaconChainClient(conn)
|
|
|
|
s.beaconNodeClient = nodeClientFactory.NewNodeClient(conn)
|
2022-11-07 10:29:27 +00:00
|
|
|
s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn)
|
2020-12-17 16:26:32 +00:00
|
|
|
return nil
|
|
|
|
}
|