diff --git a/.bazelrc b/.bazelrc index d4447811b..c0f28270a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -230,3 +230,9 @@ build --modify_execution_info='GoStdlib.*=+no-remote-cache' # Set bazel gotag build --define gotags=bazel + +# Build the binary with Beacon API calls for the validator +build --flag_alias=use_beacon_api=//validator/client/validator-client-factory:use_beacon_api + +build:beacon_api --use_beacon_api +build:beacon_api --define=gotags=use_beacon_api diff --git a/cmd/validator/accounts/exit_test.go b/cmd/validator/accounts/exit_test.go index 035b32fcb..43bd3a783 100644 --- a/cmd/validator/accounts/exit_test.go +++ b/cmd/validator/accounts/exit_test.go @@ -21,7 +21,7 @@ import ( func TestExitAccountsCli_OK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + mockValidatorClient := mock2.NewMockValidatorClient(ctrl) mockNodeClient := mock2.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). @@ -113,7 +113,7 @@ func TestExitAccountsCli_OK(t *testing.T) { func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + mockValidatorClient := mock2.NewMockValidatorClient(ctrl) mockNodeClient := mock2.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). @@ -220,7 +220,7 @@ func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) { func TestExitAccountsCli_OK_ForceExit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + mockValidatorClient := mock2.NewMockValidatorClient(ctrl) mockNodeClient := mock2.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). diff --git a/hack/update-mockgen.sh b/hack/update-mockgen.sh index 8d7e5b3fc..7570ca6eb 100755 --- a/hack/update-mockgen.sh +++ b/hack/update-mockgen.sh @@ -4,7 +4,7 @@ # Use a space to separate mock destination from its interfaces. mock_path="testing/mock" -mocks=( +proto_mocks=( "$mock_path/beacon_service_mock.go BeaconChainClient,BeaconChain_StreamChainHeadClient,BeaconChain_StreamAttestationsClient,BeaconChain_StreamBlocksClient,BeaconChain_StreamValidatorsInfoClient,BeaconChain_StreamIndexedAttestationsClient" "$mock_path/beacon_chain_service_mock.go BeaconChain_StreamChainHeadServer,BeaconChain_StreamAttestationsServer,BeaconChain_StreamBlocksServer,BeaconChain_StreamValidatorsInfoServer,BeaconChain_StreamIndexedAttestationsServer" "$mock_path/beacon_validator_server_mock.go BeaconNodeValidatorServer,BeaconNodeValidator_WaitForActivationServer,BeaconNodeValidator_WaitForChainStartServer,BeaconNodeValidator_StreamDutiesServer" @@ -15,13 +15,24 @@ mocks=( "$mock_path/keymanager_mock.go RemoteSignerClient" ) -for ((i = 0; i < ${#mocks[@]}; i++)); do - file=${mocks[i]% *}; - interfaces=${mocks[i]#* }; +iface_mocks=( + "$mock_path/validator_client_mock.go ValidatorClient" +) + +for ((i = 0; i < ${#proto_mocks[@]}; i++)); do + file=${proto_mocks[i]% *}; + interfaces=${proto_mocks[i]#* }; echo "generating $file for interfaces: $interfaces"; GO11MODULE=on mockgen -package=mock -destination="$file" github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1 "$interfaces" done +for ((i = 0; i < ${#iface_mocks[@]}; i++)); do + file=${iface_mocks[i]% *}; + interfaces=${iface_mocks[i]#* }; + echo "generating $file for interfaces: $interfaces"; + GO11MODULE=on mockgen -package=mock -destination="$file" github.com/prysmaticlabs/prysm/v3/validator/client/iface "$interfaces" +done + goimports -w "$mock_path/." gofmt -s -w "$mock_path/." diff --git a/testing/endtoend/evaluators/BUILD.bazel b/testing/endtoend/evaluators/BUILD.bazel index a9b8b8766..a50222806 100644 --- a/testing/endtoend/evaluators/BUILD.bazel +++ b/testing/endtoend/evaluators/BUILD.bazel @@ -47,6 +47,7 @@ go_library( "//testing/endtoend/types:go_default_library", "//testing/util:go_default_library", "//time/slots:go_default_library", + "//validator/client/validator-client-factory:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_ethereum_go_ethereum//ethclient:go_default_library", diff --git a/testing/endtoend/evaluators/fork.go b/testing/endtoend/evaluators/fork.go index 8f1dfa6d1..5744a2698 100644 --- a/testing/endtoend/evaluators/fork.go +++ b/testing/endtoend/evaluators/fork.go @@ -11,6 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/endtoend/policies" "github.com/prysmaticlabs/prysm/v3/testing/endtoend/types" "github.com/prysmaticlabs/prysm/v3/time/slots" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "google.golang.org/grpc" ) @@ -32,7 +33,7 @@ var BellatrixForkTransition = types.Evaluator{ func altairForkOccurs(conns ...*grpc.ClientConn) error { conn := conns[0] - client := ethpb.NewBeaconNodeValidatorClient(conn) + client := validatorClientFactory.NewValidatorClient(conn) ctx, cancel := context.WithTimeout(context.Background(), streamDeadline) defer cancel() stream, err := client.StreamBlocksAltair(ctx, ðpb.StreamBlocksRequest{VerifiedOnly: true}) @@ -74,7 +75,7 @@ func altairForkOccurs(conns ...*grpc.ClientConn) error { func bellatrixForkOccurs(conns ...*grpc.ClientConn) error { conn := conns[0] - client := ethpb.NewBeaconNodeValidatorClient(conn) + client := validatorClientFactory.NewValidatorClient(conn) ctx, cancel := context.WithTimeout(context.Background(), streamDeadline) defer cancel() stream, err := client.StreamBlocksAltair(ctx, ðpb.StreamBlocksRequest{VerifiedOnly: true}) diff --git a/testing/endtoend/evaluators/operations.go b/testing/endtoend/evaluators/operations.go index f8b2cc199..eb7b26707 100644 --- a/testing/endtoend/evaluators/operations.go +++ b/testing/endtoend/evaluators/operations.go @@ -20,6 +20,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/endtoend/policies" e2etypes "github.com/prysmaticlabs/prysm/v3/testing/endtoend/types" "github.com/prysmaticlabs/prysm/v3/testing/util" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "golang.org/x/exp/rand" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" @@ -283,7 +284,7 @@ func depositedValidatorsAreActive(conns ...*grpc.ClientConn) error { func proposeVoluntaryExit(conns ...*grpc.ClientConn) error { conn := conns[0] - valClient := ethpb.NewBeaconNodeValidatorClient(conn) + valClient := validatorClientFactory.NewValidatorClient(conn) beaconClient := ethpb.NewBeaconChainClient(conn) ctx := context.Background() diff --git a/testing/endtoend/evaluators/slashing.go b/testing/endtoend/evaluators/slashing.go index a1c0d0917..073ac1f8e 100644 --- a/testing/endtoend/evaluators/slashing.go +++ b/testing/endtoend/evaluators/slashing.go @@ -18,6 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/endtoend/policies" e2eTypes "github.com/prysmaticlabs/prysm/v3/testing/endtoend/types" "github.com/prysmaticlabs/prysm/v3/testing/util" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" ) @@ -108,7 +109,7 @@ func validatorsLoseBalance(conns ...*grpc.ClientConn) error { func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error { conn := conns[0] - valClient := eth.NewBeaconNodeValidatorClient(conn) + valClient := validatorClientFactory.NewValidatorClient(conn) beaconClient := eth.NewBeaconChainClient(conn) ctx := context.Background() @@ -185,7 +186,7 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error { } // We only broadcast to conns[0] here since we can trust that at least 1 node will be online. // Only broadcasting the attestation to one node also helps test slashing propagation. - client := eth.NewBeaconNodeValidatorClient(conns[0]) + client := validatorClientFactory.NewValidatorClient(conns[0]) if _, err = client.ProposeAttestation(ctx, att); err != nil { return errors.Wrap(err, "could not propose attestation") } @@ -196,7 +197,7 @@ func insertDoubleAttestationIntoPool(conns ...*grpc.ClientConn) error { func proposeDoubleBlock(conns ...*grpc.ClientConn) error { conn := conns[0] - valClient := eth.NewBeaconNodeValidatorClient(conn) + valClient := validatorClientFactory.NewValidatorClient(conn) beaconClient := eth.NewBeaconChainClient(conn) ctx := context.Background() @@ -238,7 +239,7 @@ func proposeDoubleBlock(conns ...*grpc.ClientConn) error { // If the proposer index is in the second validator client, we connect to // the corresponding beacon node instead. if proposerIndex >= types.ValidatorIndex(uint64(validatorsPerNode)) { - valClient = eth.NewBeaconNodeValidatorClient(conns[1]) + valClient = validatorClientFactory.NewValidatorClient(conns[1]) } hashLen := 32 diff --git a/testing/mock/BUILD.bazel b/testing/mock/BUILD.bazel index 32bcd1518..016581bcb 100644 --- a/testing/mock/BUILD.bazel +++ b/testing/mock/BUILD.bazel @@ -17,6 +17,7 @@ go_library( "keymanager_mock.go", "node_service_mock.go", "slasher_client_mock.go", + "validator_client_mock.go", ], importpath = "github.com/prysmaticlabs/prysm/v3/testing/mock", visibility = ["//visibility:public"], diff --git a/testing/mock/validator_client_mock.go b/testing/mock/validator_client_mock.go new file mode 100644 index 000000000..72d8308c7 --- /dev/null +++ b/testing/mock/validator_client_mock.go @@ -0,0 +1,427 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/prysmaticlabs/prysm/v3/validator/client/iface (interfaces: ValidatorClient) + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockValidatorClient is a mock of ValidatorClient interface. +type MockValidatorClient struct { + ctrl *gomock.Controller + recorder *MockValidatorClientMockRecorder +} + +// MockValidatorClientMockRecorder is the mock recorder for MockValidatorClient. +type MockValidatorClientMockRecorder struct { + mock *MockValidatorClient +} + +// NewMockValidatorClient creates a new mock instance. +func NewMockValidatorClient(ctrl *gomock.Controller) *MockValidatorClient { + mock := &MockValidatorClient{ctrl: ctrl} + mock.recorder = &MockValidatorClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockValidatorClient) EXPECT() *MockValidatorClientMockRecorder { + return m.recorder +} + +// CheckDoppelGanger mocks base method. +func (m *MockValidatorClient) CheckDoppelGanger(arg0 context.Context, arg1 *eth.DoppelGangerRequest) (*eth.DoppelGangerResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CheckDoppelGanger", arg0, arg1) + ret0, _ := ret[0].(*eth.DoppelGangerResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CheckDoppelGanger indicates an expected call of CheckDoppelGanger. +func (mr *MockValidatorClientMockRecorder) CheckDoppelGanger(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckDoppelGanger", reflect.TypeOf((*MockValidatorClient)(nil).CheckDoppelGanger), arg0, arg1) +} + +// DomainData mocks base method. +func (m *MockValidatorClient) DomainData(arg0 context.Context, arg1 *eth.DomainRequest) (*eth.DomainResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DomainData", arg0, arg1) + ret0, _ := ret[0].(*eth.DomainResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DomainData indicates an expected call of DomainData. +func (mr *MockValidatorClientMockRecorder) DomainData(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DomainData", reflect.TypeOf((*MockValidatorClient)(nil).DomainData), arg0, arg1) +} + +// GetAttestationData mocks base method. +func (m *MockValidatorClient) GetAttestationData(arg0 context.Context, arg1 *eth.AttestationDataRequest) (*eth.AttestationData, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAttestationData", arg0, arg1) + ret0, _ := ret[0].(*eth.AttestationData) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAttestationData indicates an expected call of GetAttestationData. +func (mr *MockValidatorClientMockRecorder) GetAttestationData(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAttestationData", reflect.TypeOf((*MockValidatorClient)(nil).GetAttestationData), arg0, arg1) +} + +// GetBeaconBlock mocks base method. +func (m *MockValidatorClient) GetBeaconBlock(arg0 context.Context, arg1 *eth.BlockRequest) (*eth.GenericBeaconBlock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBeaconBlock", arg0, arg1) + ret0, _ := ret[0].(*eth.GenericBeaconBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBeaconBlock indicates an expected call of GetBeaconBlock. +func (mr *MockValidatorClientMockRecorder) GetBeaconBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBeaconBlock", reflect.TypeOf((*MockValidatorClient)(nil).GetBeaconBlock), arg0, arg1) +} + +// GetDuties mocks base method. +func (m *MockValidatorClient) GetDuties(arg0 context.Context, arg1 *eth.DutiesRequest) (*eth.DutiesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDuties", arg0, arg1) + ret0, _ := ret[0].(*eth.DutiesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDuties indicates an expected call of GetDuties. +func (mr *MockValidatorClientMockRecorder) GetDuties(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDuties", reflect.TypeOf((*MockValidatorClient)(nil).GetDuties), arg0, arg1) +} + +// GetFeeRecipientByPubKey mocks base method. +func (m *MockValidatorClient) GetFeeRecipientByPubKey(arg0 context.Context, arg1 *eth.FeeRecipientByPubKeyRequest) (*eth.FeeRecipientByPubKeyResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFeeRecipientByPubKey", arg0, arg1) + ret0, _ := ret[0].(*eth.FeeRecipientByPubKeyResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFeeRecipientByPubKey indicates an expected call of GetFeeRecipientByPubKey. +func (mr *MockValidatorClientMockRecorder) GetFeeRecipientByPubKey(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeeRecipientByPubKey", reflect.TypeOf((*MockValidatorClient)(nil).GetFeeRecipientByPubKey), arg0, arg1) +} + +// GetSyncCommitteeContribution mocks base method. +func (m *MockValidatorClient) GetSyncCommitteeContribution(arg0 context.Context, arg1 *eth.SyncCommitteeContributionRequest) (*eth.SyncCommitteeContribution, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSyncCommitteeContribution", arg0, arg1) + ret0, _ := ret[0].(*eth.SyncCommitteeContribution) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSyncCommitteeContribution indicates an expected call of GetSyncCommitteeContribution. +func (mr *MockValidatorClientMockRecorder) GetSyncCommitteeContribution(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncCommitteeContribution", reflect.TypeOf((*MockValidatorClient)(nil).GetSyncCommitteeContribution), arg0, arg1) +} + +// GetSyncMessageBlockRoot mocks base method. +func (m *MockValidatorClient) GetSyncMessageBlockRoot(arg0 context.Context, arg1 *emptypb.Empty) (*eth.SyncMessageBlockRootResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSyncMessageBlockRoot", arg0, arg1) + ret0, _ := ret[0].(*eth.SyncMessageBlockRootResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSyncMessageBlockRoot indicates an expected call of GetSyncMessageBlockRoot. +func (mr *MockValidatorClientMockRecorder) GetSyncMessageBlockRoot(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncMessageBlockRoot", reflect.TypeOf((*MockValidatorClient)(nil).GetSyncMessageBlockRoot), arg0, arg1) +} + +// GetSyncSubcommitteeIndex mocks base method. +func (m *MockValidatorClient) GetSyncSubcommitteeIndex(arg0 context.Context, arg1 *eth.SyncSubcommitteeIndexRequest) (*eth.SyncSubcommitteeIndexResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSyncSubcommitteeIndex", arg0, arg1) + ret0, _ := ret[0].(*eth.SyncSubcommitteeIndexResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSyncSubcommitteeIndex indicates an expected call of GetSyncSubcommitteeIndex. +func (mr *MockValidatorClientMockRecorder) GetSyncSubcommitteeIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncSubcommitteeIndex", reflect.TypeOf((*MockValidatorClient)(nil).GetSyncSubcommitteeIndex), arg0, arg1) +} + +// MultipleValidatorStatus mocks base method. +func (m *MockValidatorClient) MultipleValidatorStatus(arg0 context.Context, arg1 *eth.MultipleValidatorStatusRequest) (*eth.MultipleValidatorStatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MultipleValidatorStatus", arg0, arg1) + ret0, _ := ret[0].(*eth.MultipleValidatorStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MultipleValidatorStatus indicates an expected call of MultipleValidatorStatus. +func (mr *MockValidatorClientMockRecorder) MultipleValidatorStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MultipleValidatorStatus", reflect.TypeOf((*MockValidatorClient)(nil).MultipleValidatorStatus), arg0, arg1) +} + +// PrepareBeaconProposer mocks base method. +func (m *MockValidatorClient) PrepareBeaconProposer(arg0 context.Context, arg1 *eth.PrepareBeaconProposerRequest) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareBeaconProposer", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PrepareBeaconProposer indicates an expected call of PrepareBeaconProposer. +func (mr *MockValidatorClientMockRecorder) PrepareBeaconProposer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareBeaconProposer", reflect.TypeOf((*MockValidatorClient)(nil).PrepareBeaconProposer), arg0, arg1) +} + +// ProposeAttestation mocks base method. +func (m *MockValidatorClient) ProposeAttestation(arg0 context.Context, arg1 *eth.Attestation) (*eth.AttestResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProposeAttestation", arg0, arg1) + ret0, _ := ret[0].(*eth.AttestResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProposeAttestation indicates an expected call of ProposeAttestation. +func (mr *MockValidatorClientMockRecorder) ProposeAttestation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProposeAttestation", reflect.TypeOf((*MockValidatorClient)(nil).ProposeAttestation), arg0, arg1) +} + +// ProposeBeaconBlock mocks base method. +func (m *MockValidatorClient) ProposeBeaconBlock(arg0 context.Context, arg1 *eth.GenericSignedBeaconBlock) (*eth.ProposeResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProposeBeaconBlock", arg0, arg1) + ret0, _ := ret[0].(*eth.ProposeResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProposeBeaconBlock indicates an expected call of ProposeBeaconBlock. +func (mr *MockValidatorClientMockRecorder) ProposeBeaconBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProposeBeaconBlock", reflect.TypeOf((*MockValidatorClient)(nil).ProposeBeaconBlock), arg0, arg1) +} + +// ProposeExit mocks base method. +func (m *MockValidatorClient) ProposeExit(arg0 context.Context, arg1 *eth.SignedVoluntaryExit) (*eth.ProposeExitResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProposeExit", arg0, arg1) + ret0, _ := ret[0].(*eth.ProposeExitResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProposeExit indicates an expected call of ProposeExit. +func (mr *MockValidatorClientMockRecorder) ProposeExit(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProposeExit", reflect.TypeOf((*MockValidatorClient)(nil).ProposeExit), arg0, arg1) +} + +// StreamBlocksAltair mocks base method. +func (m *MockValidatorClient) StreamBlocksAltair(arg0 context.Context, arg1 *eth.StreamBlocksRequest) (eth.BeaconNodeValidator_StreamBlocksAltairClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamBlocksAltair", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconNodeValidator_StreamBlocksAltairClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamBlocksAltair indicates an expected call of StreamBlocksAltair. +func (mr *MockValidatorClientMockRecorder) StreamBlocksAltair(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamBlocksAltair", reflect.TypeOf((*MockValidatorClient)(nil).StreamBlocksAltair), arg0, arg1) +} + +// StreamDuties mocks base method. +func (m *MockValidatorClient) StreamDuties(arg0 context.Context, arg1 *eth.DutiesRequest) (eth.BeaconNodeValidator_StreamDutiesClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamDuties", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconNodeValidator_StreamDutiesClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamDuties indicates an expected call of StreamDuties. +func (mr *MockValidatorClientMockRecorder) StreamDuties(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamDuties", reflect.TypeOf((*MockValidatorClient)(nil).StreamDuties), arg0, arg1) +} + +// SubmitAggregateSelectionProof mocks base method. +func (m *MockValidatorClient) SubmitAggregateSelectionProof(arg0 context.Context, arg1 *eth.AggregateSelectionRequest) (*eth.AggregateSelectionResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitAggregateSelectionProof", arg0, arg1) + ret0, _ := ret[0].(*eth.AggregateSelectionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitAggregateSelectionProof indicates an expected call of SubmitAggregateSelectionProof. +func (mr *MockValidatorClientMockRecorder) SubmitAggregateSelectionProof(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitAggregateSelectionProof", reflect.TypeOf((*MockValidatorClient)(nil).SubmitAggregateSelectionProof), arg0, arg1) +} + +// SubmitSignedAggregateSelectionProof mocks base method. +func (m *MockValidatorClient) SubmitSignedAggregateSelectionProof(arg0 context.Context, arg1 *eth.SignedAggregateSubmitRequest) (*eth.SignedAggregateSubmitResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitSignedAggregateSelectionProof", arg0, arg1) + ret0, _ := ret[0].(*eth.SignedAggregateSubmitResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitSignedAggregateSelectionProof indicates an expected call of SubmitSignedAggregateSelectionProof. +func (mr *MockValidatorClientMockRecorder) SubmitSignedAggregateSelectionProof(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitSignedAggregateSelectionProof", reflect.TypeOf((*MockValidatorClient)(nil).SubmitSignedAggregateSelectionProof), arg0, arg1) +} + +// SubmitSignedContributionAndProof mocks base method. +func (m *MockValidatorClient) SubmitSignedContributionAndProof(arg0 context.Context, arg1 *eth.SignedContributionAndProof) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitSignedContributionAndProof", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitSignedContributionAndProof indicates an expected call of SubmitSignedContributionAndProof. +func (mr *MockValidatorClientMockRecorder) SubmitSignedContributionAndProof(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitSignedContributionAndProof", reflect.TypeOf((*MockValidatorClient)(nil).SubmitSignedContributionAndProof), arg0, arg1) +} + +// SubmitSyncMessage mocks base method. +func (m *MockValidatorClient) SubmitSyncMessage(arg0 context.Context, arg1 *eth.SyncCommitteeMessage) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitSyncMessage", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitSyncMessage indicates an expected call of SubmitSyncMessage. +func (mr *MockValidatorClientMockRecorder) SubmitSyncMessage(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitSyncMessage", reflect.TypeOf((*MockValidatorClient)(nil).SubmitSyncMessage), arg0, arg1) +} + +// SubmitValidatorRegistrations mocks base method. +func (m *MockValidatorClient) SubmitValidatorRegistrations(arg0 context.Context, arg1 *eth.SignedValidatorRegistrationsV1) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitValidatorRegistrations", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitValidatorRegistrations indicates an expected call of SubmitValidatorRegistrations. +func (mr *MockValidatorClientMockRecorder) SubmitValidatorRegistrations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitValidatorRegistrations", reflect.TypeOf((*MockValidatorClient)(nil).SubmitValidatorRegistrations), arg0, arg1) +} + +// SubscribeCommitteeSubnets mocks base method. +func (m *MockValidatorClient) SubscribeCommitteeSubnets(arg0 context.Context, arg1 *eth.CommitteeSubnetsSubscribeRequest) (*emptypb.Empty, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeCommitteeSubnets", arg0, arg1) + ret0, _ := ret[0].(*emptypb.Empty) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubscribeCommitteeSubnets indicates an expected call of SubscribeCommitteeSubnets. +func (mr *MockValidatorClientMockRecorder) SubscribeCommitteeSubnets(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeCommitteeSubnets", reflect.TypeOf((*MockValidatorClient)(nil).SubscribeCommitteeSubnets), arg0, arg1) +} + +// ValidatorIndex mocks base method. +func (m *MockValidatorClient) ValidatorIndex(arg0 context.Context, arg1 *eth.ValidatorIndexRequest) (*eth.ValidatorIndexResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidatorIndex", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorIndexResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidatorIndex indicates an expected call of ValidatorIndex. +func (mr *MockValidatorClientMockRecorder) ValidatorIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorIndex", reflect.TypeOf((*MockValidatorClient)(nil).ValidatorIndex), arg0, arg1) +} + +// ValidatorStatus mocks base method. +func (m *MockValidatorClient) ValidatorStatus(arg0 context.Context, arg1 *eth.ValidatorStatusRequest) (*eth.ValidatorStatusResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidatorStatus", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorStatusResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidatorStatus indicates an expected call of ValidatorStatus. +func (mr *MockValidatorClientMockRecorder) ValidatorStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorStatus", reflect.TypeOf((*MockValidatorClient)(nil).ValidatorStatus), arg0, arg1) +} + +// WaitForActivation mocks base method. +func (m *MockValidatorClient) WaitForActivation(arg0 context.Context, arg1 *eth.ValidatorActivationRequest) (eth.BeaconNodeValidator_WaitForActivationClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WaitForActivation", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconNodeValidator_WaitForActivationClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// WaitForActivation indicates an expected call of WaitForActivation. +func (mr *MockValidatorClientMockRecorder) WaitForActivation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForActivation", reflect.TypeOf((*MockValidatorClient)(nil).WaitForActivation), arg0, arg1) +} + +// WaitForChainStart mocks base method. +func (m *MockValidatorClient) WaitForChainStart(arg0 context.Context, arg1 *emptypb.Empty) (eth.BeaconNodeValidator_WaitForChainStartClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WaitForChainStart", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconNodeValidator_WaitForChainStartClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// WaitForChainStart indicates an expected call of WaitForChainStart. +func (mr *MockValidatorClientMockRecorder) WaitForChainStart(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForChainStart", reflect.TypeOf((*MockValidatorClient)(nil).WaitForChainStart), arg0, arg1) +} diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index 9416450fc..19bcc1c96 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -41,6 +41,8 @@ go_library( "//validator/accounts/userprompt:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client:go_default_library", + "//validator/client/iface:go_default_library", + "//validator/client/validator-client-factory:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/local:go_default_library", diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index d3f0243bf..b36d1cbf2 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -14,13 +14,14 @@ import ( "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/validator/client" + "github.com/prysmaticlabs/prysm/v3/validator/client/iface" "github.com/prysmaticlabs/prysm/v3/validator/keymanager" "google.golang.org/protobuf/types/known/emptypb" ) // PerformExitCfg for account voluntary exits. type PerformExitCfg struct { - ValidatorClient ethpb.BeaconNodeValidatorClient + ValidatorClient iface.ValidatorClient NodeClient ethpb.NodeClient Keymanager keymanager.IKeymanager RawPubKeys [][]byte diff --git a/validator/accounts/accounts_list.go b/validator/accounts/accounts_list.go index 2c6b921fd..cb3839b70 100644 --- a/validator/accounts/accounts_list.go +++ b/validator/accounts/accounts_list.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet" + "github.com/prysmaticlabs/prysm/v3/validator/client/iface" "github.com/prysmaticlabs/prysm/v3/validator/keymanager" ) @@ -29,7 +30,7 @@ func (acm *AccountsCLIManager) List(ctx context.Context) error { }) } -func listValidatorIndices(ctx context.Context, km keymanager.IKeymanager, client ethpb.BeaconNodeValidatorClient) error { +func listValidatorIndices(ctx context.Context, km keymanager.IKeymanager, client iface.ValidatorClient) error { pubKeys, err := km.FetchValidatingPublicKeys(ctx) if err != nil { return errors.Wrap(err, "could not get validating public keys") diff --git a/validator/accounts/accounts_list_test.go b/validator/accounts/accounts_list_test.go index 7a5bc4ea6..c6fff5a94 100644 --- a/validator/accounts/accounts_list_test.go +++ b/validator/accounts/accounts_list_test.go @@ -608,7 +608,7 @@ func TestListAccounts_ListValidatorIndices(t *testing.T) { require.NoError(t, err) os.Stdout = writer - m := mock.NewMockBeaconNodeValidatorClient(ctrl) + m := mock.NewMockValidatorClient(ctrl) req := ðpb.MultipleValidatorStatusRequest{PublicKeys: pks} resp := ðpb.MultipleValidatorStatusResponse{Indices: []types.ValidatorIndex{1, math.MaxUint64, 2}} diff --git a/validator/accounts/cli_manager.go b/validator/accounts/cli_manager.go index ae603efaf..394984ff2 100644 --- a/validator/accounts/cli_manager.go +++ b/validator/accounts/cli_manager.go @@ -8,6 +8,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet" + iface "github.com/prysmaticlabs/prysm/v3/validator/client/iface" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "github.com/prysmaticlabs/prysm/v3/validator/keymanager" "github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote" "google.golang.org/grpc" @@ -58,7 +60,7 @@ type AccountsCLIManager struct { mnemonic25thWord string } -func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*ethpb.BeaconNodeValidatorClient, *ethpb.NodeClient, error) { +func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface.ValidatorClient, *ethpb.NodeClient, error) { if acm.dialOpts == nil { return nil, nil, errors.New("failed to construct dial options for beacon clients") } @@ -68,7 +70,7 @@ func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*ethpb if err != nil { return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider) } - validatorClient := ethpb.NewBeaconNodeValidatorClient(conn) + validatorClient := validatorClientFactory.NewValidatorClient(conn) nodeClient := ethpb.NewNodeClient(conn) return &validatorClient, &nodeClient, nil } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 0ec6646d7..783fd72f9 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -55,6 +55,7 @@ go_library( "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client/iface:go_default_library", + "//validator/client/validator-client-factory:go_default_library", "//validator/db:go_default_library", "//validator/db/kv:go_default_library", "//validator/graffiti:go_default_library", @@ -162,7 +163,6 @@ go_test( "@in_gopkg_d4l3k_messagediff_v1//:go_default_library", "@io_bazel_rules_go//go/tools/bazel:go_default_library", "@io_bazel_rules_go//proto/wkt:empty_go_proto", - "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//metadata:go_default_library", "@org_golang_google_protobuf//types/known/emptypb:go_default_library", "@org_golang_google_protobuf//types/known/timestamppb:go_default_library", diff --git a/validator/client/attest_test.go b/validator/client/attest_test.go index d29ea0d4c..97d0b09f0 100644 --- a/validator/client/attest_test.go +++ b/validator/client/attest_test.go @@ -27,7 +27,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/util" prysmTime "github.com/prysmaticlabs/prysm/v3/time" logTest "github.com/sirupsen/logrus/hooks/test" - "google.golang.org/grpc" "gopkg.in/d4l3k/messagediff.v1" ) @@ -134,7 +133,7 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) { m.validatorClient.EXPECT().ProposeAttestation( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.Attestation{}), - ).Do(func(_ context.Context, att *ethpb.Attestation, opts ...grpc.CallOption) { + ).Do(func(_ context.Context, att *ethpb.Attestation) { generatedAttestation = att }).Return(ðpb.AttestResponse{}, nil /* error */) @@ -338,7 +337,6 @@ func TestAttestToBlockHead_DoesNotAttestBeforeDelay(t *testing.T) { m.validatorClient.EXPECT().GetDuties( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.DutiesRequest{}), - gomock.Any(), ).Times(0) m.validatorClient.EXPECT().GetAttestationData( @@ -384,7 +382,7 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) { BeaconBlockRoot: bytesutil.PadTo([]byte("A"), 32), Target: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("B"), 32)}, Source: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte("C"), 32), Epoch: 3}, - }, nil).Do(func(arg0, arg1 interface{}, arg2 ...grpc.CallOption) { + }, nil).Do(func(arg0, arg1 interface{}) { wg.Done() }) @@ -433,7 +431,7 @@ func TestAttestToBlockHead_CorrectBitfieldLength(t *testing.T) { m.validatorClient.EXPECT().ProposeAttestation( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.Attestation{}), - ).Do(func(_ context.Context, att *ethpb.Attestation, arg2 ...grpc.CallOption) { + ).Do(func(_ context.Context, att *ethpb.Attestation) { generatedAttestation = att }).Return(ðpb.AttestResponse{}, nil /* error */) diff --git a/validator/client/beacon-api/BUILD.bazel b/validator/client/beacon-api/BUILD.bazel new file mode 100644 index 000000000..b5f2c9179 --- /dev/null +++ b/validator/client/beacon-api/BUILD.bazel @@ -0,0 +1,15 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +# Gazelle will flag this for removal since it's only being used with the use_beacon_api flag, but it should be kept +# keep +go_library( + name = "go_default_library", + srcs = ["beacon_api_validator_client.go"], + importpath = "github.com/prysmaticlabs/prysm/v3/validator/client/beacon-api", + visibility = ["//validator:__subpackages__"], + deps = [ + "//proto/prysm/v1alpha1:go_default_library", + "//validator/client/iface:go_default_library", + "@io_bazel_rules_go//proto/wkt:empty_go_proto", + ], +) diff --git a/validator/client/beacon-api/beacon_api_validator_client.go b/validator/client/beacon-api/beacon_api_validator_client.go new file mode 100644 index 000000000..11db53fe1 --- /dev/null +++ b/validator/client/beacon-api/beacon_api_validator_client.go @@ -0,0 +1,150 @@ +//go:build use_beacon_api +// +build use_beacon_api + +package beacon_api + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + iface "github.com/prysmaticlabs/prysm/v3/validator/client/iface" +) + +type beaconApiValidatorClient struct { +} + +func (*beaconApiValidatorClient) GetDuties(_ context.Context, _ *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetDuties is not implemented") +} + +func (*beaconApiValidatorClient) CheckDoppelGanger(_ context.Context, _ *ethpb.DoppelGangerRequest) (*ethpb.DoppelGangerResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.CheckDoppelGanger is not implemented") +} + +func (*beaconApiValidatorClient) DomainData(_ context.Context, _ *ethpb.DomainRequest) (*ethpb.DomainResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.DomainData is not implemented") +} + +func (*beaconApiValidatorClient) GetAttestationData(_ context.Context, _ *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetAttestationData is not implemented") +} + +func (*beaconApiValidatorClient) GetBeaconBlock(_ context.Context, _ *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetBeaconBlock is not implemented") +} + +func (*beaconApiValidatorClient) GetFeeRecipientByPubKey(_ context.Context, _ *ethpb.FeeRecipientByPubKeyRequest) (*ethpb.FeeRecipientByPubKeyResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetFeeRecipientByPubKey is not implemented") +} + +func (*beaconApiValidatorClient) GetSyncCommitteeContribution(_ context.Context, _ *ethpb.SyncCommitteeContributionRequest) (*ethpb.SyncCommitteeContribution, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetSyncCommitteeContribution is not implemented") +} + +func (*beaconApiValidatorClient) GetSyncMessageBlockRoot(_ context.Context, _ *empty.Empty) (*ethpb.SyncMessageBlockRootResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetSyncMessageBlockRoot is not implemented") +} + +func (*beaconApiValidatorClient) GetSyncSubcommitteeIndex(_ context.Context, _ *ethpb.SyncSubcommitteeIndexRequest) (*ethpb.SyncSubcommitteeIndexResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.GetSyncSubcommitteeIndex is not implemented") +} + +func (*beaconApiValidatorClient) MultipleValidatorStatus(_ context.Context, _ *ethpb.MultipleValidatorStatusRequest) (*ethpb.MultipleValidatorStatusResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.MultipleValidatorStatus is not implemented") +} + +func (*beaconApiValidatorClient) PrepareBeaconProposer(_ context.Context, _ *ethpb.PrepareBeaconProposerRequest) (*empty.Empty, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.PrepareBeaconProposer is not implemented") +} + +func (*beaconApiValidatorClient) ProposeAttestation(_ context.Context, _ *ethpb.Attestation) (*ethpb.AttestResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.ProposeAttestation is not implemented") +} + +func (*beaconApiValidatorClient) ProposeBeaconBlock(_ context.Context, _ *ethpb.GenericSignedBeaconBlock) (*ethpb.ProposeResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.ProposeBeaconBlock is not implemented") +} + +func (*beaconApiValidatorClient) ProposeExit(_ context.Context, _ *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.ProposeExit is not implemented") +} + +func (*beaconApiValidatorClient) StreamBlocksAltair(_ context.Context, _ *ethpb.StreamBlocksRequest) (ethpb.BeaconNodeValidator_StreamBlocksAltairClient, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.StreamBlocksAltair is not implemented") +} + +func (*beaconApiValidatorClient) StreamDuties(_ context.Context, _ *ethpb.DutiesRequest) (ethpb.BeaconNodeValidator_StreamDutiesClient, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.StreamDuties is not implemented") +} + +func (*beaconApiValidatorClient) SubmitAggregateSelectionProof(_ context.Context, _ *ethpb.AggregateSelectionRequest) (*ethpb.AggregateSelectionResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubmitAggregateSelectionProof is not implemented") +} + +func (*beaconApiValidatorClient) SubmitSignedAggregateSelectionProof(_ context.Context, _ *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubmitSignedAggregateSelectionProof is not implemented") +} + +func (*beaconApiValidatorClient) SubmitSignedContributionAndProof(_ context.Context, _ *ethpb.SignedContributionAndProof) (*empty.Empty, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubmitSignedContributionAndProof is not implemented") +} + +func (*beaconApiValidatorClient) SubmitSyncMessage(_ context.Context, _ *ethpb.SyncCommitteeMessage) (*empty.Empty, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubmitSyncMessage is not implemented") +} + +func (*beaconApiValidatorClient) SubmitValidatorRegistrations(_ context.Context, _ *ethpb.SignedValidatorRegistrationsV1) (*empty.Empty, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubmitValidatorRegistrations is not implemented") +} + +func (*beaconApiValidatorClient) SubscribeCommitteeSubnets(_ context.Context, _ *ethpb.CommitteeSubnetsSubscribeRequest) (*empty.Empty, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.SubscribeCommitteeSubnets is not implemented") +} + +func (*beaconApiValidatorClient) ValidatorIndex(_ context.Context, _ *ethpb.ValidatorIndexRequest) (*ethpb.ValidatorIndexResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.ValidatorIndex is not implemented") +} + +func (*beaconApiValidatorClient) ValidatorStatus(_ context.Context, _ *ethpb.ValidatorStatusRequest) (*ethpb.ValidatorStatusResponse, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.ValidatorStatus is not implemented") +} + +func (*beaconApiValidatorClient) WaitForActivation(_ context.Context, _ *ethpb.ValidatorActivationRequest) (ethpb.BeaconNodeValidator_WaitForActivationClient, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.WaitForActivation is not implemented") +} + +// Deprecated: Do not use. +func (*beaconApiValidatorClient) WaitForChainStart(_ context.Context, _ *empty.Empty) (ethpb.BeaconNodeValidator_WaitForChainStartClient, error) { + // TODO: Implement me + panic("beaconApiValidatorClient.WaitForChainStart is not implemented") +} + +func NewBeaconApiValidatorClient() iface.ValidatorClient { + return &beaconApiValidatorClient{} +} diff --git a/validator/client/grpc-api/BUILD.bazel b/validator/client/grpc-api/BUILD.bazel new file mode 100644 index 000000000..06ad584ea --- /dev/null +++ b/validator/client/grpc-api/BUILD.bazel @@ -0,0 +1,14 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["grpc_validator_client.go"], + importpath = "github.com/prysmaticlabs/prysm/v3/validator/client/grpc-api", + visibility = ["//validator:__subpackages__"], + deps = [ + "//proto/prysm/v1alpha1:go_default_library", + "//validator/client/iface:go_default_library", + "@io_bazel_rules_go//proto/wkt:empty_go_proto", + "@org_golang_google_grpc//:go_default_library", + ], +) diff --git a/validator/client/grpc-api/grpc_validator_client.go b/validator/client/grpc-api/grpc_validator_client.go new file mode 100644 index 000000000..0099dbc4c --- /dev/null +++ b/validator/client/grpc-api/grpc_validator_client.go @@ -0,0 +1,126 @@ +//go:build !use_beacon_api +// +build !use_beacon_api + +package grpc_api + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + iface "github.com/prysmaticlabs/prysm/v3/validator/client/iface" + "google.golang.org/grpc" +) + +type grpcValidatorClient struct { + beaconNodeValidatorClient ethpb.BeaconNodeValidatorClient +} + +func (c *grpcValidatorClient) GetDuties(ctx context.Context, in *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) { + return c.beaconNodeValidatorClient.GetDuties(ctx, in) +} + +func (c *grpcValidatorClient) CheckDoppelGanger(ctx context.Context, in *ethpb.DoppelGangerRequest) (*ethpb.DoppelGangerResponse, error) { + return c.beaconNodeValidatorClient.CheckDoppelGanger(ctx, in) +} + +func (c *grpcValidatorClient) DomainData(ctx context.Context, in *ethpb.DomainRequest) (*ethpb.DomainResponse, error) { + return c.beaconNodeValidatorClient.DomainData(ctx, in) +} + +func (c *grpcValidatorClient) GetAttestationData(ctx context.Context, in *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error) { + return c.beaconNodeValidatorClient.GetAttestationData(ctx, in) +} + +func (c *grpcValidatorClient) GetBeaconBlock(ctx context.Context, in *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) { + return c.beaconNodeValidatorClient.GetBeaconBlock(ctx, in) +} + +func (c *grpcValidatorClient) GetFeeRecipientByPubKey(ctx context.Context, in *ethpb.FeeRecipientByPubKeyRequest) (*ethpb.FeeRecipientByPubKeyResponse, error) { + return c.beaconNodeValidatorClient.GetFeeRecipientByPubKey(ctx, in) +} + +func (c *grpcValidatorClient) GetSyncCommitteeContribution(ctx context.Context, in *ethpb.SyncCommitteeContributionRequest) (*ethpb.SyncCommitteeContribution, error) { + return c.beaconNodeValidatorClient.GetSyncCommitteeContribution(ctx, in) +} + +func (c *grpcValidatorClient) GetSyncMessageBlockRoot(ctx context.Context, in *empty.Empty) (*ethpb.SyncMessageBlockRootResponse, error) { + return c.beaconNodeValidatorClient.GetSyncMessageBlockRoot(ctx, in) +} + +func (c *grpcValidatorClient) GetSyncSubcommitteeIndex(ctx context.Context, in *ethpb.SyncSubcommitteeIndexRequest) (*ethpb.SyncSubcommitteeIndexResponse, error) { + return c.beaconNodeValidatorClient.GetSyncSubcommitteeIndex(ctx, in) +} + +func (c *grpcValidatorClient) MultipleValidatorStatus(ctx context.Context, in *ethpb.MultipleValidatorStatusRequest) (*ethpb.MultipleValidatorStatusResponse, error) { + return c.beaconNodeValidatorClient.MultipleValidatorStatus(ctx, in) +} + +func (c *grpcValidatorClient) PrepareBeaconProposer(ctx context.Context, in *ethpb.PrepareBeaconProposerRequest) (*empty.Empty, error) { + return c.beaconNodeValidatorClient.PrepareBeaconProposer(ctx, in) +} + +func (c *grpcValidatorClient) ProposeAttestation(ctx context.Context, in *ethpb.Attestation) (*ethpb.AttestResponse, error) { + return c.beaconNodeValidatorClient.ProposeAttestation(ctx, in) +} + +func (c *grpcValidatorClient) ProposeBeaconBlock(ctx context.Context, in *ethpb.GenericSignedBeaconBlock) (*ethpb.ProposeResponse, error) { + return c.beaconNodeValidatorClient.ProposeBeaconBlock(ctx, in) +} + +func (c *grpcValidatorClient) ProposeExit(ctx context.Context, in *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) { + return c.beaconNodeValidatorClient.ProposeExit(ctx, in) +} + +func (c *grpcValidatorClient) StreamBlocksAltair(ctx context.Context, in *ethpb.StreamBlocksRequest) (ethpb.BeaconNodeValidator_StreamBlocksAltairClient, error) { + return c.beaconNodeValidatorClient.StreamBlocksAltair(ctx, in) +} + +func (c *grpcValidatorClient) StreamDuties(ctx context.Context, in *ethpb.DutiesRequest) (ethpb.BeaconNodeValidator_StreamDutiesClient, error) { + return c.beaconNodeValidatorClient.StreamDuties(ctx, in) +} + +func (c *grpcValidatorClient) SubmitAggregateSelectionProof(ctx context.Context, in *ethpb.AggregateSelectionRequest) (*ethpb.AggregateSelectionResponse, error) { + return c.beaconNodeValidatorClient.SubmitAggregateSelectionProof(ctx, in) +} + +func (c *grpcValidatorClient) SubmitSignedAggregateSelectionProof(ctx context.Context, in *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) { + return c.beaconNodeValidatorClient.SubmitSignedAggregateSelectionProof(ctx, in) +} + +func (c *grpcValidatorClient) SubmitSignedContributionAndProof(ctx context.Context, in *ethpb.SignedContributionAndProof) (*empty.Empty, error) { + return c.beaconNodeValidatorClient.SubmitSignedContributionAndProof(ctx, in) +} + +func (c *grpcValidatorClient) SubmitSyncMessage(ctx context.Context, in *ethpb.SyncCommitteeMessage) (*empty.Empty, error) { + return c.beaconNodeValidatorClient.SubmitSyncMessage(ctx, in) +} + +func (c *grpcValidatorClient) SubmitValidatorRegistrations(ctx context.Context, in *ethpb.SignedValidatorRegistrationsV1) (*empty.Empty, error) { + return c.beaconNodeValidatorClient.SubmitValidatorRegistrations(ctx, in) +} + +func (c *grpcValidatorClient) SubscribeCommitteeSubnets(ctx context.Context, in *ethpb.CommitteeSubnetsSubscribeRequest) (*empty.Empty, error) { + return c.beaconNodeValidatorClient.SubscribeCommitteeSubnets(ctx, in) +} + +func (c *grpcValidatorClient) ValidatorIndex(ctx context.Context, in *ethpb.ValidatorIndexRequest) (*ethpb.ValidatorIndexResponse, error) { + return c.beaconNodeValidatorClient.ValidatorIndex(ctx, in) +} + +func (c *grpcValidatorClient) ValidatorStatus(ctx context.Context, in *ethpb.ValidatorStatusRequest) (*ethpb.ValidatorStatusResponse, error) { + return c.beaconNodeValidatorClient.ValidatorStatus(ctx, in) +} + +func (c *grpcValidatorClient) WaitForActivation(ctx context.Context, in *ethpb.ValidatorActivationRequest) (ethpb.BeaconNodeValidator_WaitForActivationClient, error) { + return c.beaconNodeValidatorClient.WaitForActivation(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcValidatorClient) WaitForChainStart(ctx context.Context, in *empty.Empty) (ethpb.BeaconNodeValidator_WaitForChainStartClient, error) { + return c.beaconNodeValidatorClient.WaitForChainStart(ctx, in) +} + +func NewGrpcValidatorClient(cc grpc.ClientConnInterface) iface.ValidatorClient { + return &grpcValidatorClient{ethpb.NewBeaconNodeValidatorClient(cc)} +} diff --git a/validator/client/iface/BUILD.bazel b/validator/client/iface/BUILD.bazel index fdaee49fc..f37b6bb6c 100644 --- a/validator/client/iface/BUILD.bazel +++ b/validator/client/iface/BUILD.bazel @@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", - srcs = ["validator.go"], + srcs = [ + "validator.go", + "validator_client.go", + ], importpath = "github.com/prysmaticlabs/prysm/v3/validator/client/iface", visibility = ["//validator:__subpackages__"], deps = [ @@ -13,5 +16,6 @@ go_library( "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//validator/keymanager:go_default_library", + "@io_bazel_rules_go//proto/wkt:empty_go_proto", ], ) diff --git a/validator/client/iface/validator_client.go b/validator/client/iface/validator_client.go new file mode 100644 index 000000000..b8b3f9b50 --- /dev/null +++ b/validator/client/iface/validator_client.go @@ -0,0 +1,37 @@ +package iface + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" +) + +type ValidatorClient interface { + GetDuties(ctx context.Context, in *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) + StreamDuties(ctx context.Context, in *ethpb.DutiesRequest) (ethpb.BeaconNodeValidator_StreamDutiesClient, error) + DomainData(ctx context.Context, in *ethpb.DomainRequest) (*ethpb.DomainResponse, error) + WaitForChainStart(ctx context.Context, in *empty.Empty) (ethpb.BeaconNodeValidator_WaitForChainStartClient, error) + WaitForActivation(ctx context.Context, in *ethpb.ValidatorActivationRequest) (ethpb.BeaconNodeValidator_WaitForActivationClient, error) + ValidatorIndex(ctx context.Context, in *ethpb.ValidatorIndexRequest) (*ethpb.ValidatorIndexResponse, error) + ValidatorStatus(ctx context.Context, in *ethpb.ValidatorStatusRequest) (*ethpb.ValidatorStatusResponse, error) + MultipleValidatorStatus(ctx context.Context, in *ethpb.MultipleValidatorStatusRequest) (*ethpb.MultipleValidatorStatusResponse, error) + GetBeaconBlock(ctx context.Context, in *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) + ProposeBeaconBlock(ctx context.Context, in *ethpb.GenericSignedBeaconBlock) (*ethpb.ProposeResponse, error) + PrepareBeaconProposer(ctx context.Context, in *ethpb.PrepareBeaconProposerRequest) (*empty.Empty, error) + GetFeeRecipientByPubKey(ctx context.Context, in *ethpb.FeeRecipientByPubKeyRequest) (*ethpb.FeeRecipientByPubKeyResponse, error) + GetAttestationData(ctx context.Context, in *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error) + ProposeAttestation(ctx context.Context, in *ethpb.Attestation) (*ethpb.AttestResponse, error) + SubmitAggregateSelectionProof(ctx context.Context, in *ethpb.AggregateSelectionRequest) (*ethpb.AggregateSelectionResponse, error) + SubmitSignedAggregateSelectionProof(ctx context.Context, in *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) + ProposeExit(ctx context.Context, in *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) + SubscribeCommitteeSubnets(ctx context.Context, in *ethpb.CommitteeSubnetsSubscribeRequest) (*empty.Empty, error) + CheckDoppelGanger(ctx context.Context, in *ethpb.DoppelGangerRequest) (*ethpb.DoppelGangerResponse, error) + GetSyncMessageBlockRoot(ctx context.Context, in *empty.Empty) (*ethpb.SyncMessageBlockRootResponse, error) + SubmitSyncMessage(ctx context.Context, in *ethpb.SyncCommitteeMessage) (*empty.Empty, error) + GetSyncSubcommitteeIndex(ctx context.Context, in *ethpb.SyncSubcommitteeIndexRequest) (*ethpb.SyncSubcommitteeIndexResponse, error) + GetSyncCommitteeContribution(ctx context.Context, in *ethpb.SyncCommitteeContributionRequest) (*ethpb.SyncCommitteeContribution, error) + SubmitSignedContributionAndProof(ctx context.Context, in *ethpb.SignedContributionAndProof) (*empty.Empty, error) + StreamBlocksAltair(ctx context.Context, in *ethpb.StreamBlocksRequest) (ethpb.BeaconNodeValidator_StreamBlocksAltairClient, error) + SubmitValidatorRegistrations(ctx context.Context, in *ethpb.SignedValidatorRegistrationsV1) (*empty.Empty, error) +} diff --git a/validator/client/key_reload_test.go b/validator/client/key_reload_test.go index 6b5e61cf0..3e9a54b4e 100644 --- a/validator/client/key_reload_test.go +++ b/validator/client/key_reload_test.go @@ -36,7 +36,7 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockBeaconNodeValidatorClient(ctrl) + client := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: client, @@ -75,7 +75,7 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockBeaconNodeValidatorClient(ctrl) + client := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: client, @@ -111,7 +111,7 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockBeaconNodeValidatorClient(ctrl) + client := mock.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, keyManager: km, diff --git a/validator/client/propose.go b/validator/client/propose.go index 96d516a36..8add4b69d 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -189,7 +189,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f // The exit is signed by the validator before being sent to the beacon node for broadcasting. func ProposeExit( ctx context.Context, - validatorClient ethpb.BeaconNodeValidatorClient, + validatorClient iface.ValidatorClient, nodeClient ethpb.NodeClient, signer iface.SigningFunc, pubKey []byte, @@ -291,7 +291,7 @@ func (v *validator) signBlock(ctx context.Context, pubKey [fieldparams.BLSPubkey // Sign voluntary exit with proposer domain and private key. func signVoluntaryExit( ctx context.Context, - validatorClient ethpb.BeaconNodeValidatorClient, + validatorClient iface.ValidatorClient, signer iface.SigningFunc, pubKey []byte, exit *ethpb.VoluntaryExit, diff --git a/validator/client/propose_test.go b/validator/client/propose_test.go index 2c0928ea5..03d0a8964 100644 --- a/validator/client/propose_test.go +++ b/validator/client/propose_test.go @@ -28,12 +28,11 @@ import ( testing2 "github.com/prysmaticlabs/prysm/v3/validator/db/testing" "github.com/prysmaticlabs/prysm/v3/validator/graffiti" logTest "github.com/sirupsen/logrus/hooks/test" - "google.golang.org/grpc" "google.golang.org/protobuf/types/known/timestamppb" ) type mocks struct { - validatorClient *mock.MockBeaconNodeValidatorClient + validatorClient *mock.MockValidatorClient nodeClient *mock.MockNodeClient slasherClient *mock.MockSlasherClient signfunc func(context.Context, *validatorpb.SignRequest) (bls.Signature, error) @@ -72,7 +71,7 @@ func setupWithKey(t *testing.T, validatorKey bls.SecretKey) (*validator, *mocks, valDB := testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}) ctrl := gomock.NewController(t) m := &mocks{ - validatorClient: mock.NewMockBeaconNodeValidatorClient(ctrl), + validatorClient: mock.NewMockValidatorClient(ctrl), nodeClient: mock.NewMockNodeClient(ctrl), slasherClient: mock.NewMockSlasherClient(ctrl), signfunc: func(ctx context.Context, req *validatorpb.SignRequest) (bls.Signature, error) { @@ -582,7 +581,7 @@ func testProposeBlock(t *testing.T, graffiti []byte) { m.validatorClient.EXPECT().GetBeaconBlock( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.BlockRequest{}), - ).DoAndReturn(func(ctx context.Context, req *ethpb.BlockRequest, arg2 ...grpc.CallOption) (*ethpb.GenericBeaconBlock, error) { + ).DoAndReturn(func(ctx context.Context, req *ethpb.BlockRequest) (*ethpb.GenericBeaconBlock, error) { assert.DeepEqual(t, graffiti, req.Graffiti, "Unexpected graffiti in request") return tt.block, nil @@ -599,7 +598,7 @@ func testProposeBlock(t *testing.T, graffiti []byte) { m.validatorClient.EXPECT().ProposeBeaconBlock( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.GenericSignedBeaconBlock{}), - ).DoAndReturn(func(ctx context.Context, block *ethpb.GenericSignedBeaconBlock, opts ...grpc.CallOption) (*ethpb.ProposeResponse, error) { + ).DoAndReturn(func(ctx context.Context, block *ethpb.GenericSignedBeaconBlock) (*ethpb.ProposeResponse, error) { sentBlock, err = blocktest.NewSignedBeaconBlockFromGeneric(block) assert.NoError(t, err, "Unexpected error unwrapping block") return ðpb.ProposeResponse{BlockRoot: make([]byte, 32)}, nil @@ -912,7 +911,7 @@ func TestSignBellatrixBlock(t *testing.T) { func TestGetGraffiti_Ok(t *testing.T) { ctrl := gomock.NewController(t) m := &mocks{ - validatorClient: mock.NewMockBeaconNodeValidatorClient(ctrl), + validatorClient: mock.NewMockValidatorClient(ctrl), } pubKey := [fieldparams.BLSPubkeyLength]byte{'a'} tests := []struct { @@ -995,7 +994,7 @@ func TestGetGraffitiOrdered_Ok(t *testing.T) { valDB := testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}) ctrl := gomock.NewController(t) m := &mocks{ - validatorClient: mock.NewMockBeaconNodeValidatorClient(ctrl), + validatorClient: mock.NewMockValidatorClient(ctrl), } m.validatorClient.EXPECT(). ValidatorIndex(gomock.Any(), ðpb.ValidatorIndexRequest{PublicKey: pubKey[:]}). diff --git a/validator/client/registration.go b/validator/client/registration.go index 4e5fe686e..14e74b3be 100644 --- a/validator/client/registration.go +++ b/validator/client/registration.go @@ -19,7 +19,7 @@ import ( // SubmitValidatorRegistrations signs validator registration objects and submits it to the beacon node. func SubmitValidatorRegistrations( ctx context.Context, - validatorClient ethpb.BeaconNodeValidatorClient, + validatorClient iface.ValidatorClient, signedRegs []*ethpb.SignedValidatorRegistrationV1, ) error { ctx, span := trace.StartSpan(ctx, "validator.SubmitValidatorRegistrations") diff --git a/validator/client/service.go b/validator/client/service.go index c1483ef3c..0e6b3db17 100644 --- a/validator/client/service.go +++ b/validator/client/service.go @@ -22,6 +22,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/v3/validator/client/iface" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "github.com/prysmaticlabs/prysm/v3/validator/db" "github.com/prysmaticlabs/prysm/v3/validator/graffiti" "github.com/prysmaticlabs/prysm/v3/validator/keymanager" @@ -179,7 +180,7 @@ func (v *ValidatorService) Start() { valStruct := &validator{ db: v.db, - validatorClient: ethpb.NewBeaconNodeValidatorClient(v.conn), + validatorClient: validatorClientFactory.NewValidatorClient(v.conn), beaconClient: ethpb.NewBeaconChainClient(v.conn), slashingProtectionClient: ethpb.NewSlasherClient(v.conn), node: ethpb.NewNodeClient(v.conn), diff --git a/validator/client/sync_committee_test.go b/validator/client/sync_committee_test.go index ef9710aa7..893021a4a 100644 --- a/validator/client/sync_committee_test.go +++ b/validator/client/sync_committee_test.go @@ -16,7 +16,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/assert" "github.com/prysmaticlabs/prysm/v3/testing/require" logTest "github.com/sirupsen/logrus/hooks/test" - "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" ) @@ -145,7 +144,7 @@ func TestSubmitSyncCommitteeMessage_OK(t *testing.T) { m.validatorClient.EXPECT().SubmitSyncMessage( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.SyncCommitteeMessage{}), - ).Do(func(_ context.Context, msg *ethpb.SyncCommitteeMessage, opts ...grpc.CallOption) { + ).Do(func(_ context.Context, msg *ethpb.SyncCommitteeMessage) { generatedMsg = msg }).Return(&emptypb.Empty{}, nil /* error */) diff --git a/validator/client/validator-client-factory/BUILD.bazel b/validator/client/validator-client-factory/BUILD.bazel new file mode 100644 index 000000000..439050c0f --- /dev/null +++ b/validator/client/validator-client-factory/BUILD.bazel @@ -0,0 +1,31 @@ +load("@prysm//tools/go:def.bzl", "go_library") +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + +bool_flag( + name = "use_beacon_api", + build_setting_default = False, +) + +config_setting( + name = "beacon_api_usage", + flag_values = { + ":use_beacon_api": "true", + }, +) + +go_library( + name = "go_default_library", + srcs = select({ + ":beacon_api_usage": ["beacon_api_validator_client_factory.go"], + "//conditions:default": ["grpc_validator_client_factory.go"], + }), + importpath = "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory", + visibility = ["//visibility:public"], + deps = [ + "//validator/client/iface:go_default_library", + "@org_golang_google_grpc//:go_default_library", + ] + select({ + ":beacon_api_usage": ["//validator/client/beacon-api:go_default_library"], + "//conditions:default": ["//validator/client/grpc-api:go_default_library"], + }), +) diff --git a/validator/client/validator-client-factory/beacon_api_validator_client_factory.go b/validator/client/validator-client-factory/beacon_api_validator_client_factory.go new file mode 100644 index 000000000..31689c498 --- /dev/null +++ b/validator/client/validator-client-factory/beacon_api_validator_client_factory.go @@ -0,0 +1,14 @@ +//go:build use_beacon_api +// +build use_beacon_api + +package validator_client_factory + +import ( + beaconApi "github.com/prysmaticlabs/prysm/v3/validator/client/beacon-api" + "github.com/prysmaticlabs/prysm/v3/validator/client/iface" + "google.golang.org/grpc" +) + +func NewValidatorClient(cc grpc.ClientConnInterface) iface.ValidatorClient { + return beaconApi.NewBeaconApiValidatorClient() +} diff --git a/validator/client/validator-client-factory/grpc_validator_client_factory.go b/validator/client/validator-client-factory/grpc_validator_client_factory.go new file mode 100644 index 000000000..20105339b --- /dev/null +++ b/validator/client/validator-client-factory/grpc_validator_client_factory.go @@ -0,0 +1,14 @@ +//go:build !use_beacon_api +// +build !use_beacon_api + +package validator_client_factory + +import ( + grpcApi "github.com/prysmaticlabs/prysm/v3/validator/client/grpc-api" + "github.com/prysmaticlabs/prysm/v3/validator/client/iface" + "google.golang.org/grpc" +) + +func NewValidatorClient(cc grpc.ClientConnInterface) iface.ValidatorClient { + return grpcApi.NewGrpcValidatorClient(cc) +} diff --git a/validator/client/validator.go b/validator/client/validator.go index ecb72c081..92cfce6b4 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -95,7 +95,7 @@ type validator struct { beaconClient ethpb.BeaconChainClient keyManager keymanager.IKeymanager ticker slots.Ticker - validatorClient ethpb.BeaconNodeValidatorClient + validatorClient iface.ValidatorClient graffiti []byte voteStats voteStats syncCommitteeStats syncCommitteeStats diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index 4b388b420..fe45a195e 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -38,7 +38,6 @@ import ( remoteweb3signer "github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote-web3signer" "github.com/sirupsen/logrus" logTest "github.com/sirupsen/logrus/hooks/test" - "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" ) @@ -139,7 +138,7 @@ func generateMockStatusResponse(pubkeys [][]byte) *ethpb.ValidatorActivationResp func TestWaitForChainStart_SetsGenesisInfo(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) v := validator{ @@ -194,7 +193,7 @@ func TestWaitForChainStart_SetsGenesisInfo(t *testing.T) { func TestWaitForChainStart_SetsGenesisInfo_IncorrectSecondTry(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) v := validator{ @@ -246,7 +245,7 @@ func TestWaitForChainStart_SetsGenesisInfo_IncorrectSecondTry(t *testing.T) { func TestWaitForChainStart_ContextCanceled(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) v := validator{ //keyManager: testKeyManager, @@ -275,7 +274,7 @@ func TestWaitForChainStart_ContextCanceled(t *testing.T) { func TestWaitForChainStart_StreamSetupFails(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -301,7 +300,7 @@ func TestWaitForChainStart_StreamSetupFails(t *testing.T) { func TestWaitForChainStart_ReceiveErrorFromStream(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, @@ -357,7 +356,7 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock2.NewMockValidatorClient(ctrl) beaconClient := mock2.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -395,7 +394,7 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) { func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock2.NewMockValidatorClient(ctrl) beaconClient := mock2.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -492,7 +491,7 @@ func TestWaitSync_Syncing(t *testing.T) { func TestUpdateDuties_DoesNothingWhenNotEpochStart_AlreadyExistingAssignments(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) slot := types.Slot(1) v := validator{ @@ -518,7 +517,7 @@ func TestUpdateDuties_DoesNothingWhenNotEpochStart_AlreadyExistingAssignments(t func TestUpdateDuties_ReturnsError(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -555,7 +554,7 @@ func TestUpdateDuties_ReturnsError(t *testing.T) { func TestUpdateDuties_OK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) slot := params.BeaconConfig().SlotsPerEpoch privKey, err := bls.RandKey() @@ -594,7 +593,7 @@ func TestUpdateDuties_OK(t *testing.T) { client.EXPECT().SubscribeCommitteeSubnets( gomock.Any(), gomock.Any(), - ).DoAndReturn(func(_ context.Context, _ *ethpb.CommitteeSubnetsSubscribeRequest, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { + ).DoAndReturn(func(_ context.Context, _ *ethpb.CommitteeSubnetsSubscribeRequest) (*emptypb.Empty, error) { wg.Done() return nil, nil }) @@ -613,7 +612,7 @@ func TestUpdateDuties_OK_FilterBlacklistedPublicKeys(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) slot := params.BeaconConfig().SlotsPerEpoch numValidators := 10 @@ -649,7 +648,7 @@ func TestUpdateDuties_OK_FilterBlacklistedPublicKeys(t *testing.T) { client.EXPECT().SubscribeCommitteeSubnets( gomock.Any(), gomock.Any(), - ).DoAndReturn(func(_ context.Context, _ *ethpb.CommitteeSubnetsSubscribeRequest, arg2 ...grpc.CallOption) (*emptypb.Empty, error) { + ).DoAndReturn(func(_ context.Context, _ *ethpb.CommitteeSubnetsSubscribeRequest) (*emptypb.Empty, error) { wg.Done() return nil, nil }) @@ -867,7 +866,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, duties: ðpb.DutiesResponse{ @@ -891,7 +890,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { func TestAllValidatorsAreExited_AllExited(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_EXITED}, @@ -912,7 +911,7 @@ func TestAllValidatorsAreExited_AllExited(t *testing.T) { func TestAllValidatorsAreExited_NotAllExited(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_ACTIVE}, @@ -933,7 +932,7 @@ func TestAllValidatorsAreExited_NotAllExited(t *testing.T) { func TestAllValidatorsAreExited_PartialResult(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_EXITED}, @@ -953,7 +952,7 @@ func TestAllValidatorsAreExited_PartialResult(t *testing.T) { func TestAllValidatorsAreExited_NoKeys(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) v := validator{keyManager: genMockKeymanager(0), validatorClient: client} exited, err := v.AllValidatorsAreExited(context.Background()) require.NoError(t, err) @@ -964,7 +963,7 @@ func TestAllValidatorsAreExited_NoKeys(t *testing.T) { func TestAllValidatorsAreExited_CorrectRequest(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) // Create two different public keys pubKey0 := [fieldparams.BLSPubkeyLength]byte{1, 2, 3, 4} @@ -1007,7 +1006,7 @@ func TestAllValidatorsAreExited_CorrectRequest(t *testing.T) { func TestService_ReceiveBlocks_NilBlock(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - valClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + valClient := mock2.NewMockValidatorClient(ctrl) v := validator{ blockFeed: new(event.Feed), validatorClient: valClient, @@ -1034,7 +1033,7 @@ func TestService_ReceiveBlocks_NilBlock(t *testing.T) { func TestService_ReceiveBlocks_SetHighest(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, @@ -1095,7 +1094,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "no doppelganger", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1127,7 +1126,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "multiple doppelganger exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1161,7 +1160,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "single doppelganger exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1195,7 +1194,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "multiple attestations saved", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1234,7 +1233,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "no history exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) // Use only 1 key for deterministic order. km := genMockKeymanager(1) keys, err := km.FetchValidatingPublicKeys(context.Background()) @@ -1447,7 +1446,7 @@ func TestValidator_PushProposerSettings(t *testing.T) { ctrl := gomock.NewController(t) ctx := context.Background() db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) - client := mock2.NewMockBeaconNodeValidatorClient(ctrl) + client := mock2.NewMockValidatorClient(ctrl) nodeClient := mock2.NewMockNodeClient(ctrl) defaultFeeHex := "0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9" byteValueAddress, err := hexutil.Decode("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9") diff --git a/validator/client/wait_for_activation_test.go b/validator/client/wait_for_activation_test.go index 9866ae7bb..d7dec700a 100644 --- a/validator/client/wait_for_activation_test.go +++ b/validator/client/wait_for_activation_test.go @@ -30,7 +30,7 @@ import ( func TestWaitActivation_ContextCanceled(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -66,7 +66,7 @@ func TestWaitActivation_ContextCanceled(t *testing.T) { func TestWaitActivation_StreamSetupFails_AttemptsToReconnect(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -99,7 +99,7 @@ func TestWaitActivation_StreamSetupFails_AttemptsToReconnect(t *testing.T) { func TestWaitForActivation_ReceiveErrorFromStream_AttemptsReconnection(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -137,7 +137,7 @@ func TestWaitActivation_LogsActivationEpochOK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -175,7 +175,7 @@ func TestWaitActivation_LogsActivationEpochOK(t *testing.T) { func TestWaitForActivation_Exiting(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -218,7 +218,7 @@ func TestWaitForActivation_RefetchKeys(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -273,7 +273,7 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: validatorClient, @@ -347,7 +347,7 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { require.NoError(t, err) err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", "", 1) require.NoError(t, err) - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: validatorClient, @@ -405,7 +405,7 @@ func TestWaitForActivation_RemoteKeymanager(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockBeaconNodeValidatorClient(ctrl) + validatorClient := mock.NewMockValidatorClient(ctrl) beaconClient := mock.NewMockBeaconChainClient(ctrl) stream := mock.NewMockBeaconNodeValidator_WaitForActivationClient(ctrl) validatorClient.EXPECT().WaitForActivation( diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index 69fec9e82..63d951d49 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -43,6 +43,8 @@ go_library( "//validator/accounts/petnames:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client:go_default_library", + "//validator/client/iface:go_default_library", + "//validator/client/validator-client-factory:go_default_library", "//validator/db:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", diff --git a/validator/rpc/accounts_test.go b/validator/rpc/accounts_test.go index 274888417..b9f63deca 100644 --- a/validator/rpc/accounts_test.go +++ b/validator/rpc/accounts_test.go @@ -187,7 +187,7 @@ func TestServer_VoluntaryExit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() ctx := context.Background() - mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + mockValidatorClient := mock2.NewMockValidatorClient(ctrl) mockNodeClient := mock2.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). diff --git a/validator/rpc/beacon.go b/validator/rpc/beacon.go index bca6f056e..a6f30e45b 100644 --- a/validator/rpc/beacon.go +++ b/validator/rpc/beacon.go @@ -14,6 +14,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v3/validator/client" + validatorClientFactory "github.com/prysmaticlabs/prysm/v3/validator/client/validator-client-factory" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" ) @@ -48,7 +49,7 @@ func (s *Server) registerBeaconClient() error { s.beaconChainClient = ethpb.NewBeaconChainClient(conn) s.beaconNodeClient = ethpb.NewNodeClient(conn) s.beaconNodeHealthClient = ethpb.NewHealthClient(conn) - s.beaconNodeValidatorClient = ethpb.NewBeaconNodeValidatorClient(conn) + s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn) return nil } diff --git a/validator/rpc/server.go b/validator/rpc/server.go index 4af15b6b3..9c0a0fd3b 100644 --- a/validator/rpc/server.go +++ b/validator/rpc/server.go @@ -19,6 +19,7 @@ import ( validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v3/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/v3/validator/client" + iface "github.com/prysmaticlabs/prysm/v3/validator/client/iface" "github.com/prysmaticlabs/prysm/v3/validator/db" "github.com/sirupsen/logrus" "go.opencensus.io/plugin/ocgrpc" @@ -59,7 +60,7 @@ type Server struct { streamLogsBufferSize int beaconChainClient ethpb.BeaconChainClient beaconNodeClient ethpb.NodeClient - beaconNodeValidatorClient ethpb.BeaconNodeValidatorClient + beaconNodeValidatorClient iface.ValidatorClient beaconNodeHealthClient ethpb.HealthClient valDB db.Database ctx context.Context diff --git a/validator/rpc/standard_api_test.go b/validator/rpc/standard_api_test.go index da2de59d2..f05edb59d 100644 --- a/validator/rpc/standard_api_test.go +++ b/validator/rpc/standard_api_test.go @@ -770,7 +770,7 @@ func TestServer_ListFeeRecipientByPubkey(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrl := gomock.NewController(t) - mockValidatorClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + mockValidatorClient := mock2.NewMockValidatorClient(ctrl) m := &mock.MockValidator{} m.SetProposerSettings(tt.args) vs, err := client.NewValidatorService(ctx, &client.Config{ @@ -793,7 +793,7 @@ func TestServer_ListFeeRecipientByPubkey(t *testing.T) { func TestServer_SetFeeRecipientByPubkey(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - beaconClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + beaconClient := mock2.NewMockValidatorClient(ctrl) ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{}) byteval, err := hexutil.Decode("0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591493") wantAddress := "0x055Fb65722e7b2455012Bfebf6177f1d2e9738d7" @@ -1024,7 +1024,7 @@ func TestServer_GetGasLimit(t *testing.T) { func TestServer_SetGasLimit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - beaconClient := mock2.NewMockBeaconNodeValidatorClient(ctrl) + beaconClient := mock2.NewMockValidatorClient(ctrl) ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{}) pubkey1, err := hexutil.Decode("0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591493") pubkey2, err2 := hexutil.Decode("0xbedefeaa94e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2cdddddddddddddddddddddddd")