mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
61026103c6
* initial validator attesthead rewrite based on proposer rewrite * proceed with fetching committees and tree hashing the canonical head at assigned attester slot * complete filling the properties of attestation data and all associated root hashes * add when to attest todo * finish entire attester client logic * tests with mocks checked in * tests passing in client * stubbed out server implementation * fixed build due to old property * regen mocks with new mockgen version * fixed broken tests * complete bazel build fix * address some review comments * deep proto test * tests passing after checking for empty committee and crosslink root * address nishant comments
94 lines
2.2 KiB
Go
94 lines
2.2 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var log = logrus.WithField("prefix", "validator")
|
|
|
|
// ValidatorService represents a service to manage the validator client
|
|
// routine.
|
|
type ValidatorService struct {
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
validator Validator
|
|
conn *grpc.ClientConn
|
|
endpoint string
|
|
withCert string
|
|
}
|
|
|
|
// Config for the validator service.
|
|
type Config struct {
|
|
Endpoint string
|
|
CertFlag string
|
|
}
|
|
|
|
// NewValidatorService creates a new validator service for the service
|
|
// registry.
|
|
func NewValidatorService(ctx context.Context, cfg *Config) *ValidatorService {
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
return &ValidatorService{
|
|
ctx: ctx,
|
|
cancel: cancel,
|
|
endpoint: cfg.Endpoint,
|
|
withCert: cfg.CertFlag,
|
|
}
|
|
}
|
|
|
|
// Start the validator service. Launches the main go routine for the validator
|
|
// client.
|
|
func (v *ValidatorService) Start() {
|
|
var dialOpt grpc.DialOption
|
|
if v.withCert != "" {
|
|
creds, err := credentials.NewClientTLSFromFile(v.withCert, "")
|
|
if err != nil {
|
|
log.Errorf("Could not get valid credentials: %v", err)
|
|
return
|
|
}
|
|
dialOpt = grpc.WithTransportCredentials(creds)
|
|
} else {
|
|
dialOpt = grpc.WithInsecure()
|
|
log.Warn("You are using an insecure gRPC connection! Please provide a certificate and key to use a secure connection.")
|
|
}
|
|
conn, err := grpc.DialContext(v.ctx, v.endpoint, dialOpt)
|
|
if err != nil {
|
|
log.Errorf("Could not dial endpoint: %s, %v", v.endpoint, err)
|
|
return
|
|
}
|
|
log.Info("Successfully started gRPC connection")
|
|
v.conn = conn
|
|
v.validator = &validator{
|
|
beaconClient: pb.NewBeaconServiceClient(v.conn),
|
|
validatorClient: pb.NewValidatorServiceClient(v.conn),
|
|
attesterClient: pb.NewAttesterServiceClient(v.conn),
|
|
}
|
|
go run(v.ctx, v.validator)
|
|
}
|
|
|
|
// Stop the validator service.
|
|
func (v *ValidatorService) Stop() error {
|
|
v.cancel()
|
|
log.Info("Stopping service")
|
|
if v.conn != nil {
|
|
return v.conn.Close()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Status ...
|
|
//
|
|
// WIP - not done.
|
|
func (v *ValidatorService) Status() error {
|
|
if v.conn == nil {
|
|
return errors.New("no connection to beacon RPC")
|
|
}
|
|
return nil
|
|
}
|