Skip to content

Commit

Permalink
Fix validators chunked vs state decision.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 3, 2024
1 parent 595a7a6 commit 644acdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func (s *Service) get(ctx context.Context, endpoint string, query string, opts *
// Prefer SSZ, JSON if not.
req.Header.Set("Accept", "application/octet-stream;q=1,application/json;q=0.9")
}
span.AddEvent("Sending request")

resp, err := s.client.Do(req)
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion http/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/attestantio/go-eth2-client/api"
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
)

// indexChunkSizes defines the per-beacon-node size of an index chunk.
Expand Down Expand Up @@ -99,12 +101,17 @@ func (s *Service) Validators(ctx context.Context,
*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator],
error,
) {
ctx, span := otel.Tracer("attestantio.go-eth2-client.http").Start(ctx, "Validators")
defer span.End()

if err := s.assertIsActive(ctx); err != nil {
return nil, err
}
if opts == nil {
return nil, client.ErrNoOptions
}
span.SetAttributes(attribute.Int("validators", len(opts.Indices)+len(opts.PubKeys)))

if opts.State == "" {
return nil, errors.Join(errors.New("no state specified"), client.ErrInvalidOptions)
}
Expand All @@ -117,7 +124,7 @@ func (s *Service) Validators(ctx context.Context,
return s.validatorsFromState(ctx, opts)
}

if len(opts.Indices) > s.indexChunkSize(ctx)*16 || len(opts.PubKeys) > s.indexChunkSize(ctx)*16 {
if len(opts.Indices) > s.indexChunkSize(ctx)*16 || len(opts.PubKeys) > s.pubKeyChunkSize(ctx)*16 {
// Request is for multiple pages of validators; fetch from state.
return s.validatorsFromState(ctx, opts)
}
Expand Down Expand Up @@ -185,6 +192,9 @@ func (s *Service) validatorsFromState(ctx context.Context,
*api.Response[map[phase0.ValidatorIndex]*apiv1.Validator],
error,
) {
ctx, span := otel.Tracer("attestantio.go-eth2-client.http").Start(ctx, "validatorsFromState")
defer span.End()

stateResponse, err := s.BeaconState(ctx, &api.BeaconStateOpts{State: opts.State, Common: opts.Common})
if err != nil {
return nil, err
Expand Down

0 comments on commit 644acdf

Please sign in to comment.