builder client: Revert key batching PR #11002 (#11022)

* builder client: Revert key batching PR #11002

* forgot

* gaz
This commit is contained in:
Preston Van Loon 2022-07-11 15:55:08 -05:00 committed by GitHub
parent 5e53d6976e
commit d53f2c7661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 77 deletions

View File

@ -12,7 +12,6 @@ go_library(
deps = [
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//monitoring/tracing:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
@ -20,7 +19,6 @@ go_library(
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
],
)

View File

@ -13,15 +13,12 @@ import (
"time"
"github.com/pkg/errors"
mathprysm "github.com/prysmaticlabs/prysm/math"
"go.opencensus.io/trace"
"golang.org/x/sync/errgroup"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/monitoring/tracing"
v1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
log "github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)
const (
@ -34,8 +31,6 @@ const (
var errMalformedHostname = errors.New("hostname must include port, separated by one colon, like example.com:3500")
var errMalformedRequest = errors.New("required request data are missing")
const registerValidatorBatchLimit = 100
// ClientOpt is a functional option for the Client type (http.Client wrapper)
type ClientOpt func(*Client)
@ -223,36 +218,26 @@ func (c *Client) GetHeader(ctx context.Context, slot types.Slot, parentHash [32]
func (c *Client) RegisterValidator(ctx context.Context, svr []*ethpb.SignedValidatorRegistrationV1) error {
ctx, span := trace.StartSpan(ctx, "builder.client.RegisterValidator")
defer span.End()
span.AddAttributes(trace.Int64Attribute("num_reqs", int64(len(svr))))
if len(svr) == 0 {
err := errors.Wrap(errMalformedRequest, "empty validator registration list")
tracing.AnnotateError(span, err)
return err
}
eg, ctx := errgroup.WithContext(ctx)
for i := 0; i < len(svr); i += registerValidatorBatchLimit {
end := int(mathprysm.Min(uint64(len(svr)), uint64(i+registerValidatorBatchLimit))) // lint:ignore uintcast -- Request will never exceed int.
vs := make([]*SignedValidatorRegistration, 0, registerValidatorBatchLimit)
for j := i; j < end; j++ {
vs = append(vs, &SignedValidatorRegistration{SignedValidatorRegistrationV1: svr[j]})
}
body, err := json.Marshal(vs)
if err != nil {
err := errors.Wrap(err, "error encoding the SignedValidatorRegistration value body in RegisterValidator")
tracing.AnnotateError(span, err)
}
eg.Go(func() error {
ctx, span := trace.StartSpan(ctx, "builder.client.RegisterValidator.Go")
defer span.End()
span.AddAttributes(trace.Int64Attribute("reqs", int64(len(vs))))
_, err = c.do(ctx, http.MethodPost, postRegisterValidatorPath, bytes.NewBuffer(body))
return err
})
vs := make([]*SignedValidatorRegistration, len(svr))
for i := 0; i < len(svr); i++ {
vs[i] = &SignedValidatorRegistration{SignedValidatorRegistrationV1: svr[i]}
}
body, err := json.Marshal(vs)
if err != nil {
err := errors.Wrap(err, "error encoding the SignedValidatorRegistration value body in RegisterValidator")
tracing.AnnotateError(span, err)
return err
}
return eg.Wait()
_, err = c.do(ctx, http.MethodPost, postRegisterValidatorPath, bytes.NewBuffer(body))
return err
}
// SubmitBlindedBlock calls the builder API endpoint that binds the validator to the builder and submits the block.

View File

@ -3,7 +3,6 @@ package builder
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
@ -109,52 +108,6 @@ func TestClient_RegisterValidator(t *testing.T) {
require.NoError(t, c.RegisterValidator(ctx, []*eth.SignedValidatorRegistrationV1{reg}))
}
func TestClient_RegisterValidator_Over100Requests(t *testing.T) {
reqs := make([]*eth.SignedValidatorRegistrationV1, 301)
for i := 0; i < len(reqs); i++ {
reqs[i] = &eth.SignedValidatorRegistrationV1{
Message: &eth.ValidatorRegistrationV1{
FeeRecipient: ezDecode(t, params.BeaconConfig().EthBurnAddressHex),
GasLimit: 23,
Timestamp: 42,
Pubkey: []byte(fmt.Sprint(i)),
},
}
}
var total int
ctx := context.Background()
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
body, err := io.ReadAll(r.Body)
require.NoError(t, r.Body.Close())
require.NoError(t, err)
recvd := make([]*SignedValidatorRegistration, 0)
require.NoError(t, json.Unmarshal(body, &recvd))
if len(recvd) > registerValidatorBatchLimit {
t.Errorf("Number of requests (%d) exceeds limit (%d)", len(recvd), registerValidatorBatchLimit)
}
total += len(recvd)
require.Equal(t, http.MethodPost, r.Method)
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(nil)),
Request: r.Clone(ctx),
}, nil
}),
}
c := &Client{
hc: hc,
baseURL: &url.URL{Host: "localhost:3500", Scheme: "http"},
}
require.NoError(t, c.RegisterValidator(ctx, reqs))
require.Equal(t, len(reqs), total)
}
func TestClient_GetHeader(t *testing.T) {
ctx := context.Background()
expectedPath := "/eth/v1/builder/header/23/0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2/0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a"