Skip to content

Commit

Permalink
fix panic (#12277)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed Apr 14, 2023
1 parent ff1b03a commit f376427
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion beacon-chain/builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (s *Service) Start() {
}

// Stop halts the service.
func (*Service) Stop() error {
func (s *Service) Stop() error {
s.cancel()
return nil
}

Expand All @@ -89,6 +90,9 @@ func (s *Service) SubmitBlindedBlock(ctx context.Context, b interfaces.ReadOnlyS
defer func() {
submitBlindedBlockLatency.Observe(float64(time.Since(start).Milliseconds()))
}()
if s.c == nil {
return nil, ErrNoBuilder
}

return s.c.SubmitBlindedBlock(ctx, b)
}
Expand All @@ -101,6 +105,9 @@ func (s *Service) GetHeader(ctx context.Context, slot primitives.Slot, parentHas
defer func() {
getHeaderLatency.Observe(float64(time.Since(start).Milliseconds()))
}()
if s.c == nil {
return nil, ErrNoBuilder
}

return s.c.GetHeader(ctx, slot, parentHash, pubKey)
}
Expand All @@ -124,6 +131,9 @@ func (s *Service) RegisterValidator(ctx context.Context, reg []*ethpb.SignedVali
defer func() {
registerValidatorLatency.Observe(float64(time.Since(start).Milliseconds()))
}()
if s.c == nil {
return ErrNoBuilder
}

idxs := make([]primitives.ValidatorIndex, 0)
msgs := make([]*ethpb.ValidatorRegistrationV1, 0)
Expand Down
15 changes: 15 additions & 0 deletions beacon-chain/builder/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ func Test_RegisterValidator(t *testing.T) {
require.NoError(t, s.RegisterValidator(ctx, []*eth.SignedValidatorRegistrationV1{{Message: &eth.ValidatorRegistrationV1{Pubkey: pubkey[:], FeeRecipient: feeRecipient[:]}}}))
assert.Equal(t, true, builder.RegisteredVals[pubkey])
}

func Test_BuilderMethodsWithouClient(t *testing.T) {
s, err := NewService(context.Background())
require.NoError(t, err)
assert.Equal(t, false, s.Configured())

_, err = s.GetHeader(context.Background(), 0, [32]byte{}, [48]byte{})
assert.ErrorContains(t, ErrNoBuilder.Error(), err)

_, err = s.SubmitBlindedBlock(context.Background(), nil)
assert.ErrorContains(t, ErrNoBuilder.Error(), err)

err = s.RegisterValidator(context.Background(), nil)
assert.ErrorContains(t, ErrNoBuilder.Error(), err)
}

0 comments on commit f376427

Please sign in to comment.