diff --git a/api/client/beacon/BUILD.bazel b/api/client/beacon/BUILD.bazel index 35c52211d8..6695dd4b18 100644 --- a/api/client/beacon/BUILD.bazel +++ b/api/client/beacon/BUILD.bazel @@ -5,7 +5,6 @@ go_library( srcs = [ "client.go", "doc.go", - "health.go", "log.go", "template.go", ], @@ -13,7 +12,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//api/client:go_default_library", - "//api/client/beacon/iface:go_default_library", "//api/server:go_default_library", "//api/server/structs:go_default_library", "//consensus-types/primitives:go_default_library", @@ -28,15 +26,10 @@ go_library( go_test( name = "go_default_test", - srcs = [ - "client_test.go", - "health_test.go", - ], + srcs = ["client_test.go"], embed = [":go_default_library"], deps = [ "//api/client:go_default_library", - "//api/client/beacon/testing:go_default_library", "//testing/require:go_default_library", - "@org_uber_go_mock//gomock:go_default_library", ], ) diff --git a/api/client/beacon/health/BUILD.bazel b/api/client/beacon/health/BUILD.bazel new file mode 100644 index 0000000000..8a08c7fbfd --- /dev/null +++ b/api/client/beacon/health/BUILD.bazel @@ -0,0 +1,20 @@ +load("@prysm//tools/go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = [ + "health.go", + "interfaces.go", + "mock.go", + ], + importpath = "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health", + visibility = ["//visibility:public"], + deps = ["@org_uber_go_mock//gomock:go_default_library"], +) + +go_test( + name = "go_default_test", + srcs = ["health_test.go"], + embed = [":go_default_library"], + deps = ["@org_uber_go_mock//gomock:go_default_library"], +) diff --git a/api/client/beacon/health.go b/api/client/beacon/health/health.go similarity index 81% rename from api/client/beacon/health.go rename to api/client/beacon/health/health.go index 9b4f088af1..59cfc4b89f 100644 --- a/api/client/beacon/health.go +++ b/api/client/beacon/health/health.go @@ -1,20 +1,18 @@ -package beacon +package health import ( "context" "sync" - - "github.com/prysmaticlabs/prysm/v5/api/client/beacon/iface" ) type NodeHealthTracker struct { isHealthy *bool healthChan chan bool - node iface.HealthNode + node Node sync.RWMutex } -func NewNodeHealthTracker(node iface.HealthNode) *NodeHealthTracker { +func NewTracker(node Node) Tracker { return &NodeHealthTracker{ node: node, healthChan: make(chan bool, 1), @@ -26,7 +24,7 @@ func (n *NodeHealthTracker) HealthUpdates() <-chan bool { return n.healthChan } -func (n *NodeHealthTracker) IsHealthy() bool { +func (n *NodeHealthTracker) IsHealthy(_ context.Context) bool { n.RLock() defer n.RUnlock() if n.isHealthy == nil { diff --git a/api/client/beacon/health_test.go b/api/client/beacon/health/health_test.go similarity index 89% rename from api/client/beacon/health_test.go rename to api/client/beacon/health/health_test.go index a6d3a06278..c3ac1f1caa 100644 --- a/api/client/beacon/health_test.go +++ b/api/client/beacon/health/health_test.go @@ -1,11 +1,10 @@ -package beacon +package health import ( "context" "sync" "testing" - healthTesting "github.com/prysmaticlabs/prysm/v5/api/client/beacon/testing" "go.uber.org/mock/gomock" ) @@ -24,7 +23,7 @@ func TestNodeHealth_IsHealthy(t *testing.T) { isHealthy: &tt.isHealthy, healthChan: make(chan bool, 1), } - if got := n.IsHealthy(); got != tt.want { + if got := n.IsHealthy(context.Background()); got != tt.want { t.Errorf("IsHealthy() = %v, want %v", got, tt.want) } }) @@ -47,7 +46,7 @@ func TestNodeHealth_UpdateNodeHealth(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := healthTesting.NewMockHealthClient(ctrl) + client := NewMockHealthClient(ctrl) client.EXPECT().IsHealthy(gomock.Any()).Return(tt.newStatus) n := &NodeHealthTracker{ isHealthy: &tt.initial, @@ -80,8 +79,8 @@ func TestNodeHealth_UpdateNodeHealth(t *testing.T) { func TestNodeHealth_Concurrency(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - client := healthTesting.NewMockHealthClient(ctrl) - n := NewNodeHealthTracker(client) + client := NewMockHealthClient(ctrl) + n := NewTracker(client) var wg sync.WaitGroup // Number of goroutines to spawn for both reading and writing @@ -104,7 +103,7 @@ func TestNodeHealth_Concurrency(t *testing.T) { for i := 0; i < numGoroutines; i++ { go func() { defer wg.Done() - _ = n.IsHealthy() // Just read the value + _ = n.IsHealthy(context.Background()) // Just read the value }() } diff --git a/api/client/beacon/iface/health.go b/api/client/beacon/health/interfaces.go similarity index 58% rename from api/client/beacon/iface/health.go rename to api/client/beacon/health/interfaces.go index ac0ad42112..7a188e06a5 100644 --- a/api/client/beacon/iface/health.go +++ b/api/client/beacon/health/interfaces.go @@ -1,13 +1,13 @@ -package iface +package health import "context" -type HealthTracker interface { +type Tracker interface { HealthUpdates() <-chan bool - IsHealthy() bool CheckHealth(ctx context.Context) bool + Node } -type HealthNode interface { +type Node interface { IsHealthy(ctx context.Context) bool } diff --git a/api/client/beacon/testing/mock.go b/api/client/beacon/health/mock.go similarity index 91% rename from api/client/beacon/testing/mock.go rename to api/client/beacon/health/mock.go index 7768d4a7ed..8d6f591281 100644 --- a/api/client/beacon/testing/mock.go +++ b/api/client/beacon/health/mock.go @@ -1,16 +1,15 @@ -package testing +package health import ( "context" "reflect" "sync" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon/iface" "go.uber.org/mock/gomock" ) var ( - _ = iface.HealthNode(&MockHealthClient{}) + _ = Node(&MockHealthClient{}) ) // MockHealthClient is a mock of HealthClient interface. diff --git a/api/client/beacon/iface/BUILD.bazel b/api/client/beacon/iface/BUILD.bazel deleted file mode 100644 index c41efa3d02..0000000000 --- a/api/client/beacon/iface/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["health.go"], - importpath = "github.com/prysmaticlabs/prysm/v5/api/client/beacon/iface", - visibility = ["//visibility:public"], -) diff --git a/api/client/beacon/testing/BUILD.bazel b/api/client/beacon/testing/BUILD.bazel deleted file mode 100644 index 5f21aa5dfa..0000000000 --- a/api/client/beacon/testing/BUILD.bazel +++ /dev/null @@ -1,12 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["mock.go"], - importpath = "github.com/prysmaticlabs/prysm/v5/api/client/beacon/testing", - visibility = ["//visibility:public"], - deps = [ - "//api/client/beacon/iface:go_default_library", - "@org_uber_go_mock//gomock:go_default_library", - ], -) diff --git a/changelog/james-prysm_fix-health-interface.md b/changelog/james-prysm_fix-health-interface.md new file mode 100644 index 0000000000..cf645b64e9 --- /dev/null +++ b/changelog/james-prysm_fix-health-interface.md @@ -0,0 +1,3 @@ +### Ignored + +- fixes health interface usage, we should be using the interface instead of using a pointer in places. \ No newline at end of file diff --git a/testing/validator-mock/BUILD.bazel b/testing/validator-mock/BUILD.bazel index 08bb8fa69b..60cf2a5870 100644 --- a/testing/validator-mock/BUILD.bazel +++ b/testing/validator-mock/BUILD.bazel @@ -13,7 +13,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v5/testing/validator-mock", visibility = ["//visibility:public"], deps = [ - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/validator:go_default_library", diff --git a/testing/validator-mock/node_client_mock.go b/testing/validator-mock/node_client_mock.go index a7826860e9..bca63bc705 100644 --- a/testing/validator-mock/node_client_mock.go +++ b/testing/validator-mock/node_client_mock.go @@ -13,7 +13,7 @@ import ( context "context" reflect "reflect" - beacon "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + health "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" gomock "go.uber.org/mock/gomock" emptypb "google.golang.org/protobuf/types/known/emptypb" @@ -58,10 +58,10 @@ func (mr *MockNodeClientMockRecorder) Genesis(arg0, arg1 any) *gomock.Call { } // HealthTracker mocks base method. -func (m *MockNodeClient) HealthTracker() *beacon.NodeHealthTracker { +func (m *MockNodeClient) HealthTracker() health.Tracker { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "HealthTracker") - ret0, _ := ret[0].(*beacon.NodeHealthTracker) + ret0, _ := ret[0].(health.Tracker) return ret0 } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 2349af9e84..1e633f3cf5 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -24,7 +24,7 @@ go_library( ], deps = [ "//api/client:go_default_library", - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//api/grpc:go_default_library", "//api/server/structs:go_default_library", @@ -121,8 +121,7 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//api/client/beacon:go_default_library", - "//api/client/beacon/testing:go_default_library", + "//api/client/beacon/health:go_default_library", "//async/event:go_default_library", "//beacon-chain/core/signing:go_default_library", "//cache/lru:go_default_library", diff --git a/validator/client/beacon-api/BUILD.bazel b/validator/client/beacon-api/BUILD.bazel index f0659271aa..5be3890bbc 100644 --- a/validator/client/beacon-api/BUILD.bazel +++ b/validator/client/beacon-api/BUILD.bazel @@ -42,7 +42,7 @@ go_library( deps = [ "//api:go_default_library", "//api/apiutil:go_default_library", - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//api/server/structs:go_default_library", "//beacon-chain/core/helpers:go_default_library", diff --git a/validator/client/beacon-api/beacon_api_node_client.go b/validator/client/beacon-api/beacon_api_node_client.go index bdbbc3ccf4..4020591bdb 100644 --- a/validator/client/beacon-api/beacon_api_node_client.go +++ b/validator/client/beacon-api/beacon_api_node_client.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" "github.com/prysmaticlabs/prysm/v5/api/server/structs" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/validator/client/iface" @@ -22,7 +22,7 @@ type beaconApiNodeClient struct { fallbackClient iface.NodeClient jsonRestHandler JsonRestHandler genesisProvider GenesisProvider - healthTracker *beacon.NodeHealthTracker + healthTracker health.Tracker } func (c *beaconApiNodeClient) SyncStatus(ctx context.Context, _ *empty.Empty) (*ethpb.SyncStatus, error) { @@ -107,7 +107,7 @@ func (c *beaconApiNodeClient) IsHealthy(ctx context.Context) bool { return c.jsonRestHandler.Get(ctx, "/eth/v1/node/health", nil) == nil } -func (c *beaconApiNodeClient) HealthTracker() *beacon.NodeHealthTracker { +func (c *beaconApiNodeClient) HealthTracker() health.Tracker { return c.healthTracker } @@ -117,6 +117,6 @@ func NewNodeClientWithFallback(jsonRestHandler JsonRestHandler, fallbackClient i fallbackClient: fallbackClient, genesisProvider: &beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler}, } - b.healthTracker = beacon.NewNodeHealthTracker(b) + b.healthTracker = health.NewTracker(b) return b } diff --git a/validator/client/grpc-api/BUILD.bazel b/validator/client/grpc-api/BUILD.bazel index 0225016f29..ba7637f8c5 100644 --- a/validator/client/grpc-api/BUILD.bazel +++ b/validator/client/grpc-api/BUILD.bazel @@ -12,7 +12,7 @@ go_library( visibility = ["//validator:__subpackages__"], deps = [ "//api/client:go_default_library", - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//api/server/structs:go_default_library", "//beacon-chain/rpc/eth/helpers:go_default_library", diff --git a/validator/client/grpc-api/grpc_node_client.go b/validator/client/grpc-api/grpc_node_client.go index 54bf320a50..a46959d704 100644 --- a/validator/client/grpc-api/grpc_node_client.go +++ b/validator/client/grpc-api/grpc_node_client.go @@ -4,7 +4,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/validator/client/iface" log "github.com/sirupsen/logrus" @@ -17,7 +17,7 @@ var ( type grpcNodeClient struct { nodeClient ethpb.NodeClient - healthTracker *beacon.NodeHealthTracker + healthTracker health.Tracker } func (c *grpcNodeClient) SyncStatus(ctx context.Context, in *empty.Empty) (*ethpb.SyncStatus, error) { @@ -45,12 +45,12 @@ func (c *grpcNodeClient) IsHealthy(ctx context.Context) bool { return true } -func (c *grpcNodeClient) HealthTracker() *beacon.NodeHealthTracker { +func (c *grpcNodeClient) HealthTracker() health.Tracker { return c.healthTracker } func NewNodeClient(cc grpc.ClientConnInterface) iface.NodeClient { g := &grpcNodeClient{nodeClient: ethpb.NewNodeClient(cc)} - g.healthTracker = beacon.NewNodeHealthTracker(g) + g.healthTracker = health.NewTracker(g) return g } diff --git a/validator/client/iface/BUILD.bazel b/validator/client/iface/BUILD.bazel index f949235436..4583e279d2 100644 --- a/validator/client/iface/BUILD.bazel +++ b/validator/client/iface/BUILD.bazel @@ -12,7 +12,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v5/validator/client/iface", visibility = ["//visibility:public"], deps = [ - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//config/fieldparams:go_default_library", "//config/proposer:go_default_library", diff --git a/validator/client/iface/node_client.go b/validator/client/iface/node_client.go index 7f6b80d7d7..aa4a692659 100644 --- a/validator/client/iface/node_client.go +++ b/validator/client/iface/node_client.go @@ -4,7 +4,7 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) @@ -13,5 +13,5 @@ type NodeClient interface { Genesis(ctx context.Context, in *empty.Empty) (*ethpb.Genesis, error) Version(ctx context.Context, in *empty.Empty) (*ethpb.Version, error) Peers(ctx context.Context, in *empty.Empty) (*ethpb.Peers, error) - HealthTracker() *beacon.NodeHealthTracker + HealthTracker() health.Tracker } diff --git a/validator/client/iface/validator.go b/validator/client/iface/validator.go index 354e92a5bf..0518b81436 100644 --- a/validator/client/iface/validator.go +++ b/validator/client/iface/validator.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" "github.com/prysmaticlabs/prysm/v5/api/client/event" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/proposer" @@ -67,7 +67,7 @@ type Validator interface { Graffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]byte, error) SetGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, graffiti []byte) error DeleteGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) error - HealthTracker() *beacon.NodeHealthTracker + HealthTracker() health.Tracker Host() string ChangeHost() } diff --git a/validator/client/runner.go b/validator/client/runner.go index 49129f6528..830ef4ff5d 100644 --- a/validator/client/runner.go +++ b/validator/client/runner.go @@ -73,7 +73,7 @@ func run(ctx context.Context, v iface.Validator) { close(accountsChangedChan) return // Exit if context is canceled. case slot := <-v.NextSlot(): - if !healthTracker.IsHealthy() { + if !healthTracker.IsHealthy(ctx) { continue } diff --git a/validator/client/runner_test.go b/validator/client/runner_test.go index aee9800da4..9a1edf1e92 100644 --- a/validator/client/runner_test.go +++ b/validator/client/runner_test.go @@ -8,8 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" - healthTesting "github.com/prysmaticlabs/prysm/v5/api/client/beacon/testing" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" "github.com/prysmaticlabs/prysm/v5/async/event" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" @@ -32,8 +31,8 @@ func cancelledContext() context.Context { func TestCancelledContext_CleansUpValidator(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) v := &testutil.FakeValidator{ Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}, Tracker: tracker, @@ -45,8 +44,8 @@ func TestCancelledContext_CleansUpValidator(t *testing.T) { func TestCancelledContext_WaitsForChainStart(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) v := &testutil.FakeValidator{ Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}, Tracker: tracker, @@ -58,8 +57,8 @@ func TestCancelledContext_WaitsForChainStart(t *testing.T) { func TestRetry_On_ConnectionError(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) retry := 10 node.EXPECT().IsHealthy(gomock.Any()).Return(true) v := &testutil.FakeValidator{ @@ -84,8 +83,8 @@ func TestRetry_On_ConnectionError(t *testing.T) { func TestCancelledContext_WaitsForActivation(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) v := &testutil.FakeValidator{ Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}, Tracker: tracker, @@ -97,8 +96,8 @@ func TestCancelledContext_WaitsForActivation(t *testing.T) { func TestUpdateDuties_NextSlot(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -124,8 +123,8 @@ func TestUpdateDuties_HandlesError(t *testing.T) { hook := logTest.NewGlobal() ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -150,8 +149,8 @@ func TestUpdateDuties_HandlesError(t *testing.T) { func TestRoleAt_NextSlot(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -176,8 +175,8 @@ func TestRoleAt_NextSlot(t *testing.T) { func TestAttests_NextSlot(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -203,8 +202,8 @@ func TestAttests_NextSlot(t *testing.T) { func TestProposes_NextSlot(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -231,8 +230,8 @@ func TestProposes_NextSlot(t *testing.T) { func TestBothProposesAndAttests_NextSlot(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() // avoid race condition between the cancellation of the context in the go stream from slot and the setting of IsHealthy _ = tracker.CheckHealth(context.Background()) @@ -264,8 +263,8 @@ func TestKeyReload_ActiveKey(t *testing.T) { km := &mockKeymanager{} ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() v := &testutil.FakeValidator{Km: km, Tracker: tracker} ac := make(chan [][fieldparams.BLSPubkeyLength]byte) @@ -283,8 +282,8 @@ func TestKeyReload_NoActiveKey(t *testing.T) { km := &mockKeymanager{} ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() v := &testutil.FakeValidator{Km: km, Tracker: tracker} ac := make(chan [][fieldparams.BLSPubkeyLength]byte) @@ -310,8 +309,8 @@ func notActive(t *testing.T) [fieldparams.BLSPubkeyLength]byte { func TestUpdateProposerSettingsAt_EpochStart(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() v := &testutil.FakeValidator{Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}, Tracker: tracker} err := v.SetProposerSettings(context.Background(), &proposer.Settings{ @@ -340,8 +339,8 @@ func TestUpdateProposerSettingsAt_EpochStart(t *testing.T) { func TestUpdateProposerSettingsAt_EpochEndOk(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - node := healthTesting.NewMockHealthClient(ctrl) - tracker := beacon.NewNodeHealthTracker(node) + node := health.NewMockHealthClient(ctrl) + tracker := health.NewTracker(node) node.EXPECT().IsHealthy(gomock.Any()).Return(true).AnyTimes() v := &testutil.FakeValidator{ Km: &mockKeymanager{accountsChangedFeed: &event.Feed{}}, diff --git a/validator/client/testutil/BUILD.bazel b/validator/client/testutil/BUILD.bazel index 633d7c976b..830696ca5f 100644 --- a/validator/client/testutil/BUILD.bazel +++ b/validator/client/testutil/BUILD.bazel @@ -11,7 +11,7 @@ go_library( visibility = ["//validator:__subpackages__"], deps = [ "//api/client:go_default_library", - "//api/client/beacon:go_default_library", + "//api/client/beacon/health:go_default_library", "//api/client/event:go_default_library", "//config/fieldparams:go_default_library", "//config/proposer:go_default_library", diff --git a/validator/client/testutil/mock_validator.go b/validator/client/testutil/mock_validator.go index e6a48d5b91..c4f052540a 100644 --- a/validator/client/testutil/mock_validator.go +++ b/validator/client/testutil/mock_validator.go @@ -7,7 +7,7 @@ import ( "time" api "github.com/prysmaticlabs/prysm/v5/api/client" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" "github.com/prysmaticlabs/prysm/v5/api/client/event" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/proposer" @@ -60,7 +60,7 @@ type FakeValidator struct { ProposerSettingWait time.Duration Km keymanager.IKeymanager graffiti string - Tracker *beacon.NodeHealthTracker + Tracker health.Tracker AttSubmitted chan interface{} BlockProposed chan interface{} } @@ -318,7 +318,7 @@ func (*FakeValidator) EventStreamIsRunning() bool { return true } -func (fv *FakeValidator) HealthTracker() *beacon.NodeHealthTracker { +func (fv *FakeValidator) HealthTracker() health.Tracker { return fv.Tracker } diff --git a/validator/client/validator.go b/validator/client/validator.go index 142ca8cf37..12767dbb5f 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -21,7 +21,7 @@ import ( lru "github.com/hashicorp/golang-lru" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/client" - "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/api/client/beacon/health" eventClient "github.com/prysmaticlabs/prysm/v5/api/client/event" "github.com/prysmaticlabs/prysm/v5/api/server/structs" "github.com/prysmaticlabs/prysm/v5/async/event" @@ -1169,7 +1169,7 @@ func (v *validator) EventStreamIsRunning() bool { return v.validatorClient.EventStreamIsRunning() } -func (v *validator) HealthTracker() *beacon.NodeHealthTracker { +func (v *validator) HealthTracker() health.Tracker { return v.nodeClient.HealthTracker() }