2020-12-17 16:26:32 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2024-01-11 16:03:35 +00:00
|
|
|
"net/http"
|
|
|
|
|
2020-12-17 16:26:32 +00:00
|
|
|
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"
|
2024-02-15 05:46:47 +00:00
|
|
|
grpcutil "github.com/prysmaticlabs/prysm/v5/api/grpc"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/validator/client"
|
|
|
|
beaconApi "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api"
|
|
|
|
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-chain-client-factory"
|
|
|
|
nodeClientFactory "github.com/prysmaticlabs/prysm/v5/validator/client/node-client-factory"
|
|
|
|
validatorClientFactory "github.com/prysmaticlabs/prysm/v5/validator/client/validator-client-factory"
|
|
|
|
validatorHelpers "github.com/prysmaticlabs/prysm/v5/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,
|
|
|
|
)
|
|
|
|
|
2024-03-13 13:01:05 +00:00
|
|
|
restHandler := beaconApi.NewBeaconApiJsonRestHandler(http.Client{Timeout: s.beaconApiTimeout}, s.beaconApiEndpoint)
|
|
|
|
|
2024-01-11 16:03:35 +00:00
|
|
|
s.beaconChainClient = beaconChainClientFactory.NewBeaconChainClient(conn, restHandler)
|
|
|
|
s.beaconNodeClient = nodeClientFactory.NewNodeClient(conn, restHandler)
|
|
|
|
s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn, restHandler)
|
|
|
|
|
2020-12-17 16:26:32 +00:00
|
|
|
return nil
|
|
|
|
}
|