From 4f08487d2bb7634b86320e8a313da7a8fd5743f3 Mon Sep 17 00:00:00 2001 From: moshe-blox Date: Thu, 25 Jan 2024 17:13:16 +0200 Subject: [PATCH 1/3] Opt-in to debug endpoint usage in `Validators` --- api/validatorsopts.go | 2 ++ http/validators.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/validatorsopts.go b/api/validatorsopts.go index f3cd8ff3..dc5e5c32 100644 --- a/api/validatorsopts.go +++ b/api/validatorsopts.go @@ -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 + // WithDebugEndpoints enables the use of debug endpoints for faster retrieval of large validator sets. + WithDebugEndpoints bool } diff --git a/http/validators.go b/http/validators.go index 74cb1f1d..8f525bb0 100644 --- a/http/validators.go +++ b/http/validators.go @@ -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.WithDebugEndpoints { + 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) { From 2e5f3d340cff15216cbd2e1a3192d8c41b1ebe82 Mon Sep 17 00:00:00 2001 From: moshe-blox Date: Fri, 2 Feb 2024 13:26:03 +0200 Subject: [PATCH 2/3] Rename `WithDebugEndpoint` to `WithBeaconState` --- api/validatorsopts.go | 5 +++-- http/validators.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/validatorsopts.go b/api/validatorsopts.go index dc5e5c32..bee56aab 100644 --- a/api/validatorsopts.go +++ b/api/validatorsopts.go @@ -26,6 +26,7 @@ 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 - // WithDebugEndpoints enables the use of debug endpoints for faster retrieval of large validator sets. - WithDebugEndpoints bool + // WithBeaconState enables the use of the BeaconState endpoint for faster retrieval of large validator sets. + // This might increase memory usage during the request. + WithBeaconState bool } diff --git a/http/validators.go b/http/validators.go index 3daad12c..2fc10faf 100644 --- a/http/validators.go +++ b/http/validators.go @@ -128,7 +128,7 @@ func (s *Service) Validators(ctx context.Context, return nil, errors.New("cannot specify both indices and public keys") } - if opts.WithDebugEndpoints { + if opts.WithBeaconState { if len(opts.Indices) == 0 && len(opts.PubKeys) == 0 { // Request is for all validators; fetch from state. return s.validatorsFromState(ctx, opts) From 17f5c145f39f55138cce737b6221b99fdbbfe8e2 Mon Sep 17 00:00:00 2001 From: moshe-blox Date: Sun, 4 Feb 2024 11:44:54 +0200 Subject: [PATCH 3/3] opt-out --- api/validatorsopts.go | 5 ++--- http/validators.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/validatorsopts.go b/api/validatorsopts.go index bee56aab..bdef0b8b 100644 --- a/api/validatorsopts.go +++ b/api/validatorsopts.go @@ -26,7 +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 - // WithBeaconState enables the use of the BeaconState endpoint for faster retrieval of large validator sets. - // This might increase memory usage during the request. - WithBeaconState bool + // WithoutBeaconState prevents the retrieval of BeaconState for large validator sets, which is often much faster but allocates much more memory. + WithoutBeaconState bool } diff --git a/http/validators.go b/http/validators.go index 2fc10faf..faf19eff 100644 --- a/http/validators.go +++ b/http/validators.go @@ -128,7 +128,7 @@ func (s *Service) Validators(ctx context.Context, return nil, errors.New("cannot specify both indices and public keys") } - if opts.WithBeaconState { + 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)