From 7c49277e83997fa0858c789862b7c8def950ce24 Mon Sep 17 00:00:00 2001 From: Patrice Vignola Date: Mon, 20 Mar 2023 09:32:32 -0700 Subject: [PATCH] Add REST API stubs for beacon chain, node and slasher clients (#12094) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WIP * WIP * Remove duplicate mock * WIP * Revert "WIP" This reverts commit a8010057fef4209dfddde34ea868b88f1e196c44. * Fix build break * Remove unused variable * Fix build break * Rename validator_mock to validatormock * Fix failing test --------- Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: RadosÅ‚aw Kapka --- cmd/validator/accounts/BUILD.bazel | 2 +- cmd/validator/accounts/exit_test.go | 14 +- hack/update-mockgen.sh | 8 +- testing/mock/BUILD.bazel | 2 - testing/validator-mock/BUILD.bazel | 21 + .../beacon_chain_client_mock.go | 382 ++++++++++++++++++ testing/validator-mock/node_client_mock.go | 157 +++++++ testing/validator-mock/slasher_client_mock.go | 81 ++++ .../validator_client_mock.go | 19 +- validator/accounts/BUILD.bazel | 3 +- validator/accounts/accounts_exit.go | 3 +- validator/accounts/accounts_list_test.go | 4 +- validator/accounts/cli_manager.go | 6 +- validator/client/BUILD.bazel | 4 + validator/client/beacon-api/BUILD.bazel | 3 + .../beacon_api_beacon_chain_client.go | 240 +++++++++++ .../beacon-api/beacon_api_node_client.go | 100 +++++ .../beacon-api/beacon_api_slasher_client.go | 55 +++ .../beacon-chain-client-factory/BUILD.bazel | 15 + .../beacon_chain_client_factory.go | 20 + validator/client/grpc-api/BUILD.bazel | 7 +- .../grpc-api/grpc_beacon_chain_client.go | 115 ++++++ validator/client/grpc-api/grpc_node_client.go | 50 +++ .../client/grpc-api/grpc_slasher_client.go | 29 ++ validator/client/iface/BUILD.bazel | 3 + validator/client/iface/beacon_chain_client.go | 39 ++ validator/client/iface/node_client.go | 19 + validator/client/iface/slasher_client.go | 13 + validator/client/key_reload_test.go | 12 +- .../client/node-client-factory/BUILD.bazel | 15 + .../node_client_factory.go | 20 + validator/client/propose.go | 2 +- validator/client/propose_test.go | 18 +- validator/client/service.go | 9 +- .../client/slasher-client-factory/BUILD.bazel | 15 + .../slasher_client_factory.go | 20 + validator/client/validator.go | 6 +- validator/client/validator_test.go | 77 ++-- validator/client/wait_for_activation_test.go | 33 +- validator/rpc/BUILD.bazel | 4 +- validator/rpc/accounts_test.go | 6 +- validator/rpc/beacon.go | 6 +- validator/rpc/beacon_test.go | 8 +- validator/rpc/server.go | 4 +- validator/rpc/standard_api_test.go | 12 +- 45 files changed, 1549 insertions(+), 132 deletions(-) create mode 100644 testing/validator-mock/BUILD.bazel create mode 100644 testing/validator-mock/beacon_chain_client_mock.go create mode 100644 testing/validator-mock/node_client_mock.go create mode 100644 testing/validator-mock/slasher_client_mock.go rename testing/{mock => validator-mock}/validator_client_mock.go (96%) create mode 100644 validator/client/beacon-api/beacon_api_beacon_chain_client.go create mode 100644 validator/client/beacon-api/beacon_api_node_client.go create mode 100644 validator/client/beacon-api/beacon_api_slasher_client.go create mode 100644 validator/client/beacon-chain-client-factory/BUILD.bazel create mode 100644 validator/client/beacon-chain-client-factory/beacon_chain_client_factory.go create mode 100644 validator/client/grpc-api/grpc_beacon_chain_client.go create mode 100644 validator/client/grpc-api/grpc_node_client.go create mode 100644 validator/client/grpc-api/grpc_slasher_client.go create mode 100644 validator/client/iface/beacon_chain_client.go create mode 100644 validator/client/iface/node_client.go create mode 100644 validator/client/iface/slasher_client.go create mode 100644 validator/client/node-client-factory/BUILD.bazel create mode 100644 validator/client/node-client-factory/node_client_factory.go create mode 100644 validator/client/slasher-client-factory/BUILD.bazel create mode 100644 validator/client/slasher-client-factory/slasher_client_factory.go diff --git a/cmd/validator/accounts/BUILD.bazel b/cmd/validator/accounts/BUILD.bazel index 30ce8e5fa..22d3454ec 100644 --- a/cmd/validator/accounts/BUILD.bazel +++ b/cmd/validator/accounts/BUILD.bazel @@ -56,8 +56,8 @@ go_test( "//io/file:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", - "//testing/mock:go_default_library", "//testing/require:go_default_library", + "//testing/validator-mock:go_default_library", "//time:go_default_library", "//validator/accounts:go_default_library", "//validator/accounts/iface:go_default_library", diff --git a/cmd/validator/accounts/exit_test.go b/cmd/validator/accounts/exit_test.go index ebb97e9b5..0f8647ad8 100644 --- a/cmd/validator/accounts/exit_test.go +++ b/cmd/validator/accounts/exit_test.go @@ -11,8 +11,8 @@ import ( "github.com/golang/mock/gomock" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" - mock2 "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/accounts" "github.com/prysmaticlabs/prysm/v4/validator/keymanager" "google.golang.org/protobuf/types/known/timestamppb" @@ -21,8 +21,8 @@ import ( func TestExitAccountsCli_OK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) - mockNodeClient := mock2.NewMockNodeClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) + mockNodeClient := validatormock.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). ValidatorIndex(gomock.Any(), gomock.Any()). @@ -113,8 +113,8 @@ func TestExitAccountsCli_OK(t *testing.T) { func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) - mockNodeClient := mock2.NewMockNodeClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) + mockNodeClient := validatormock.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). ValidatorIndex(gomock.Any(), gomock.Any()). @@ -220,8 +220,8 @@ func TestExitAccountsCli_OK_AllPublicKeys(t *testing.T) { func TestExitAccountsCli_OK_ForceExit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) - mockNodeClient := mock2.NewMockNodeClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) + mockNodeClient := validatormock.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). ValidatorIndex(gomock.Any(), gomock.Any()). diff --git a/hack/update-mockgen.sh b/hack/update-mockgen.sh index 0f9317b10..a717fbb46 100755 --- a/hack/update-mockgen.sh +++ b/hack/update-mockgen.sh @@ -4,6 +4,7 @@ # Use a space to separate mock destination from its interfaces. mock_path="testing/mock" +iface_mock_path="testing/validator-mock" # github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1 # ------------------------------------------------------ @@ -55,14 +56,17 @@ done # github.com/prysmaticlabs/prysm/v4/validator/client/iface # -------------------------------------------------------- iface_mocks=( - "$mock_path/validator_client_mock.go ValidatorClient" + "$iface_mock_path/beacon_chain_client_mock.go BeaconChainClient" + "$iface_mock_path/node_client_mock.go NodeClient" + "$iface_mock_path/slasher_client_mock.go SlasherClient" + "$iface_mock_path/validator_client_mock.go ValidatorClient" ) 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/v4/validator/client/iface "$interfaces" + GO11MODULE=on mockgen -package=validator_mock -destination="$file" github.com/prysmaticlabs/prysm/v4/validator/client/iface "$interfaces" done goimports -w "$mock_path/." diff --git a/testing/mock/BUILD.bazel b/testing/mock/BUILD.bazel index f48b94eba..43a212870 100644 --- a/testing/mock/BUILD.bazel +++ b/testing/mock/BUILD.bazel @@ -15,12 +15,10 @@ go_library( "keymanager_mock.go", "node_service_mock.go", "slasher_client_mock.go", - "validator_client_mock.go", ], importpath = "github.com/prysmaticlabs/prysm/v4/testing/mock", visibility = ["//visibility:public"], deps = [ - "//consensus-types/primitives:go_default_library", "//proto/eth/service:go_default_library", "//proto/eth/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/testing/validator-mock/BUILD.bazel b/testing/validator-mock/BUILD.bazel new file mode 100644 index 000000000..a267353d2 --- /dev/null +++ b/testing/validator-mock/BUILD.bazel @@ -0,0 +1,21 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +package(default_testonly = True) + +go_library( + name = "go_default_library", + srcs = [ + "beacon_chain_client_mock.go", + "node_client_mock.go", + "slasher_client_mock.go", + "validator_client_mock.go", + ], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/validator-mock", + visibility = ["//visibility:public"], + deps = [ + "//consensus-types/primitives:go_default_library", + "//proto/prysm/v1alpha1:go_default_library", + "@com_github_golang_mock//gomock:go_default_library", + "@org_golang_google_protobuf//types/known/emptypb:go_default_library", + ], +) diff --git a/testing/validator-mock/beacon_chain_client_mock.go b/testing/validator-mock/beacon_chain_client_mock.go new file mode 100644 index 000000000..b152084b0 --- /dev/null +++ b/testing/validator-mock/beacon_chain_client_mock.go @@ -0,0 +1,382 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/prysmaticlabs/prysm/v4/validator/client/iface (interfaces: BeaconChainClient) + +// Package validator_mock is a generated GoMock package. +package validator_mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockBeaconChainClient is a mock of BeaconChainClient interface. +type MockBeaconChainClient struct { + ctrl *gomock.Controller + recorder *MockBeaconChainClientMockRecorder +} + +// MockBeaconChainClientMockRecorder is the mock recorder for MockBeaconChainClient. +type MockBeaconChainClientMockRecorder struct { + mock *MockBeaconChainClient +} + +// NewMockBeaconChainClient creates a new mock instance. +func NewMockBeaconChainClient(ctrl *gomock.Controller) *MockBeaconChainClient { + mock := &MockBeaconChainClient{ctrl: ctrl} + mock.recorder = &MockBeaconChainClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBeaconChainClient) EXPECT() *MockBeaconChainClientMockRecorder { + return m.recorder +} + +// AttestationPool mocks base method. +func (m *MockBeaconChainClient) AttestationPool(arg0 context.Context, arg1 *eth.AttestationPoolRequest) (*eth.AttestationPoolResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AttestationPool", arg0, arg1) + ret0, _ := ret[0].(*eth.AttestationPoolResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AttestationPool indicates an expected call of AttestationPool. +func (mr *MockBeaconChainClientMockRecorder) AttestationPool(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttestationPool", reflect.TypeOf((*MockBeaconChainClient)(nil).AttestationPool), arg0, arg1) +} + +// GetBeaconConfig mocks base method. +func (m *MockBeaconChainClient) GetBeaconConfig(arg0 context.Context, arg1 *emptypb.Empty) (*eth.BeaconConfig, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBeaconConfig", arg0, arg1) + ret0, _ := ret[0].(*eth.BeaconConfig) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBeaconConfig indicates an expected call of GetBeaconConfig. +func (mr *MockBeaconChainClientMockRecorder) GetBeaconConfig(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBeaconConfig", reflect.TypeOf((*MockBeaconChainClient)(nil).GetBeaconConfig), arg0, arg1) +} + +// GetChainHead mocks base method. +func (m *MockBeaconChainClient) GetChainHead(arg0 context.Context, arg1 *emptypb.Empty) (*eth.ChainHead, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChainHead", arg0, arg1) + ret0, _ := ret[0].(*eth.ChainHead) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetChainHead indicates an expected call of GetChainHead. +func (mr *MockBeaconChainClientMockRecorder) GetChainHead(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChainHead", reflect.TypeOf((*MockBeaconChainClient)(nil).GetChainHead), arg0, arg1) +} + +// GetIndividualVotes mocks base method. +func (m *MockBeaconChainClient) GetIndividualVotes(arg0 context.Context, arg1 *eth.IndividualVotesRequest) (*eth.IndividualVotesRespond, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetIndividualVotes", arg0, arg1) + ret0, _ := ret[0].(*eth.IndividualVotesRespond) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetIndividualVotes indicates an expected call of GetIndividualVotes. +func (mr *MockBeaconChainClientMockRecorder) GetIndividualVotes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIndividualVotes", reflect.TypeOf((*MockBeaconChainClient)(nil).GetIndividualVotes), arg0, arg1) +} + +// GetValidator mocks base method. +func (m *MockBeaconChainClient) GetValidator(arg0 context.Context, arg1 *eth.GetValidatorRequest) (*eth.Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidator", arg0, arg1) + ret0, _ := ret[0].(*eth.Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetValidator indicates an expected call of GetValidator. +func (mr *MockBeaconChainClientMockRecorder) GetValidator(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidator", reflect.TypeOf((*MockBeaconChainClient)(nil).GetValidator), arg0, arg1) +} + +// GetValidatorActiveSetChanges mocks base method. +func (m *MockBeaconChainClient) GetValidatorActiveSetChanges(arg0 context.Context, arg1 *eth.GetValidatorActiveSetChangesRequest) (*eth.ActiveSetChanges, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidatorActiveSetChanges", arg0, arg1) + ret0, _ := ret[0].(*eth.ActiveSetChanges) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetValidatorActiveSetChanges indicates an expected call of GetValidatorActiveSetChanges. +func (mr *MockBeaconChainClientMockRecorder) GetValidatorActiveSetChanges(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorActiveSetChanges", reflect.TypeOf((*MockBeaconChainClient)(nil).GetValidatorActiveSetChanges), arg0, arg1) +} + +// GetValidatorParticipation mocks base method. +func (m *MockBeaconChainClient) GetValidatorParticipation(arg0 context.Context, arg1 *eth.GetValidatorParticipationRequest) (*eth.ValidatorParticipationResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidatorParticipation", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorParticipationResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetValidatorParticipation indicates an expected call of GetValidatorParticipation. +func (mr *MockBeaconChainClientMockRecorder) GetValidatorParticipation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorParticipation", reflect.TypeOf((*MockBeaconChainClient)(nil).GetValidatorParticipation), arg0, arg1) +} + +// GetValidatorPerformance mocks base method. +func (m *MockBeaconChainClient) GetValidatorPerformance(arg0 context.Context, arg1 *eth.ValidatorPerformanceRequest) (*eth.ValidatorPerformanceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidatorPerformance", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorPerformanceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetValidatorPerformance indicates an expected call of GetValidatorPerformance. +func (mr *MockBeaconChainClientMockRecorder) GetValidatorPerformance(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorPerformance", reflect.TypeOf((*MockBeaconChainClient)(nil).GetValidatorPerformance), arg0, arg1) +} + +// GetValidatorQueue mocks base method. +func (m *MockBeaconChainClient) GetValidatorQueue(arg0 context.Context, arg1 *emptypb.Empty) (*eth.ValidatorQueue, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValidatorQueue", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorQueue) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetValidatorQueue indicates an expected call of GetValidatorQueue. +func (mr *MockBeaconChainClientMockRecorder) GetValidatorQueue(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorQueue", reflect.TypeOf((*MockBeaconChainClient)(nil).GetValidatorQueue), arg0, arg1) +} + +// ListAttestations mocks base method. +func (m *MockBeaconChainClient) ListAttestations(arg0 context.Context, arg1 *eth.ListAttestationsRequest) (*eth.ListAttestationsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListAttestations", arg0, arg1) + ret0, _ := ret[0].(*eth.ListAttestationsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListAttestations indicates an expected call of ListAttestations. +func (mr *MockBeaconChainClientMockRecorder) ListAttestations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAttestations", reflect.TypeOf((*MockBeaconChainClient)(nil).ListAttestations), arg0, arg1) +} + +// ListBeaconBlocks mocks base method. +func (m *MockBeaconChainClient) ListBeaconBlocks(arg0 context.Context, arg1 *eth.ListBlocksRequest) (*eth.ListBeaconBlocksResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListBeaconBlocks", arg0, arg1) + ret0, _ := ret[0].(*eth.ListBeaconBlocksResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListBeaconBlocks indicates an expected call of ListBeaconBlocks. +func (mr *MockBeaconChainClientMockRecorder) ListBeaconBlocks(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListBeaconBlocks", reflect.TypeOf((*MockBeaconChainClient)(nil).ListBeaconBlocks), arg0, arg1) +} + +// ListBeaconCommittees mocks base method. +func (m *MockBeaconChainClient) ListBeaconCommittees(arg0 context.Context, arg1 *eth.ListCommitteesRequest) (*eth.BeaconCommittees, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListBeaconCommittees", arg0, arg1) + ret0, _ := ret[0].(*eth.BeaconCommittees) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListBeaconCommittees indicates an expected call of ListBeaconCommittees. +func (mr *MockBeaconChainClientMockRecorder) ListBeaconCommittees(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListBeaconCommittees", reflect.TypeOf((*MockBeaconChainClient)(nil).ListBeaconCommittees), arg0, arg1) +} + +// ListIndexedAttestations mocks base method. +func (m *MockBeaconChainClient) ListIndexedAttestations(arg0 context.Context, arg1 *eth.ListIndexedAttestationsRequest) (*eth.ListIndexedAttestationsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListIndexedAttestations", arg0, arg1) + ret0, _ := ret[0].(*eth.ListIndexedAttestationsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListIndexedAttestations indicates an expected call of ListIndexedAttestations. +func (mr *MockBeaconChainClientMockRecorder) ListIndexedAttestations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListIndexedAttestations", reflect.TypeOf((*MockBeaconChainClient)(nil).ListIndexedAttestations), arg0, arg1) +} + +// ListValidatorAssignments mocks base method. +func (m *MockBeaconChainClient) ListValidatorAssignments(arg0 context.Context, arg1 *eth.ListValidatorAssignmentsRequest) (*eth.ValidatorAssignments, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListValidatorAssignments", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorAssignments) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListValidatorAssignments indicates an expected call of ListValidatorAssignments. +func (mr *MockBeaconChainClientMockRecorder) ListValidatorAssignments(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListValidatorAssignments", reflect.TypeOf((*MockBeaconChainClient)(nil).ListValidatorAssignments), arg0, arg1) +} + +// ListValidatorBalances mocks base method. +func (m *MockBeaconChainClient) ListValidatorBalances(arg0 context.Context, arg1 *eth.ListValidatorBalancesRequest) (*eth.ValidatorBalances, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListValidatorBalances", arg0, arg1) + ret0, _ := ret[0].(*eth.ValidatorBalances) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListValidatorBalances indicates an expected call of ListValidatorBalances. +func (mr *MockBeaconChainClientMockRecorder) ListValidatorBalances(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListValidatorBalances", reflect.TypeOf((*MockBeaconChainClient)(nil).ListValidatorBalances), arg0, arg1) +} + +// ListValidators mocks base method. +func (m *MockBeaconChainClient) ListValidators(arg0 context.Context, arg1 *eth.ListValidatorsRequest) (*eth.Validators, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListValidators", arg0, arg1) + ret0, _ := ret[0].(*eth.Validators) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListValidators indicates an expected call of ListValidators. +func (mr *MockBeaconChainClientMockRecorder) ListValidators(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListValidators", reflect.TypeOf((*MockBeaconChainClient)(nil).ListValidators), arg0, arg1) +} + +// StreamAttestations mocks base method. +func (m *MockBeaconChainClient) StreamAttestations(arg0 context.Context, arg1 *emptypb.Empty) (eth.BeaconChain_StreamAttestationsClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamAttestations", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconChain_StreamAttestationsClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamAttestations indicates an expected call of StreamAttestations. +func (mr *MockBeaconChainClientMockRecorder) StreamAttestations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamAttestations", reflect.TypeOf((*MockBeaconChainClient)(nil).StreamAttestations), arg0, arg1) +} + +// StreamBlocks mocks base method. +func (m *MockBeaconChainClient) StreamBlocks(arg0 context.Context, arg1 *eth.StreamBlocksRequest) (eth.BeaconChain_StreamBlocksClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamBlocks", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconChain_StreamBlocksClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamBlocks indicates an expected call of StreamBlocks. +func (mr *MockBeaconChainClientMockRecorder) StreamBlocks(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamBlocks", reflect.TypeOf((*MockBeaconChainClient)(nil).StreamBlocks), arg0, arg1) +} + +// StreamChainHead mocks base method. +func (m *MockBeaconChainClient) StreamChainHead(arg0 context.Context, arg1 *emptypb.Empty) (eth.BeaconChain_StreamChainHeadClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamChainHead", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconChain_StreamChainHeadClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamChainHead indicates an expected call of StreamChainHead. +func (mr *MockBeaconChainClientMockRecorder) StreamChainHead(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamChainHead", reflect.TypeOf((*MockBeaconChainClient)(nil).StreamChainHead), arg0, arg1) +} + +// StreamIndexedAttestations mocks base method. +func (m *MockBeaconChainClient) StreamIndexedAttestations(arg0 context.Context, arg1 *emptypb.Empty) (eth.BeaconChain_StreamIndexedAttestationsClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamIndexedAttestations", arg0, arg1) + ret0, _ := ret[0].(eth.BeaconChain_StreamIndexedAttestationsClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamIndexedAttestations indicates an expected call of StreamIndexedAttestations. +func (mr *MockBeaconChainClientMockRecorder) StreamIndexedAttestations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamIndexedAttestations", reflect.TypeOf((*MockBeaconChainClient)(nil).StreamIndexedAttestations), arg0, arg1) +} + +// StreamValidatorsInfo mocks base method. +func (m *MockBeaconChainClient) StreamValidatorsInfo(arg0 context.Context) (eth.BeaconChain_StreamValidatorsInfoClient, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StreamValidatorsInfo", arg0) + ret0, _ := ret[0].(eth.BeaconChain_StreamValidatorsInfoClient) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StreamValidatorsInfo indicates an expected call of StreamValidatorsInfo. +func (mr *MockBeaconChainClientMockRecorder) StreamValidatorsInfo(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StreamValidatorsInfo", reflect.TypeOf((*MockBeaconChainClient)(nil).StreamValidatorsInfo), arg0) +} + +// SubmitAttesterSlashing mocks base method. +func (m *MockBeaconChainClient) SubmitAttesterSlashing(arg0 context.Context, arg1 *eth.AttesterSlashing) (*eth.SubmitSlashingResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitAttesterSlashing", arg0, arg1) + ret0, _ := ret[0].(*eth.SubmitSlashingResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitAttesterSlashing indicates an expected call of SubmitAttesterSlashing. +func (mr *MockBeaconChainClientMockRecorder) SubmitAttesterSlashing(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitAttesterSlashing", reflect.TypeOf((*MockBeaconChainClient)(nil).SubmitAttesterSlashing), arg0, arg1) +} + +// SubmitProposerSlashing mocks base method. +func (m *MockBeaconChainClient) SubmitProposerSlashing(arg0 context.Context, arg1 *eth.ProposerSlashing) (*eth.SubmitSlashingResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubmitProposerSlashing", arg0, arg1) + ret0, _ := ret[0].(*eth.SubmitSlashingResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitProposerSlashing indicates an expected call of SubmitProposerSlashing. +func (mr *MockBeaconChainClientMockRecorder) SubmitProposerSlashing(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitProposerSlashing", reflect.TypeOf((*MockBeaconChainClient)(nil).SubmitProposerSlashing), arg0, arg1) +} diff --git a/testing/validator-mock/node_client_mock.go b/testing/validator-mock/node_client_mock.go new file mode 100644 index 000000000..d178b3295 --- /dev/null +++ b/testing/validator-mock/node_client_mock.go @@ -0,0 +1,157 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/prysmaticlabs/prysm/v4/validator/client/iface (interfaces: NodeClient) + +// Package validator_mock is a generated GoMock package. +package validator_mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// MockNodeClient is a mock of NodeClient interface. +type MockNodeClient struct { + ctrl *gomock.Controller + recorder *MockNodeClientMockRecorder +} + +// MockNodeClientMockRecorder is the mock recorder for MockNodeClient. +type MockNodeClientMockRecorder struct { + mock *MockNodeClient +} + +// NewMockNodeClient creates a new mock instance. +func NewMockNodeClient(ctrl *gomock.Controller) *MockNodeClient { + mock := &MockNodeClient{ctrl: ctrl} + mock.recorder = &MockNodeClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockNodeClient) EXPECT() *MockNodeClientMockRecorder { + return m.recorder +} + +// GetETH1ConnectionStatus mocks base method. +func (m *MockNodeClient) GetETH1ConnectionStatus(arg0 context.Context, arg1 *emptypb.Empty) (*eth.ETH1ConnectionStatus, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetETH1ConnectionStatus", arg0, arg1) + ret0, _ := ret[0].(*eth.ETH1ConnectionStatus) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetETH1ConnectionStatus indicates an expected call of GetETH1ConnectionStatus. +func (mr *MockNodeClientMockRecorder) GetETH1ConnectionStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetETH1ConnectionStatus", reflect.TypeOf((*MockNodeClient)(nil).GetETH1ConnectionStatus), arg0, arg1) +} + +// GetGenesis mocks base method. +func (m *MockNodeClient) GetGenesis(arg0 context.Context, arg1 *emptypb.Empty) (*eth.Genesis, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGenesis", arg0, arg1) + ret0, _ := ret[0].(*eth.Genesis) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetGenesis indicates an expected call of GetGenesis. +func (mr *MockNodeClientMockRecorder) GetGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGenesis", reflect.TypeOf((*MockNodeClient)(nil).GetGenesis), arg0, arg1) +} + +// GetHost mocks base method. +func (m *MockNodeClient) GetHost(arg0 context.Context, arg1 *emptypb.Empty) (*eth.HostData, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetHost", arg0, arg1) + ret0, _ := ret[0].(*eth.HostData) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetHost indicates an expected call of GetHost. +func (mr *MockNodeClientMockRecorder) GetHost(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHost", reflect.TypeOf((*MockNodeClient)(nil).GetHost), arg0, arg1) +} + +// GetPeer mocks base method. +func (m *MockNodeClient) GetPeer(arg0 context.Context, arg1 *eth.PeerRequest) (*eth.Peer, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPeer", arg0, arg1) + ret0, _ := ret[0].(*eth.Peer) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPeer indicates an expected call of GetPeer. +func (mr *MockNodeClientMockRecorder) GetPeer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPeer", reflect.TypeOf((*MockNodeClient)(nil).GetPeer), arg0, arg1) +} + +// GetSyncStatus mocks base method. +func (m *MockNodeClient) GetSyncStatus(arg0 context.Context, arg1 *emptypb.Empty) (*eth.SyncStatus, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSyncStatus", arg0, arg1) + ret0, _ := ret[0].(*eth.SyncStatus) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSyncStatus indicates an expected call of GetSyncStatus. +func (mr *MockNodeClientMockRecorder) GetSyncStatus(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncStatus", reflect.TypeOf((*MockNodeClient)(nil).GetSyncStatus), arg0, arg1) +} + +// GetVersion mocks base method. +func (m *MockNodeClient) GetVersion(arg0 context.Context, arg1 *emptypb.Empty) (*eth.Version, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetVersion", arg0, arg1) + ret0, _ := ret[0].(*eth.Version) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetVersion indicates an expected call of GetVersion. +func (mr *MockNodeClientMockRecorder) GetVersion(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersion", reflect.TypeOf((*MockNodeClient)(nil).GetVersion), arg0, arg1) +} + +// ListImplementedServices mocks base method. +func (m *MockNodeClient) ListImplementedServices(arg0 context.Context, arg1 *emptypb.Empty) (*eth.ImplementedServices, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListImplementedServices", arg0, arg1) + ret0, _ := ret[0].(*eth.ImplementedServices) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListImplementedServices indicates an expected call of ListImplementedServices. +func (mr *MockNodeClientMockRecorder) ListImplementedServices(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListImplementedServices", reflect.TypeOf((*MockNodeClient)(nil).ListImplementedServices), arg0, arg1) +} + +// ListPeers mocks base method. +func (m *MockNodeClient) ListPeers(arg0 context.Context, arg1 *emptypb.Empty) (*eth.Peers, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListPeers", arg0, arg1) + ret0, _ := ret[0].(*eth.Peers) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListPeers indicates an expected call of ListPeers. +func (mr *MockNodeClientMockRecorder) ListPeers(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListPeers", reflect.TypeOf((*MockNodeClient)(nil).ListPeers), arg0, arg1) +} diff --git a/testing/validator-mock/slasher_client_mock.go b/testing/validator-mock/slasher_client_mock.go new file mode 100644 index 000000000..50c0f609e --- /dev/null +++ b/testing/validator-mock/slasher_client_mock.go @@ -0,0 +1,81 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/prysmaticlabs/prysm/v4/validator/client/iface (interfaces: SlasherClient) + +// Package validator_mock is a generated GoMock package. +package validator_mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" +) + +// MockSlasherClient is a mock of SlasherClient interface. +type MockSlasherClient struct { + ctrl *gomock.Controller + recorder *MockSlasherClientMockRecorder +} + +// MockSlasherClientMockRecorder is the mock recorder for MockSlasherClient. +type MockSlasherClientMockRecorder struct { + mock *MockSlasherClient +} + +// NewMockSlasherClient creates a new mock instance. +func NewMockSlasherClient(ctrl *gomock.Controller) *MockSlasherClient { + mock := &MockSlasherClient{ctrl: ctrl} + mock.recorder = &MockSlasherClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSlasherClient) EXPECT() *MockSlasherClientMockRecorder { + return m.recorder +} + +// HighestAttestations mocks base method. +func (m *MockSlasherClient) HighestAttestations(arg0 context.Context, arg1 *eth.HighestAttestationRequest) (*eth.HighestAttestationResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HighestAttestations", arg0, arg1) + ret0, _ := ret[0].(*eth.HighestAttestationResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// HighestAttestations indicates an expected call of HighestAttestations. +func (mr *MockSlasherClientMockRecorder) HighestAttestations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HighestAttestations", reflect.TypeOf((*MockSlasherClient)(nil).HighestAttestations), arg0, arg1) +} + +// IsSlashableAttestation mocks base method. +func (m *MockSlasherClient) IsSlashableAttestation(arg0 context.Context, arg1 *eth.IndexedAttestation) (*eth.AttesterSlashingResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSlashableAttestation", arg0, arg1) + ret0, _ := ret[0].(*eth.AttesterSlashingResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IsSlashableAttestation indicates an expected call of IsSlashableAttestation. +func (mr *MockSlasherClientMockRecorder) IsSlashableAttestation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSlashableAttestation", reflect.TypeOf((*MockSlasherClient)(nil).IsSlashableAttestation), arg0, arg1) +} + +// IsSlashableBlock mocks base method. +func (m *MockSlasherClient) IsSlashableBlock(arg0 context.Context, arg1 *eth.SignedBeaconBlockHeader) (*eth.ProposerSlashingResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSlashableBlock", arg0, arg1) + ret0, _ := ret[0].(*eth.ProposerSlashingResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IsSlashableBlock indicates an expected call of IsSlashableBlock. +func (mr *MockSlasherClientMockRecorder) IsSlashableBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSlashableBlock", reflect.TypeOf((*MockSlasherClient)(nil).IsSlashableBlock), arg0, arg1) +} diff --git a/testing/mock/validator_client_mock.go b/testing/validator-mock/validator_client_mock.go similarity index 96% rename from testing/mock/validator_client_mock.go rename to testing/validator-mock/validator_client_mock.go index 542d0af96..6e76da586 100644 --- a/testing/mock/validator_client_mock.go +++ b/testing/validator-mock/validator_client_mock.go @@ -1,8 +1,8 @@ // Code generated by MockGen. DO NOT EDIT. // Source: github.com/prysmaticlabs/prysm/v4/validator/client/iface (interfaces: ValidatorClient) -// Package mock is a generated GoMock package. -package mock +// Package validator_mock is a generated GoMock package. +package validator_mock import ( context "context" @@ -262,21 +262,6 @@ func (mr *MockValidatorClientMockRecorder) StreamBlocksAltair(arg0, arg1 interfa 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() diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index a30fc7055..9ff7d8de2 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -41,6 +41,7 @@ go_library( "//validator/accounts/wallet:go_default_library", "//validator/client:go_default_library", "//validator/client/iface:go_default_library", + "//validator/client/node-client-factory:go_default_library", "//validator/client/validator-client-factory:go_default_library", "//validator/helpers:go_default_library", "//validator/keymanager:go_default_library", @@ -80,8 +81,8 @@ go_test( "//proto/eth/service:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", - "//testing/mock:go_default_library", "//testing/require:go_default_library", + "//testing/validator-mock:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index d4f5a2f0f..f5bcf9a50 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -12,7 +12,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" "github.com/prysmaticlabs/prysm/v4/config/params" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/validator/client" "github.com/prysmaticlabs/prysm/v4/validator/client/iface" "github.com/prysmaticlabs/prysm/v4/validator/keymanager" @@ -22,7 +21,7 @@ import ( // PerformExitCfg for account voluntary exits. type PerformExitCfg struct { ValidatorClient iface.ValidatorClient - NodeClient ethpb.NodeClient + NodeClient iface.NodeClient Keymanager keymanager.IKeymanager RawPubKeys [][]byte FormattedPubKeys []string diff --git a/validator/accounts/accounts_list_test.go b/validator/accounts/accounts_list_test.go index 8f3346902..7994f3f1f 100644 --- a/validator/accounts/accounts_list_test.go +++ b/validator/accounts/accounts_list_test.go @@ -19,8 +19,8 @@ import ( "github.com/prysmaticlabs/prysm/v4/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/keymanager" "github.com/prysmaticlabs/prysm/v4/validator/keymanager/derived" "github.com/prysmaticlabs/prysm/v4/validator/keymanager/local" @@ -287,7 +287,7 @@ func TestListAccounts_LocalKeymanager(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - m := mock.NewMockValidatorClient(ctrl) + m := validatormock.NewMockValidatorClient(ctrl) var pks [][]byte for i := range pubKeys { pks = append(pks, pubKeys[i][:]) diff --git a/validator/accounts/cli_manager.go b/validator/accounts/cli_manager.go index 523735ff3..99740b6e9 100644 --- a/validator/accounts/cli_manager.go +++ b/validator/accounts/cli_manager.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc" "github.com/prysmaticlabs/prysm/v4/crypto/bls" - ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet" iface "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory" validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory" validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers" "github.com/prysmaticlabs/prysm/v4/validator/keymanager" @@ -65,7 +65,7 @@ type AccountsCLIManager struct { beaconApiTimeout time.Duration } -func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface.ValidatorClient, *ethpb.NodeClient, error) { +func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface.ValidatorClient, *iface.NodeClient, error) { if acm.dialOpts == nil { return nil, nil, errors.New("failed to construct dial options for beacon clients") } @@ -83,6 +83,6 @@ func (acm *AccountsCLIManager) prepareBeaconClients(ctx context.Context) (*iface ) validatorClient := validatorClientFactory.NewValidatorClient(conn) - nodeClient := ethpb.NewNodeClient(grpcConn) + nodeClient := nodeClientFactory.NewNodeClient(conn) return &validatorClient, &nodeClient, nil } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index b7aedf442..4c81838bb 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -54,7 +54,10 @@ go_library( "//time/slots:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", + "//validator/client/beacon-chain-client-factory:go_default_library", "//validator/client/iface:go_default_library", + "//validator/client/node-client-factory:go_default_library", + "//validator/client/slasher-client-factory:go_default_library", "//validator/client/validator-client-factory:go_default_library", "//validator/db:go_default_library", "//validator/db/kv:go_default_library", @@ -137,6 +140,7 @@ go_test( "//testing/mock:go_default_library", "//testing/require:go_default_library", "//testing/util:go_default_library", + "//testing/validator-mock:go_default_library", "//time:go_default_library", "//time/slots:go_default_library", "//validator/accounts/testing:go_default_library", diff --git a/validator/client/beacon-api/BUILD.bazel b/validator/client/beacon-api/BUILD.bazel index aa97c0778..876604622 100644 --- a/validator/client/beacon-api/BUILD.bazel +++ b/validator/client/beacon-api/BUILD.bazel @@ -5,7 +5,10 @@ go_library( srcs = [ "activation.go", "attestation_data.go", + "beacon_api_beacon_chain_client.go", "beacon_api_helpers.go", + "beacon_api_node_client.go", + "beacon_api_slasher_client.go", "beacon_api_validator_client.go", "beacon_block_converter.go", "beacon_block_json_helpers.go", diff --git a/validator/client/beacon-api/beacon_api_beacon_chain_client.go b/validator/client/beacon-api/beacon_api_beacon_chain_client.go new file mode 100644 index 000000000..e8081da25 --- /dev/null +++ b/validator/client/beacon-api/beacon_api_beacon_chain_client.go @@ -0,0 +1,240 @@ +package beacon_api + +import ( + "context" + "net/http" + "time" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" +) + +type beaconApiBeaconChainClient struct { + fallbackClient iface.BeaconChainClient + jsonRestHandler jsonRestHandler +} + +func (c beaconApiBeaconChainClient) ListAttestations(ctx context.Context, in *ethpb.ListAttestationsRequest) (*ethpb.ListAttestationsResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListAttestations(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListAttestations is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListIndexedAttestations(ctx context.Context, in *ethpb.ListIndexedAttestationsRequest) (*ethpb.ListIndexedAttestationsResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListIndexedAttestations(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListIndexedAttestations is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiBeaconChainClient) StreamAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamAttestationsClient, error) { + if c.fallbackClient != nil { + return c.fallbackClient.StreamAttestations(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.StreamAttestations is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiBeaconChainClient) StreamIndexedAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamIndexedAttestationsClient, error) { + if c.fallbackClient != nil { + return c.fallbackClient.StreamIndexedAttestations(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.StreamIndexedAttestations is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) AttestationPool(ctx context.Context, in *ethpb.AttestationPoolRequest) (*ethpb.AttestationPoolResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.AttestationPool(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.AttestationPool is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListBeaconBlocks(ctx context.Context, in *ethpb.ListBlocksRequest) (*ethpb.ListBeaconBlocksResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListBeaconBlocks(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListBeaconBlocks is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiBeaconChainClient) StreamBlocks(ctx context.Context, in *ethpb.StreamBlocksRequest) (ethpb.BeaconChain_StreamBlocksClient, error) { + if c.fallbackClient != nil { + return c.fallbackClient.StreamBlocks(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.StreamBlocks is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiBeaconChainClient) StreamChainHead(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamChainHeadClient, error) { + if c.fallbackClient != nil { + return c.fallbackClient.StreamChainHead(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.StreamChainHead is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetChainHead(ctx context.Context, in *empty.Empty) (*ethpb.ChainHead, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetChainHead(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetChainHead is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListBeaconCommittees(ctx context.Context, in *ethpb.ListCommitteesRequest) (*ethpb.BeaconCommittees, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListBeaconCommittees(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListBeaconCommittees is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListValidatorBalances(ctx context.Context, in *ethpb.ListValidatorBalancesRequest) (*ethpb.ValidatorBalances, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListValidatorBalances(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListValidatorBalances is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListValidators(ctx context.Context, in *ethpb.ListValidatorsRequest) (*ethpb.Validators, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListValidators(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListValidators is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetValidator(ctx context.Context, in *ethpb.GetValidatorRequest) (*ethpb.Validator, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetValidator(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetValidator is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetValidatorActiveSetChanges(ctx context.Context, in *ethpb.GetValidatorActiveSetChangesRequest) (*ethpb.ActiveSetChanges, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetValidatorActiveSetChanges(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetValidatorActiveSetChanges is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetValidatorQueue(ctx context.Context, in *empty.Empty) (*ethpb.ValidatorQueue, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetValidatorQueue(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetValidatorQueue is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetValidatorPerformance(ctx context.Context, in *ethpb.ValidatorPerformanceRequest) (*ethpb.ValidatorPerformanceResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetValidatorPerformance(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetValidatorPerformance is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) ListValidatorAssignments(ctx context.Context, in *ethpb.ListValidatorAssignmentsRequest) (*ethpb.ValidatorAssignments, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListValidatorAssignments(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.ListValidatorAssignments is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetValidatorParticipation(ctx context.Context, in *ethpb.GetValidatorParticipationRequest) (*ethpb.ValidatorParticipationResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetValidatorParticipation(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetValidatorParticipation is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetBeaconConfig(ctx context.Context, in *empty.Empty) (*ethpb.BeaconConfig, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetBeaconConfig(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetBeaconConfig is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiBeaconChainClient) StreamValidatorsInfo(ctx context.Context) (ethpb.BeaconChain_StreamValidatorsInfoClient, error) { + if c.fallbackClient != nil { + return c.fallbackClient.StreamValidatorsInfo(ctx) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.StreamValidatorsInfo is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) SubmitAttesterSlashing(ctx context.Context, in *ethpb.AttesterSlashing) (*ethpb.SubmitSlashingResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.SubmitAttesterSlashing(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.SubmitAttesterSlashing is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) SubmitProposerSlashing(ctx context.Context, in *ethpb.ProposerSlashing) (*ethpb.SubmitSlashingResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.SubmitProposerSlashing(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.SubmitProposerSlashing is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func (c beaconApiBeaconChainClient) GetIndividualVotes(ctx context.Context, in *ethpb.IndividualVotesRequest) (*ethpb.IndividualVotesRespond, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetIndividualVotes(ctx, in) + } + + // TODO: Implement me + panic("beaconApiBeaconChainClient.GetIndividualVotes is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.") +} + +func NewBeaconApiBeaconChainClientWithFallback(host string, timeout time.Duration, fallbackClient iface.BeaconChainClient) iface.BeaconChainClient { + jsonRestHandler := beaconApiJsonRestHandler{ + httpClient: http.Client{Timeout: timeout}, + host: host, + } + + return &beaconApiBeaconChainClient{ + jsonRestHandler: jsonRestHandler, + fallbackClient: fallbackClient, + } +} diff --git a/validator/client/beacon-api/beacon_api_node_client.go b/validator/client/beacon-api/beacon_api_node_client.go new file mode 100644 index 000000000..6c6b18554 --- /dev/null +++ b/validator/client/beacon-api/beacon_api_node_client.go @@ -0,0 +1,100 @@ +package beacon_api + +import ( + "context" + "net/http" + "time" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" +) + +type beaconApiNodeClient struct { + fallbackClient iface.NodeClient + jsonRestHandler jsonRestHandler +} + +func (c *beaconApiNodeClient) GetSyncStatus(ctx context.Context, in *empty.Empty) (*ethpb.SyncStatus, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetSyncStatus(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetSyncStatus is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) GetGenesis(ctx context.Context, in *empty.Empty) (*ethpb.Genesis, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetGenesis(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetGenesis is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) GetVersion(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetVersion(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetVersion is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) ListImplementedServices(ctx context.Context, in *empty.Empty) (*ethpb.ImplementedServices, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListImplementedServices(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.ListImplementedServices is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) GetHost(ctx context.Context, in *empty.Empty) (*ethpb.HostData, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetHost(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetHost is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) GetPeer(ctx context.Context, in *ethpb.PeerRequest) (*ethpb.Peer, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetPeer(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetPeer is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) ListPeers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) { + if c.fallbackClient != nil { + return c.fallbackClient.ListPeers(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.ListPeers is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func (c *beaconApiNodeClient) GetETH1ConnectionStatus(ctx context.Context, in *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) { + if c.fallbackClient != nil { + return c.fallbackClient.GetETH1ConnectionStatus(ctx, in) + } + + // TODO: Implement me + panic("beaconApiNodeClient.GetETH1ConnectionStatus is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.") +} + +func NewNodeClientWithFallback(host string, timeout time.Duration, fallbackClient iface.NodeClient) iface.NodeClient { + jsonRestHandler := beaconApiJsonRestHandler{ + httpClient: http.Client{Timeout: timeout}, + host: host, + } + + return &beaconApiNodeClient{ + jsonRestHandler: jsonRestHandler, + fallbackClient: fallbackClient, + } +} diff --git a/validator/client/beacon-api/beacon_api_slasher_client.go b/validator/client/beacon-api/beacon_api_slasher_client.go new file mode 100644 index 000000000..752ff63bf --- /dev/null +++ b/validator/client/beacon-api/beacon_api_slasher_client.go @@ -0,0 +1,55 @@ +package beacon_api + +import ( + "context" + "net/http" + "time" + + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" +) + +type beaconApiSlasherClient struct { + fallbackClient iface.SlasherClient + jsonRestHandler jsonRestHandler +} + +func (c beaconApiSlasherClient) IsSlashableAttestation(ctx context.Context, in *ethpb.IndexedAttestation) (*ethpb.AttesterSlashingResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.IsSlashableAttestation(ctx, in) + } + + // TODO: Implement me + panic("beaconApiSlasherClient.IsSlashableAttestation is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiSlasherClientWithFallback.") +} + +func (c beaconApiSlasherClient) IsSlashableBlock(ctx context.Context, in *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashingResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.IsSlashableBlock(ctx, in) + } + + // TODO: Implement me + panic("beaconApiSlasherClient.IsSlashableBlock is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiSlasherClientWithFallback.") +} + +// Deprecated: Do not use. +func (c beaconApiSlasherClient) HighestAttestations(ctx context.Context, in *ethpb.HighestAttestationRequest) (*ethpb.HighestAttestationResponse, error) { + if c.fallbackClient != nil { + return c.fallbackClient.HighestAttestations(ctx, in) + } + + // TODO: Implement me + panic("beaconApiSlasherClient.HighestAttestations is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiSlasherClientWithFallback.") +} + +func NewSlasherClientWithFallback(host string, timeout time.Duration, fallbackClient iface.SlasherClient) iface.SlasherClient { + jsonRestHandler := beaconApiJsonRestHandler{ + httpClient: http.Client{Timeout: timeout}, + host: host, + } + + return &beaconApiSlasherClient{ + jsonRestHandler: jsonRestHandler, + fallbackClient: fallbackClient, + } +} diff --git a/validator/client/beacon-chain-client-factory/BUILD.bazel b/validator/client/beacon-chain-client-factory/BUILD.bazel new file mode 100644 index 000000000..369c12271 --- /dev/null +++ b/validator/client/beacon-chain-client-factory/BUILD.bazel @@ -0,0 +1,15 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["beacon_chain_client_factory.go"], + importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory", + visibility = ["//visibility:public"], + deps = [ + "//config/features:go_default_library", + "//validator/client/beacon-api:go_default_library", + "//validator/client/grpc-api:go_default_library", + "//validator/client/iface:go_default_library", + "//validator/helpers:go_default_library", + ], +) diff --git a/validator/client/beacon-chain-client-factory/beacon_chain_client_factory.go b/validator/client/beacon-chain-client-factory/beacon_chain_client_factory.go new file mode 100644 index 000000000..ddddeabcd --- /dev/null +++ b/validator/client/beacon-chain-client-factory/beacon_chain_client_factory.go @@ -0,0 +1,20 @@ +package validator_client_factory + +import ( + "github.com/prysmaticlabs/prysm/v4/config/features" + beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api" + grpcApi "github.com/prysmaticlabs/prysm/v4/validator/client/grpc-api" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers" +) + +func NewBeaconChainClient(validatorConn validatorHelpers.NodeConnection) iface.BeaconChainClient { + grpcClient := grpcApi.NewGrpcBeaconChainClient(validatorConn.GetGrpcClientConn()) + featureFlags := features.Get() + + if featureFlags.EnableBeaconRESTApi { + return beaconApi.NewBeaconApiBeaconChainClientWithFallback(validatorConn.GetBeaconApiUrl(), validatorConn.GetBeaconApiTimeout(), grpcClient) + } else { + return grpcClient + } +} diff --git a/validator/client/grpc-api/BUILD.bazel b/validator/client/grpc-api/BUILD.bazel index 47b51f995..aba007dc4 100644 --- a/validator/client/grpc-api/BUILD.bazel +++ b/validator/client/grpc-api/BUILD.bazel @@ -2,7 +2,12 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["grpc_validator_client.go"], + srcs = [ + "grpc_beacon_chain_client.go", + "grpc_node_client.go", + "grpc_slasher_client.go", + "grpc_validator_client.go", + ], importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/grpc-api", visibility = ["//validator:__subpackages__"], deps = [ diff --git a/validator/client/grpc-api/grpc_beacon_chain_client.go b/validator/client/grpc-api/grpc_beacon_chain_client.go new file mode 100644 index 000000000..f49b73512 --- /dev/null +++ b/validator/client/grpc-api/grpc_beacon_chain_client.go @@ -0,0 +1,115 @@ +package grpc_api + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + "google.golang.org/grpc" +) + +type grpcBeaconChainClient struct { + beaconChainClient ethpb.BeaconChainClient +} + +func (c *grpcBeaconChainClient) ListAttestations(ctx context.Context, in *ethpb.ListAttestationsRequest) (*ethpb.ListAttestationsResponse, error) { + return c.beaconChainClient.ListAttestations(ctx, in) +} + +func (c *grpcBeaconChainClient) ListIndexedAttestations(ctx context.Context, in *ethpb.ListIndexedAttestationsRequest) (*ethpb.ListIndexedAttestationsResponse, error) { + return c.beaconChainClient.ListIndexedAttestations(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcBeaconChainClient) StreamAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamAttestationsClient, error) { + return c.beaconChainClient.StreamAttestations(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcBeaconChainClient) StreamIndexedAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamIndexedAttestationsClient, error) { + return c.beaconChainClient.StreamIndexedAttestations(ctx, in) +} + +func (c *grpcBeaconChainClient) AttestationPool(ctx context.Context, in *ethpb.AttestationPoolRequest) (*ethpb.AttestationPoolResponse, error) { + return c.beaconChainClient.AttestationPool(ctx, in) +} + +func (c *grpcBeaconChainClient) ListBeaconBlocks(ctx context.Context, in *ethpb.ListBlocksRequest) (*ethpb.ListBeaconBlocksResponse, error) { + return c.beaconChainClient.ListBeaconBlocks(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcBeaconChainClient) StreamBlocks(ctx context.Context, in *ethpb.StreamBlocksRequest) (ethpb.BeaconChain_StreamBlocksClient, error) { + return c.beaconChainClient.StreamBlocks(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcBeaconChainClient) StreamChainHead(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamChainHeadClient, error) { + return c.beaconChainClient.StreamChainHead(ctx, in) +} + +func (c *grpcBeaconChainClient) GetChainHead(ctx context.Context, in *empty.Empty) (*ethpb.ChainHead, error) { + return c.beaconChainClient.GetChainHead(ctx, in) +} + +func (c *grpcBeaconChainClient) ListBeaconCommittees(ctx context.Context, in *ethpb.ListCommitteesRequest) (*ethpb.BeaconCommittees, error) { + return c.beaconChainClient.ListBeaconCommittees(ctx, in) +} + +func (c *grpcBeaconChainClient) ListValidatorBalances(ctx context.Context, in *ethpb.ListValidatorBalancesRequest) (*ethpb.ValidatorBalances, error) { + return c.beaconChainClient.ListValidatorBalances(ctx, in) +} + +func (c *grpcBeaconChainClient) ListValidators(ctx context.Context, in *ethpb.ListValidatorsRequest) (*ethpb.Validators, error) { + return c.beaconChainClient.ListValidators(ctx, in) +} + +func (c *grpcBeaconChainClient) GetValidator(ctx context.Context, in *ethpb.GetValidatorRequest) (*ethpb.Validator, error) { + return c.beaconChainClient.GetValidator(ctx, in) +} + +func (c *grpcBeaconChainClient) GetValidatorActiveSetChanges(ctx context.Context, in *ethpb.GetValidatorActiveSetChangesRequest) (*ethpb.ActiveSetChanges, error) { + return c.beaconChainClient.GetValidatorActiveSetChanges(ctx, in) +} + +func (c *grpcBeaconChainClient) GetValidatorQueue(ctx context.Context, in *empty.Empty) (*ethpb.ValidatorQueue, error) { + return c.beaconChainClient.GetValidatorQueue(ctx, in) +} + +func (c *grpcBeaconChainClient) GetValidatorPerformance(ctx context.Context, in *ethpb.ValidatorPerformanceRequest) (*ethpb.ValidatorPerformanceResponse, error) { + return c.beaconChainClient.GetValidatorPerformance(ctx, in) +} + +func (c *grpcBeaconChainClient) ListValidatorAssignments(ctx context.Context, in *ethpb.ListValidatorAssignmentsRequest) (*ethpb.ValidatorAssignments, error) { + return c.beaconChainClient.ListValidatorAssignments(ctx, in) +} + +func (c *grpcBeaconChainClient) GetValidatorParticipation(ctx context.Context, in *ethpb.GetValidatorParticipationRequest) (*ethpb.ValidatorParticipationResponse, error) { + return c.beaconChainClient.GetValidatorParticipation(ctx, in) +} + +func (c *grpcBeaconChainClient) GetBeaconConfig(ctx context.Context, in *empty.Empty) (*ethpb.BeaconConfig, error) { + return c.beaconChainClient.GetBeaconConfig(ctx, in) +} + +// Deprecated: Do not use. +func (c *grpcBeaconChainClient) StreamValidatorsInfo(ctx context.Context) (ethpb.BeaconChain_StreamValidatorsInfoClient, error) { + return c.beaconChainClient.StreamValidatorsInfo(ctx) +} + +func (c *grpcBeaconChainClient) SubmitAttesterSlashing(ctx context.Context, in *ethpb.AttesterSlashing) (*ethpb.SubmitSlashingResponse, error) { + return c.beaconChainClient.SubmitAttesterSlashing(ctx, in) +} + +func (c *grpcBeaconChainClient) SubmitProposerSlashing(ctx context.Context, in *ethpb.ProposerSlashing) (*ethpb.SubmitSlashingResponse, error) { + return c.beaconChainClient.SubmitProposerSlashing(ctx, in) +} + +func (c *grpcBeaconChainClient) GetIndividualVotes(ctx context.Context, in *ethpb.IndividualVotesRequest) (*ethpb.IndividualVotesRespond, error) { + return c.beaconChainClient.GetIndividualVotes(ctx, in) +} + +func NewGrpcBeaconChainClient(cc grpc.ClientConnInterface) iface.BeaconChainClient { + return &grpcBeaconChainClient{ethpb.NewBeaconChainClient(cc)} +} diff --git a/validator/client/grpc-api/grpc_node_client.go b/validator/client/grpc-api/grpc_node_client.go new file mode 100644 index 000000000..da3068e0e --- /dev/null +++ b/validator/client/grpc-api/grpc_node_client.go @@ -0,0 +1,50 @@ +package grpc_api + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + "google.golang.org/grpc" +) + +type grpcNodeClient struct { + nodeClient ethpb.NodeClient +} + +func (c *grpcNodeClient) GetSyncStatus(ctx context.Context, in *empty.Empty) (*ethpb.SyncStatus, error) { + return c.nodeClient.GetSyncStatus(ctx, in) +} + +func (c *grpcNodeClient) GetGenesis(ctx context.Context, in *empty.Empty) (*ethpb.Genesis, error) { + return c.nodeClient.GetGenesis(ctx, in) +} + +func (c *grpcNodeClient) GetVersion(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) { + return c.nodeClient.GetVersion(ctx, in) +} + +func (c *grpcNodeClient) ListImplementedServices(ctx context.Context, in *empty.Empty) (*ethpb.ImplementedServices, error) { + return c.nodeClient.ListImplementedServices(ctx, in) +} + +func (c *grpcNodeClient) GetHost(ctx context.Context, in *empty.Empty) (*ethpb.HostData, error) { + return c.nodeClient.GetHost(ctx, in) +} + +func (c *grpcNodeClient) GetPeer(ctx context.Context, in *ethpb.PeerRequest) (*ethpb.Peer, error) { + return c.nodeClient.GetPeer(ctx, in) +} + +func (c *grpcNodeClient) ListPeers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) { + return c.nodeClient.ListPeers(ctx, in) +} + +func (c *grpcNodeClient) GetETH1ConnectionStatus(ctx context.Context, in *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) { + return c.nodeClient.GetETH1ConnectionStatus(ctx, in) +} + +func NewNodeClient(cc grpc.ClientConnInterface) iface.NodeClient { + return &grpcNodeClient{ethpb.NewNodeClient(cc)} +} diff --git a/validator/client/grpc-api/grpc_slasher_client.go b/validator/client/grpc-api/grpc_slasher_client.go new file mode 100644 index 000000000..d0eb9c52c --- /dev/null +++ b/validator/client/grpc-api/grpc_slasher_client.go @@ -0,0 +1,29 @@ +package grpc_api + +import ( + "context" + + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + "google.golang.org/grpc" +) + +type grpcSlasherClient struct { + slasherClient ethpb.SlasherClient +} + +func (c *grpcSlasherClient) IsSlashableAttestation(ctx context.Context, in *ethpb.IndexedAttestation) (*ethpb.AttesterSlashingResponse, error) { + return c.slasherClient.IsSlashableAttestation(ctx, in) +} + +func (c *grpcSlasherClient) IsSlashableBlock(ctx context.Context, in *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashingResponse, error) { + return c.slasherClient.IsSlashableBlock(ctx, in) +} + +func (c *grpcSlasherClient) HighestAttestations(ctx context.Context, in *ethpb.HighestAttestationRequest) (*ethpb.HighestAttestationResponse, error) { + return c.slasherClient.HighestAttestations(ctx, in) +} + +func NewSlasherClient(cc grpc.ClientConnInterface) iface.SlasherClient { + return &grpcSlasherClient{ethpb.NewSlasherClient(cc)} +} diff --git a/validator/client/iface/BUILD.bazel b/validator/client/iface/BUILD.bazel index cf553b531..582c27f11 100644 --- a/validator/client/iface/BUILD.bazel +++ b/validator/client/iface/BUILD.bazel @@ -3,6 +3,9 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = [ + "beacon_chain_client.go", + "node_client.go", + "slasher_client.go", "validator.go", "validator_client.go", ], diff --git a/validator/client/iface/beacon_chain_client.go b/validator/client/iface/beacon_chain_client.go new file mode 100644 index 000000000..cf613e065 --- /dev/null +++ b/validator/client/iface/beacon_chain_client.go @@ -0,0 +1,39 @@ +package iface + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" +) + +type BeaconChainClient interface { + ListAttestations(ctx context.Context, in *ethpb.ListAttestationsRequest) (*ethpb.ListAttestationsResponse, error) + ListIndexedAttestations(ctx context.Context, in *ethpb.ListIndexedAttestationsRequest) (*ethpb.ListIndexedAttestationsResponse, error) + // Deprecated: Do not use. + StreamAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamAttestationsClient, error) + // Deprecated: Do not use. + StreamIndexedAttestations(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamIndexedAttestationsClient, error) + AttestationPool(ctx context.Context, in *ethpb.AttestationPoolRequest) (*ethpb.AttestationPoolResponse, error) + ListBeaconBlocks(ctx context.Context, in *ethpb.ListBlocksRequest) (*ethpb.ListBeaconBlocksResponse, error) + // Deprecated: Do not use. + StreamBlocks(ctx context.Context, in *ethpb.StreamBlocksRequest) (ethpb.BeaconChain_StreamBlocksClient, error) + // Deprecated: Do not use. + StreamChainHead(ctx context.Context, in *empty.Empty) (ethpb.BeaconChain_StreamChainHeadClient, error) + GetChainHead(ctx context.Context, in *empty.Empty) (*ethpb.ChainHead, error) + ListBeaconCommittees(ctx context.Context, in *ethpb.ListCommitteesRequest) (*ethpb.BeaconCommittees, error) + ListValidatorBalances(ctx context.Context, in *ethpb.ListValidatorBalancesRequest) (*ethpb.ValidatorBalances, error) + ListValidators(ctx context.Context, in *ethpb.ListValidatorsRequest) (*ethpb.Validators, error) + GetValidator(ctx context.Context, in *ethpb.GetValidatorRequest) (*ethpb.Validator, error) + GetValidatorActiveSetChanges(ctx context.Context, in *ethpb.GetValidatorActiveSetChangesRequest) (*ethpb.ActiveSetChanges, error) + GetValidatorQueue(ctx context.Context, in *empty.Empty) (*ethpb.ValidatorQueue, error) + GetValidatorPerformance(ctx context.Context, in *ethpb.ValidatorPerformanceRequest) (*ethpb.ValidatorPerformanceResponse, error) + ListValidatorAssignments(ctx context.Context, in *ethpb.ListValidatorAssignmentsRequest) (*ethpb.ValidatorAssignments, error) + GetValidatorParticipation(ctx context.Context, in *ethpb.GetValidatorParticipationRequest) (*ethpb.ValidatorParticipationResponse, error) + GetBeaconConfig(ctx context.Context, in *empty.Empty) (*ethpb.BeaconConfig, error) + // Deprecated: Do not use. + StreamValidatorsInfo(ctx context.Context) (ethpb.BeaconChain_StreamValidatorsInfoClient, error) + SubmitAttesterSlashing(ctx context.Context, in *ethpb.AttesterSlashing) (*ethpb.SubmitSlashingResponse, error) + SubmitProposerSlashing(ctx context.Context, in *ethpb.ProposerSlashing) (*ethpb.SubmitSlashingResponse, error) + GetIndividualVotes(ctx context.Context, in *ethpb.IndividualVotesRequest) (*ethpb.IndividualVotesRespond, error) +} diff --git a/validator/client/iface/node_client.go b/validator/client/iface/node_client.go new file mode 100644 index 000000000..c307ac817 --- /dev/null +++ b/validator/client/iface/node_client.go @@ -0,0 +1,19 @@ +package iface + +import ( + "context" + + "github.com/golang/protobuf/ptypes/empty" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" +) + +type NodeClient interface { + GetSyncStatus(ctx context.Context, in *empty.Empty) (*ethpb.SyncStatus, error) + GetGenesis(ctx context.Context, in *empty.Empty) (*ethpb.Genesis, error) + GetVersion(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) + ListImplementedServices(ctx context.Context, in *empty.Empty) (*ethpb.ImplementedServices, error) + GetHost(ctx context.Context, in *empty.Empty) (*ethpb.HostData, error) + GetPeer(ctx context.Context, in *ethpb.PeerRequest) (*ethpb.Peer, error) + ListPeers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) + GetETH1ConnectionStatus(ctx context.Context, in *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) +} diff --git a/validator/client/iface/slasher_client.go b/validator/client/iface/slasher_client.go new file mode 100644 index 000000000..d3fd1b2ec --- /dev/null +++ b/validator/client/iface/slasher_client.go @@ -0,0 +1,13 @@ +package iface + +import ( + "context" + + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" +) + +type SlasherClient interface { + IsSlashableAttestation(ctx context.Context, in *ethpb.IndexedAttestation) (*ethpb.AttesterSlashingResponse, error) + IsSlashableBlock(ctx context.Context, in *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashingResponse, error) + HighestAttestations(ctx context.Context, in *ethpb.HighestAttestationRequest) (*ethpb.HighestAttestationResponse, error) +} diff --git a/validator/client/key_reload_test.go b/validator/client/key_reload_test.go index 582e4cf14..be5f934aa 100644 --- a/validator/client/key_reload_test.go +++ b/validator/client/key_reload_test.go @@ -10,8 +10,8 @@ import ( "github.com/prysmaticlabs/prysm/v4/crypto/bls" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/client/testutil" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -36,8 +36,8 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: client, keyManager: km, @@ -75,8 +75,8 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: client, keyManager: km, @@ -111,7 +111,7 @@ func TestValidator_HandleKeyReload(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - client := mock.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, keyManager: km, diff --git a/validator/client/node-client-factory/BUILD.bazel b/validator/client/node-client-factory/BUILD.bazel new file mode 100644 index 000000000..759a5a1cf --- /dev/null +++ b/validator/client/node-client-factory/BUILD.bazel @@ -0,0 +1,15 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["node_client_factory.go"], + importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory", + visibility = ["//visibility:public"], + deps = [ + "//config/features:go_default_library", + "//validator/client/beacon-api:go_default_library", + "//validator/client/grpc-api:go_default_library", + "//validator/client/iface:go_default_library", + "//validator/helpers:go_default_library", + ], +) diff --git a/validator/client/node-client-factory/node_client_factory.go b/validator/client/node-client-factory/node_client_factory.go new file mode 100644 index 000000000..90f60c8c9 --- /dev/null +++ b/validator/client/node-client-factory/node_client_factory.go @@ -0,0 +1,20 @@ +package validator_client_factory + +import ( + "github.com/prysmaticlabs/prysm/v4/config/features" + beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api" + grpcApi "github.com/prysmaticlabs/prysm/v4/validator/client/grpc-api" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers" +) + +func NewNodeClient(validatorConn validatorHelpers.NodeConnection) iface.NodeClient { + grpcClient := grpcApi.NewNodeClient(validatorConn.GetGrpcClientConn()) + featureFlags := features.Get() + + if featureFlags.EnableBeaconRESTApi { + return beaconApi.NewNodeClientWithFallback(validatorConn.GetBeaconApiUrl(), validatorConn.GetBeaconApiTimeout(), grpcClient) + } else { + return grpcClient + } +} diff --git a/validator/client/propose.go b/validator/client/propose.go index 1b60baae8..9147fd7f9 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -198,7 +198,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot primitives.Slot, pubK func ProposeExit( ctx context.Context, validatorClient iface.ValidatorClient, - nodeClient ethpb.NodeClient, + nodeClient iface.NodeClient, signer iface.SigningFunc, pubKey []byte, ) error { diff --git a/validator/client/propose_test.go b/validator/client/propose_test.go index 04bfed23c..183c7d4ae 100644 --- a/validator/client/propose_test.go +++ b/validator/client/propose_test.go @@ -22,9 +22,9 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" "github.com/prysmaticlabs/prysm/v4/testing/util" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" testing2 "github.com/prysmaticlabs/prysm/v4/validator/db/testing" "github.com/prysmaticlabs/prysm/v4/validator/graffiti" logTest "github.com/sirupsen/logrus/hooks/test" @@ -32,9 +32,9 @@ import ( ) type mocks struct { - validatorClient *mock.MockValidatorClient - nodeClient *mock.MockNodeClient - slasherClient *mock.MockSlasherClient + validatorClient *validatormock.MockValidatorClient + nodeClient *validatormock.MockNodeClient + slasherClient *validatormock.MockSlasherClient signfunc func(context.Context, *validatorpb.SignRequest) (bls.Signature, error) } @@ -71,9 +71,9 @@ 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.NewMockValidatorClient(ctrl), - nodeClient: mock.NewMockNodeClient(ctrl), - slasherClient: mock.NewMockSlasherClient(ctrl), + validatorClient: validatormock.NewMockValidatorClient(ctrl), + nodeClient: validatormock.NewMockNodeClient(ctrl), + slasherClient: validatormock.NewMockSlasherClient(ctrl), signfunc: func(ctx context.Context, req *validatorpb.SignRequest) (bls.Signature, error) { return mockSignature{}, nil }, @@ -935,7 +935,7 @@ func TestSignBellatrixBlock(t *testing.T) { func TestGetGraffiti_Ok(t *testing.T) { ctrl := gomock.NewController(t) m := &mocks{ - validatorClient: mock.NewMockValidatorClient(ctrl), + validatorClient: validatormock.NewMockValidatorClient(ctrl), } pubKey := [fieldparams.BLSPubkeyLength]byte{'a'} tests := []struct { @@ -1018,7 +1018,7 @@ func TestGetGraffitiOrdered_Ok(t *testing.T) { valDB := testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}) ctrl := gomock.NewController(t) m := &mocks{ - validatorClient: mock.NewMockValidatorClient(ctrl), + validatorClient: validatormock.NewMockValidatorClient(ctrl), } m.validatorClient.EXPECT(). ValidatorIndex(gomock.Any(), ðpb.ValidatorIndexRequest{PublicKey: pubKey[:]}). diff --git a/validator/client/service.go b/validator/client/service.go index 0cae66175..756cda2be 100644 --- a/validator/client/service.go +++ b/validator/client/service.go @@ -21,7 +21,10 @@ import ( "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet" + beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory" "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory" + slasherClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/slasher-client-factory" validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory" "github.com/prysmaticlabs/prysm/v4/validator/db" "github.com/prysmaticlabs/prysm/v4/validator/graffiti" @@ -188,9 +191,9 @@ func (v *ValidatorService) Start() { valStruct := &validator{ db: v.db, validatorClient: validatorClientFactory.NewValidatorClient(v.conn), - beaconClient: ethpb.NewBeaconChainClient(v.conn.GetGrpcClientConn()), - slashingProtectionClient: ethpb.NewSlasherClient(v.conn.GetGrpcClientConn()), - node: ethpb.NewNodeClient(v.conn.GetGrpcClientConn()), + beaconClient: beaconChainClientFactory.NewBeaconChainClient(v.conn), + slashingProtectionClient: slasherClientFactory.NewSlasherClient(v.conn), + node: nodeClientFactory.NewNodeClient(v.conn), graffiti: v.graffiti, logValidatorBalances: v.logValidatorBalances, emitAccountMetrics: v.emitAccountMetrics, diff --git a/validator/client/slasher-client-factory/BUILD.bazel b/validator/client/slasher-client-factory/BUILD.bazel new file mode 100644 index 000000000..4decbf220 --- /dev/null +++ b/validator/client/slasher-client-factory/BUILD.bazel @@ -0,0 +1,15 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["slasher_client_factory.go"], + importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/slasher-client-factory", + visibility = ["//visibility:public"], + deps = [ + "//config/features:go_default_library", + "//validator/client/beacon-api:go_default_library", + "//validator/client/grpc-api:go_default_library", + "//validator/client/iface:go_default_library", + "//validator/helpers:go_default_library", + ], +) diff --git a/validator/client/slasher-client-factory/slasher_client_factory.go b/validator/client/slasher-client-factory/slasher_client_factory.go new file mode 100644 index 000000000..9d0b2c333 --- /dev/null +++ b/validator/client/slasher-client-factory/slasher_client_factory.go @@ -0,0 +1,20 @@ +package validator_client_factory + +import ( + "github.com/prysmaticlabs/prysm/v4/config/features" + beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api" + grpcApi "github.com/prysmaticlabs/prysm/v4/validator/client/grpc-api" + "github.com/prysmaticlabs/prysm/v4/validator/client/iface" + validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers" +) + +func NewSlasherClient(validatorConn validatorHelpers.NodeConnection) iface.SlasherClient { + grpcClient := grpcApi.NewSlasherClient(validatorConn.GetGrpcClientConn()) + featureFlags := features.Get() + + if featureFlags.EnableBeaconRESTApi { + return beaconApi.NewSlasherClientWithFallback(validatorConn.GetBeaconApiUrl(), validatorConn.GetBeaconApiTimeout(), grpcClient) + } else { + return grpcClient + } +} diff --git a/validator/client/validator.go b/validator/client/validator.go index 71b2c0b6e..7df849a10 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -90,10 +90,10 @@ type validator struct { interopKeysConfig *local.InteropKeymanagerConfig wallet *wallet.Wallet graffitiStruct *graffiti.Graffiti - node ethpb.NodeClient - slashingProtectionClient ethpb.SlasherClient + node iface.NodeClient + slashingProtectionClient iface.SlasherClient db vdb.Database - beaconClient ethpb.BeaconChainClient + beaconClient iface.BeaconChainClient keyManager keymanager.IKeymanager ticker slots.Ticker validatorClient iface.ValidatorClient diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index a3703ee24..5c2f811cf 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -31,6 +31,7 @@ import ( mock2 "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" "github.com/prysmaticlabs/prysm/v4/testing/util" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/v4/validator/client/iface" dbTest "github.com/prysmaticlabs/prysm/v4/validator/db/testing" @@ -141,7 +142,7 @@ func generateMockStatusResponse(pubkeys [][]byte) *ethpb.ValidatorActivationResp func TestWaitForChainStart_SetsGenesisInfo(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) v := validator{ @@ -187,7 +188,7 @@ func TestWaitForChainStart_SetsGenesisInfo(t *testing.T) { func TestWaitForChainStart_SetsGenesisInfo_IncorrectSecondTry(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) v := validator{ @@ -230,7 +231,7 @@ func TestWaitForChainStart_SetsGenesisInfo_IncorrectSecondTry(t *testing.T) { func TestWaitForChainStart_ContextCanceled(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ //keyManager: testKeyManager, @@ -254,7 +255,7 @@ func TestWaitForChainStart_ContextCanceled(t *testing.T) { func TestWaitForChainStart_ReceiveErrorFromStream(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, @@ -271,7 +272,7 @@ func TestWaitForChainStart_ReceiveErrorFromStream(t *testing.T) { func TestCanonicalHeadSlot_FailedRPC(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconChainClient(ctrl) + client := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ beaconClient: client, genesisTime: 1, @@ -287,7 +288,7 @@ func TestCanonicalHeadSlot_FailedRPC(t *testing.T) { func TestCanonicalHeadSlot_OK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockBeaconChainClient(ctrl) + client := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ beaconClient: client, } @@ -305,8 +306,8 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock2.NewMockValidatorClient(ctrl) - beaconClient := mock2.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -343,8 +344,8 @@ func TestWaitMultipleActivation_LogsActivationEpochOK(t *testing.T) { func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock2.NewMockValidatorClient(ctrl) - beaconClient := mock2.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -381,7 +382,7 @@ func TestWaitActivation_NotAllValidatorsActivatedOK(t *testing.T) { func TestWaitSync_ContextCanceled(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - n := mock2.NewMockNodeClient(ctrl) + n := validatormock.NewMockNodeClient(ctrl) v := validator{ node: n, @@ -401,7 +402,7 @@ func TestWaitSync_ContextCanceled(t *testing.T) { func TestWaitSync_NotSyncing(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - n := mock2.NewMockNodeClient(ctrl) + n := validatormock.NewMockNodeClient(ctrl) v := validator{ node: n, @@ -418,7 +419,7 @@ func TestWaitSync_NotSyncing(t *testing.T) { func TestWaitSync_Syncing(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - n := mock2.NewMockNodeClient(ctrl) + n := validatormock.NewMockNodeClient(ctrl) v := validator{ node: n, @@ -440,7 +441,7 @@ func TestWaitSync_Syncing(t *testing.T) { func TestUpdateDuties_DoesNothingWhenNotEpochStart_AlreadyExistingAssignments(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) slot := primitives.Slot(1) v := validator{ @@ -466,7 +467,7 @@ func TestUpdateDuties_DoesNothingWhenNotEpochStart_AlreadyExistingAssignments(t func TestUpdateDuties_ReturnsError(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) @@ -503,7 +504,7 @@ func TestUpdateDuties_ReturnsError(t *testing.T) { func TestUpdateDuties_OK(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) slot := params.BeaconConfig().SlotsPerEpoch privKey, err := bls.RandKey() @@ -562,7 +563,7 @@ func TestUpdateDuties_OK_FilterBlacklistedPublicKeys(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) slot := params.BeaconConfig().SlotsPerEpoch numValidators := 10 @@ -817,7 +818,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, duties: ðpb.DutiesResponse{ @@ -841,7 +842,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { func TestAllValidatorsAreExited_AllExited(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_EXITED}, @@ -862,7 +863,7 @@ func TestAllValidatorsAreExited_AllExited(t *testing.T) { func TestAllValidatorsAreExited_NotAllExited(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_ACTIVE}, @@ -883,7 +884,7 @@ func TestAllValidatorsAreExited_NotAllExited(t *testing.T) { func TestAllValidatorsAreExited_PartialResult(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) statuses := []*ethpb.ValidatorStatusResponse{ {Status: ethpb.ValidatorStatus_EXITED}, @@ -903,7 +904,7 @@ func TestAllValidatorsAreExited_PartialResult(t *testing.T) { func TestAllValidatorsAreExited_NoKeys(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{keyManager: genMockKeymanager(0), validatorClient: client} exited, err := v.AllValidatorsAreExited(context.Background()) require.NoError(t, err) @@ -914,7 +915,7 @@ func TestAllValidatorsAreExited_NoKeys(t *testing.T) { func TestAllValidatorsAreExited_CorrectRequest(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) // Create two different public keys pubKey0 := [fieldparams.BLSPubkeyLength]byte{1, 2, 3, 4} @@ -957,7 +958,7 @@ func TestAllValidatorsAreExited_CorrectRequest(t *testing.T) { func TestService_ReceiveBlocks_NilBlock(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - valClient := mock2.NewMockValidatorClient(ctrl) + valClient := validatormock.NewMockValidatorClient(ctrl) v := validator{ blockFeed: new(event.Feed), validatorClient: valClient, @@ -984,7 +985,7 @@ func TestService_ReceiveBlocks_NilBlock(t *testing.T) { func TestService_ReceiveBlocks_SetHighest(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ validatorClient: client, @@ -1045,7 +1046,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "no doppelganger", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1077,7 +1078,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "multiple doppelganger exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1111,7 +1112,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "single doppelganger exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1145,7 +1146,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "multiple attestations saved", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) km := genMockKeymanager(10) keys, err := km.FetchValidatingPublicKeys(context.Background()) assert.NoError(t, err) @@ -1184,7 +1185,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) { { name: "no history exists", validatorSetter: func(t *testing.T) *validator { - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) // Use only 1 key for deterministic order. km := genMockKeymanager(1) keys, err := km.FetchValidatingPublicKeys(context.Background()) @@ -1397,8 +1398,8 @@ func TestValidator_PushProposerSettings(t *testing.T) { ctrl := gomock.NewController(t) ctx := context.Background() db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}) - client := mock2.NewMockValidatorClient(ctrl) - nodeClient := mock2.NewMockNodeClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) + nodeClient := validatormock.NewMockNodeClient(ctrl) defaultFeeHex := "0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9" byteValueAddress, err := hexutil.Decode("0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9") require.NoError(t, err) @@ -1981,7 +1982,7 @@ func TestValidator_buildPrepProposerReqs_InvalidValidatorIndex(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{validatorClient: client} pubkeys := [][fieldparams.BLSPubkeyLength]byte{{}} @@ -2035,7 +2036,7 @@ func TestValidator_buildPrepProposerReqs_WithoutDefaultConfig(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) client.EXPECT().ValidatorIndex( ctx, @@ -2122,7 +2123,7 @@ func TestValidator_buildPrepProposerReqs_WithDefaultConfig(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) client.EXPECT().ValidatorIndex( ctx, @@ -2214,7 +2215,7 @@ func TestValidator_buildSignedRegReqs_DefaultConfigDisabled(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) signature := blsmock.NewMockSignature(ctrl) signature.EXPECT().Marshal().Return([]byte{}) @@ -2297,7 +2298,7 @@ func TestValidator_buildSignedRegReqs_DefaultConfigEnabled(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) signature := blsmock.NewMockSignature(ctrl) signature.EXPECT().Marshal().Return([]byte{}).Times(2) @@ -2376,7 +2377,7 @@ func TestValidator_buildSignedRegReqs_SignerOnError(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - client := mock2.NewMockValidatorClient(ctrl) + client := validatormock.NewMockValidatorClient(ctrl) v := validator{ signedValidatorRegistrations: map[[48]byte]*ethpb.SignedValidatorRegistrationV1{}, diff --git a/validator/client/wait_for_activation_test.go b/validator/client/wait_for_activation_test.go index bad5f51ad..b8ea758f3 100644 --- a/validator/client/wait_for_activation_test.go +++ b/validator/client/wait_for_activation_test.go @@ -14,6 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" walletMock "github.com/prysmaticlabs/prysm/v4/validator/accounts/testing" "github.com/prysmaticlabs/prysm/v4/validator/keymanager/derived" constant "github.com/prysmaticlabs/prysm/v4/validator/testing" @@ -25,8 +26,8 @@ import ( func TestWaitActivation_ContextCanceled(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -61,8 +62,8 @@ func TestWaitActivation_ContextCanceled(t *testing.T) { func TestWaitActivation_StreamSetupFails_AttemptsToReconnect(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -94,8 +95,8 @@ func TestWaitActivation_StreamSetupFails_AttemptsToReconnect(t *testing.T) { func TestWaitForActivation_ReceiveErrorFromStream_AttemptsReconnection(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -132,8 +133,8 @@ func TestWaitActivation_LogsActivationEpochOK(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -170,8 +171,8 @@ func TestWaitActivation_LogsActivationEpochOK(t *testing.T) { func TestWaitForActivation_Exiting(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -213,8 +214,8 @@ func TestWaitForActivation_RefetchKeys(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) privKey, err := bls.RandKey() require.NoError(t, err) var pubKey [fieldparams.BLSPubkeyLength]byte @@ -268,8 +269,8 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { inactivePubKey: inactivePrivKey, }, } - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: validatorClient, keyManager: km, @@ -342,8 +343,8 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { require.NoError(t, err) err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, derived.DefaultMnemonicLanguage, "", 1) require.NoError(t, err) - validatorClient := mock.NewMockValidatorClient(ctrl) - beaconClient := mock.NewMockBeaconChainClient(ctrl) + validatorClient := validatormock.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockBeaconChainClient(ctrl) v := validator{ validatorClient: validatorClient, keyManager: km, diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index 6ca81c0b2..96efc62a4 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -43,7 +43,9 @@ go_library( "//validator/accounts/petnames:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client:go_default_library", + "//validator/client/beacon-chain-client-factory:go_default_library", "//validator/client/iface:go_default_library", + "//validator/client/node-client-factory:go_default_library", "//validator/client/validator-client-factory:go_default_library", "//validator/db:go_default_library", "//validator/helpers:go_default_library", @@ -107,8 +109,8 @@ go_test( "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/validator-client:go_default_library", "//testing/assert:go_default_library", - "//testing/mock:go_default_library", "//testing/require:go_default_library", + "//testing/validator-mock:go_default_library", "//validator/accounts:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/testing:go_default_library", diff --git a/validator/rpc/accounts_test.go b/validator/rpc/accounts_test.go index d85088304..f40a3422c 100644 --- a/validator/rpc/accounts_test.go +++ b/validator/rpc/accounts_test.go @@ -16,8 +16,8 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" pb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v4/testing/assert" - mock2 "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/accounts" "github.com/prysmaticlabs/prysm/v4/validator/accounts/iface" mock "github.com/prysmaticlabs/prysm/v4/validator/accounts/testing" @@ -187,8 +187,8 @@ func TestServer_VoluntaryExit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() ctx := context.Background() - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) - mockNodeClient := mock2.NewMockNodeClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) + mockNodeClient := validatormock.NewMockNodeClient(ctrl) mockValidatorClient.EXPECT(). ValidatorIndex(gomock.Any(), gomock.Any()). diff --git a/validator/rpc/beacon.go b/validator/rpc/beacon.go index d22599d27..841fc96a3 100644 --- a/validator/rpc/beacon.go +++ b/validator/rpc/beacon.go @@ -14,6 +14,8 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v4/validator/client" + beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory" + nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory" validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory" validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers" "google.golang.org/grpc" @@ -47,8 +49,6 @@ func (s *Server) registerBeaconClient() error { if s.clientWithCert != "" { log.Info("Established secure gRPC connection") } - s.beaconChainClient = ethpb.NewBeaconChainClient(grpcConn) - s.beaconNodeClient = ethpb.NewNodeClient(grpcConn) s.beaconNodeHealthClient = ethpb.NewHealthClient(grpcConn) conn := validatorHelpers.NewNodeConnection( @@ -57,6 +57,8 @@ func (s *Server) registerBeaconClient() error { s.beaconApiTimeout, ) + s.beaconChainClient = beaconChainClientFactory.NewBeaconChainClient(conn) + s.beaconNodeClient = nodeClientFactory.NewNodeClient(conn) s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn) return nil } diff --git a/validator/rpc/beacon_test.go b/validator/rpc/beacon_test.go index 17a2c2ba9..b7aab331b 100644 --- a/validator/rpc/beacon_test.go +++ b/validator/rpc/beacon_test.go @@ -11,15 +11,15 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" pb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v4/testing/assert" - mock2 "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/types/known/timestamppb" ) func TestGetBeaconStatus_NotConnected(t *testing.T) { ctrl := gomock.NewController(t) - nodeClient := mock2.NewMockNodeClient(ctrl) + nodeClient := validatormock.NewMockNodeClient(ctrl) nodeClient.EXPECT().GetSyncStatus( gomock.Any(), // ctx gomock.Any(), @@ -40,8 +40,8 @@ func TestGetBeaconStatus_NotConnected(t *testing.T) { func TestGetBeaconStatus_OK(t *testing.T) { ctrl := gomock.NewController(t) - nodeClient := mock2.NewMockNodeClient(ctrl) - beaconChainClient := mock2.NewMockBeaconChainClient(ctrl) + nodeClient := validatormock.NewMockNodeClient(ctrl) + beaconChainClient := validatormock.NewMockBeaconChainClient(ctrl) nodeClient.EXPECT().GetSyncStatus( gomock.Any(), // ctx gomock.Any(), diff --git a/validator/rpc/server.go b/validator/rpc/server.go index ada558f7c..17daabc17 100644 --- a/validator/rpc/server.go +++ b/validator/rpc/server.go @@ -58,8 +58,8 @@ type Config struct { type Server struct { logsStreamer logs.Streamer streamLogsBufferSize int - beaconChainClient ethpb.BeaconChainClient - beaconNodeClient ethpb.NodeClient + beaconChainClient iface.BeaconChainClient + beaconNodeClient iface.NodeClient beaconNodeValidatorClient iface.ValidatorClient beaconNodeHealthClient ethpb.HealthClient valDB db.Database diff --git a/validator/rpc/standard_api_test.go b/validator/rpc/standard_api_test.go index 6ca8704d2..af866f544 100644 --- a/validator/rpc/standard_api_test.go +++ b/validator/rpc/standard_api_test.go @@ -23,8 +23,8 @@ import ( eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v4/testing/assert" - mock2 "github.com/prysmaticlabs/prysm/v4/testing/mock" "github.com/prysmaticlabs/prysm/v4/testing/require" + validatormock "github.com/prysmaticlabs/prysm/v4/testing/validator-mock" "github.com/prysmaticlabs/prysm/v4/validator/accounts" "github.com/prysmaticlabs/prysm/v4/validator/accounts/iface" mock "github.com/prysmaticlabs/prysm/v4/validator/accounts/testing" @@ -758,7 +758,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.NewMockValidatorClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) m := &mock.MockValidator{} m.SetProposerSettings(tt.args) @@ -791,7 +791,7 @@ func TestServer_ListFeeRecipientByPubKey_BeaconNodeError(t *testing.T) { require.NoError(t, err) ctrl := gomock.NewController(t) - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) mockValidatorClient.EXPECT().GetFeeRecipientByPubKey(gomock.Any(), gomock.Any()).Return(nil, errors.New("custom error")) @@ -815,7 +815,7 @@ func TestServer_ListFeeRecipientByPubKey_NoFeeRecipientSet(t *testing.T) { require.NoError(t, err) ctrl := gomock.NewController(t) - mockValidatorClient := mock2.NewMockValidatorClient(ctrl) + mockValidatorClient := validatormock.NewMockValidatorClient(ctrl) mockValidatorClient.EXPECT().GetFeeRecipientByPubKey(gomock.Any(), gomock.Any()).Return(nil, nil) @@ -860,7 +860,7 @@ func TestServer_FeeRecipientByPubkey(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - beaconClient := mock2.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockValidatorClient(ctrl) ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{}) byteval, err := hexutil.Decode("0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591493") @@ -1208,7 +1208,7 @@ func TestServer_SetGasLimit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - beaconClient := mock2.NewMockValidatorClient(ctrl) + beaconClient := validatormock.NewMockValidatorClient(ctrl) ctx := grpc.NewContextWithServerTransportStream(context.Background(), &runtime.ServerTransportStream{}) pubkey1, err := hexutil.Decode("0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591493")