Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional BeaconState usage in Validators #105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/validatorsopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ type ValidatorsOpts struct {
Indices []phase0.ValidatorIndex
// PubKeys is a list of validator public keys to restrict the returned values. If no public keys are supplied then no filter will be applied.
PubKeys []phase0.BLSPubKey
// WithoutBeaconState prevents the retrieval of BeaconState for large validator sets, which is often much faster but allocates much more memory.
WithoutBeaconState bool
}
16 changes: 9 additions & 7 deletions http/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ func (s *Service) Validators(ctx context.Context,
return nil, errors.New("cannot specify both indices and public keys")
}

if len(opts.Indices) == 0 && len(opts.PubKeys) == 0 {
// Request is for all validators; fetch from state.
return s.validatorsFromState(ctx, opts)
}
if !opts.WithoutBeaconState {
if len(opts.Indices) == 0 && len(opts.PubKeys) == 0 {
// Request is for all validators; fetch from state.
return s.validatorsFromState(ctx, opts)
}

if len(opts.Indices) > indexChunkSizes["default"]*2 || len(opts.PubKeys) > pubKeyChunkSizes["default"]*2 {
// Request is for multiple pages of validators; fetch from state.
return s.validatorsFromState(ctx, opts)
if len(opts.Indices) > indexChunkSizes["default"]*2 || len(opts.PubKeys) > pubKeyChunkSizes["default"]*2 {
// Request is for multiple pages of validators; fetch from state.
return s.validatorsFromState(ctx, opts)
}
}

if len(opts.Indices) > s.indexChunkSize(ctx) || len(opts.PubKeys) > s.pubKeyChunkSize(ctx) {
Expand Down
Loading