diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 24f532fa1c9..f745c0b9bb3 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -234,14 +234,6 @@ func (s *Service) headGenesisValidatorRoot() [32]byte { return bytesutil.ToBytes32(s.head.state.GenesisValidatorRoot()) } -// HasHeadState returns true if head state exists. -func (s *Service) HasHeadState() bool { - s.headLock.RLock() - defer s.headLock.RUnlock() - - return s.hasHeadState() -} - // Returns true if head state exists. // This is the lock free version. func (s *Service) hasHeadState() bool { diff --git a/beacon-chain/blockchain/metrics_test.go b/beacon-chain/blockchain/metrics_test.go index fd653466c81..d77643eb003 100644 --- a/beacon-chain/blockchain/metrics_test.go +++ b/beacon-chain/blockchain/metrics_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" @@ -24,3 +25,14 @@ func TestReportEpochMetrics_BadAttestation(t *testing.T) { err := reportEpochMetrics(context.Background(), s, h) require.ErrorContains(t, "attestation with inclusion delay of 0", err) } + +func TestReportEpochMetrics_SlashedValidatorOutOfBound(t *testing.T) { + h, _ := testutil.DeterministicGenesisState(t, 1) + v, err := h.ValidatorAtIndex(0) + require.NoError(t, err) + v.Slashed = true + require.NoError(t, h.UpdateValidatorAtIndex(0, v)) + require.NoError(t, h.SetCurrentEpochAttestations([]*pb.PendingAttestation{{InclusionDelay: 1, Data: testutil.HydrateAttestationData(ð.AttestationData{})}})) + err = reportEpochMetrics(context.Background(), h, h) + require.ErrorContains(t, "slot 0 out of bounds", err) +} diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 0fa8f22daee..a43efbd7b7b 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -12,6 +12,8 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" + statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/beacon-chain/db" @@ -455,6 +457,20 @@ func TestServiceStop_SaveCachedBlocks(t *testing.T) { require.Equal(t, true, s.beaconDB.HasBlock(ctx, r)) } +func TestProcessChainStartTime_ReceivedFeed(t *testing.T) { + beaconDB := testDB.SetupDB(t) + service := setupBeaconChain(t, beaconDB) + stateChannel := make(chan *feed.Event, 1) + stateSub := service.stateNotifier.StateFeed().Subscribe(stateChannel) + defer stateSub.Unsubscribe() + service.processChainStartTime(context.Background(), time.Now()) + + stateEvent := <-stateChannel + require.Equal(t, int(stateEvent.Type), int(statefeed.Initialized)) + _, ok := stateEvent.Data.(*statefeed.InitializedData) + require.Equal(t, true, ok) +} + func BenchmarkHasBlockDB(b *testing.B) { beaconDB := testDB.SetupDB(b) ctx := context.Background()