diff --git a/api/client/beacon/BUILD.bazel b/api/client/beacon/BUILD.bazel index c8c080eecd..309f70162a 100644 --- a/api/client/beacon/BUILD.bazel +++ b/api/client/beacon/BUILD.bazel @@ -12,7 +12,6 @@ go_library( deps = [ "//api/client:go_default_library", "//beacon-chain/core/helpers:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/beacon:go_default_library", "//beacon-chain/rpc/eth/config:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", diff --git a/api/client/beacon/client.go b/api/client/beacon/client.go index c3cbe38952..f0692fdd3a 100644 --- a/api/client/beacon/client.go +++ b/api/client/beacon/client.go @@ -16,7 +16,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v4/api/client" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/config" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" @@ -306,7 +305,7 @@ func (c *Client) SubmitChangeBLStoExecution(ctx context.Context, request []*shar if resp.StatusCode != http.StatusOK { decoder := json.NewDecoder(resp.Body) decoder.DisallowUnknownFields() - errorJson := &apimiddleware.IndexedVerificationFailureErrorJson{} + errorJson := &shared.IndexedVerificationFailureError{} if err := decoder.Decode(errorJson); err != nil { return errors.Wrapf(err, "failed to decode error JSON for %s", resp.Request.URL) } diff --git a/api/gateway/BUILD.bazel b/api/gateway/BUILD.bazel index eb6fb6d13f..c58d7d49e6 100644 --- a/api/gateway/BUILD.bazel +++ b/api/gateway/BUILD.bazel @@ -14,7 +14,6 @@ go_library( "//validator:__subpackages__", ], deps = [ - "//api/gateway/apimiddleware:go_default_library", "//runtime:go_default_library", "@com_github_gorilla_mux//:go_default_library", "@com_github_grpc_ecosystem_grpc_gateway_v2//runtime:go_default_library", @@ -34,7 +33,6 @@ go_test( srcs = ["gateway_test.go"], embed = [":go_default_library"], deps = [ - "//api/gateway/apimiddleware:go_default_library", "//cmd/beacon-chain/flags:go_default_library", "//testing/assert:go_default_library", "//testing/require:go_default_library", diff --git a/api/gateway/apimiddleware/BUILD.bazel b/api/gateway/apimiddleware/BUILD.bazel deleted file mode 100644 index 6d44e84028..0000000000 --- a/api/gateway/apimiddleware/BUILD.bazel +++ /dev/null @@ -1,43 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "api_middleware.go", - "log.go", - "param_handling.go", - "process_field.go", - "process_request.go", - "structs.go", - ], - importpath = "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware", - visibility = ["//visibility:public"], - deps = [ - "//api:go_default_library", - "//api/grpc:go_default_library", - "//encoding/bytesutil:go_default_library", - "@com_github_ethereum_go_ethereum//common:go_default_library", - "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", - "@com_github_gorilla_mux//:go_default_library", - "@com_github_pkg_errors//:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", - "@com_github_wealdtech_go_bytesutil//:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "param_handling_test.go", - "process_request_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//api:go_default_library", - "//api/grpc:go_default_library", - "//testing/assert:go_default_library", - "//testing/require:go_default_library", - "@com_github_gorilla_mux//:go_default_library", - "@com_github_sirupsen_logrus//hooks/test:go_default_library", - ], -) diff --git a/api/gateway/apimiddleware/api_middleware.go b/api/gateway/apimiddleware/api_middleware.go deleted file mode 100644 index e04b1f3254..0000000000 --- a/api/gateway/apimiddleware/api_middleware.go +++ /dev/null @@ -1,265 +0,0 @@ -package apimiddleware - -import ( - "net/http" - "reflect" - "time" - - "github.com/gorilla/mux" -) - -// ApiProxyMiddleware is a proxy between an Ethereum consensus API HTTP client and grpc-gateway. -// The purpose of the proxy is to handle HTTP requests and gRPC responses in such a way that: -// - Ethereum consensus API requests can be handled by grpc-gateway correctly -// - gRPC responses can be returned as spec-compliant Ethereum consensus API responses -type ApiProxyMiddleware struct { - GatewayAddress string - EndpointCreator EndpointFactory - Timeout time.Duration - router *mux.Router -} - -// EndpointFactory is responsible for creating new instances of Endpoint values. -type EndpointFactory interface { - Create(path string) (*Endpoint, error) - Paths() []string - IsNil() bool -} - -// Endpoint is a representation of an API HTTP endpoint that should be proxied by the middleware. -type Endpoint struct { - Path string // The path of the HTTP endpoint. - GetResponse interface{} // The struct corresponding to the JSON structure used in a GET response. - PostRequest interface{} // The struct corresponding to the JSON structure used in a POST request. - PostResponse interface{} // The struct corresponding to the JSON structure used in a POST response. - DeleteRequest interface{} // The struct corresponding to the JSON structure used in a DELETE request. - DeleteResponse interface{} // The struct corresponding to the JSON structure used in a DELETE response. - RequestURLLiterals []string // Names of URL parameters that should not be base64-encoded. - RequestQueryParams []QueryParam // Query parameters of the request. - Err ErrorJson // The struct corresponding to the error that should be returned in case of a request failure. - Hooks HookCollection // A collection of functions that can be invoked at various stages of the request/response cycle. - CustomHandlers []CustomHandler // Functions that will be executed instead of the default request/response behaviour. -} - -// RunDefault expresses whether the default processing logic should be carried out after running a pre hook. -type RunDefault bool - -// DefaultEndpoint returns an Endpoint with default configuration, e.g. DefaultErrorJson for error handling. -func DefaultEndpoint() Endpoint { - return Endpoint{ - Err: &DefaultErrorJson{}, - } -} - -// QueryParam represents a single query parameter's metadata. -type QueryParam struct { - Name string - Hex bool - Enum bool -} - -// CustomHandler is a function that can be invoked at the very beginning of the request, -// essentially replacing the whole default request/response logic with custom logic for a specific endpoint. -type CustomHandler = func(m *ApiProxyMiddleware, endpoint Endpoint, w http.ResponseWriter, req *http.Request) (handled bool) - -// HookCollection contains hooks that can be used to amend the default request/response cycle with custom logic for a specific endpoint. -type HookCollection struct { - OnPreDeserializeRequestBodyIntoContainer func(endpoint *Endpoint, w http.ResponseWriter, req *http.Request) (RunDefault, ErrorJson) - OnPostDeserializeRequestBodyIntoContainer func(endpoint *Endpoint, w http.ResponseWriter, req *http.Request) ErrorJson - OnPreDeserializeGrpcResponseBodyIntoContainer func([]byte, interface{}) (RunDefault, ErrorJson) - OnPreSerializeMiddlewareResponseIntoJson func(interface{}) (RunDefault, []byte, ErrorJson) -} - -// fieldProcessor applies the processing function f to a value when the tag is present on the field. -type fieldProcessor struct { - tag string - f func(value reflect.Value) error -} - -// Run starts the proxy, registering all proxy endpoints. -func (m *ApiProxyMiddleware) Run(gatewayRouter *mux.Router) { - for _, path := range m.EndpointCreator.Paths() { - gatewayRouter.HandleFunc(path, m.WithMiddleware(path)) - } - m.router = gatewayRouter -} - -// ServeHTTP for the proxy middleware. -func (m *ApiProxyMiddleware) ServeHTTP(w http.ResponseWriter, req *http.Request) { - m.router.ServeHTTP(w, req) -} - -// WithMiddleware wraps the given endpoint handler with the middleware logic. -func (m *ApiProxyMiddleware) WithMiddleware(path string) http.HandlerFunc { - return func(w http.ResponseWriter, req *http.Request) { - endpoint, err := m.EndpointCreator.Create(path) - if err != nil { - log.WithError(err).Errorf("Could not create endpoint for path: %s", path) - return - } - - for _, handler := range endpoint.CustomHandlers { - if handler(m, *endpoint, w, req) { - return - } - } - - if req.Method == "POST" { - if errJson := handlePostRequestForEndpoint(endpoint, w, req); errJson != nil { - WriteError(w, errJson, nil) - return - } - } - - if req.Method == "DELETE" && req.Body != http.NoBody { - if errJson := handleDeleteRequestForEndpoint(endpoint, req); errJson != nil { - WriteError(w, errJson, nil) - return - } - } - - if errJson := m.PrepareRequestForProxying(*endpoint, req); errJson != nil { - WriteError(w, errJson, nil) - return - } - grpcResp, errJson := m.ProxyRequest(req) - if errJson != nil { - WriteError(w, errJson, nil) - return - } - grpcRespBody, errJson := ReadGrpcResponseBody(grpcResp.Body) - if errJson != nil { - WriteError(w, errJson, nil) - return - } - - var respJson []byte - if !GrpcResponseIsEmpty(grpcRespBody) { - respHasError, errJson := HandleGrpcResponseError(endpoint.Err, grpcResp, grpcRespBody, w) - if errJson != nil { - WriteError(w, errJson, nil) - return - } - if respHasError { - return - } - - var resp interface{} - if req.Method == "GET" { - resp = endpoint.GetResponse - } else if req.Method == "DELETE" { - resp = endpoint.DeleteResponse - } else { - resp = endpoint.PostResponse - } - if errJson := deserializeGrpcResponseBodyIntoContainerWrapped(endpoint, grpcRespBody, resp); errJson != nil { - WriteError(w, errJson, nil) - return - } - if errJson := ProcessMiddlewareResponseFields(resp); errJson != nil { - WriteError(w, errJson, nil) - return - } - - respJson, errJson = serializeMiddlewareResponseIntoJsonWrapped(endpoint, respJson, resp) - if errJson != nil { - WriteError(w, errJson, nil) - return - } - } - - if errJson := WriteMiddlewareResponseHeadersAndBody(grpcResp, respJson, w); errJson != nil { - WriteError(w, errJson, nil) - return - } - if errJson := Cleanup(grpcResp.Body); errJson != nil { - WriteError(w, errJson, nil) - return - } - } -} - -func handlePostRequestForEndpoint(endpoint *Endpoint, w http.ResponseWriter, req *http.Request) ErrorJson { - if errJson := deserializeRequestBodyIntoContainerWrapped(endpoint, req, w); errJson != nil { - return errJson - } - if errJson := ProcessRequestContainerFields(endpoint.PostRequest); errJson != nil { - return errJson - } - return SetRequestBodyToRequestContainer(endpoint.PostRequest, req) -} - -func handleDeleteRequestForEndpoint(endpoint *Endpoint, req *http.Request) ErrorJson { - if errJson := DeserializeRequestBodyIntoContainer(req.Body, endpoint.DeleteRequest); errJson != nil { - return errJson - } - if errJson := ProcessRequestContainerFields(endpoint.DeleteRequest); errJson != nil { - return errJson - } - return SetRequestBodyToRequestContainer(endpoint.DeleteRequest, req) -} - -func deserializeRequestBodyIntoContainerWrapped(endpoint *Endpoint, req *http.Request, w http.ResponseWriter) ErrorJson { - runDefault := true - if endpoint.Hooks.OnPreDeserializeRequestBodyIntoContainer != nil { - run, errJson := endpoint.Hooks.OnPreDeserializeRequestBodyIntoContainer(endpoint, w, req) - if errJson != nil { - return errJson - } - if !run { - runDefault = false - } - } - if runDefault { - if errJson := DeserializeRequestBodyIntoContainer(req.Body, endpoint.PostRequest); errJson != nil { - return errJson - } - } - if endpoint.Hooks.OnPostDeserializeRequestBodyIntoContainer != nil { - if errJson := endpoint.Hooks.OnPostDeserializeRequestBodyIntoContainer(endpoint, w, req); errJson != nil { - return errJson - } - } - return nil -} - -func deserializeGrpcResponseBodyIntoContainerWrapped(endpoint *Endpoint, grpcResponseBody []byte, resp interface{}) ErrorJson { - runDefault := true - if endpoint.Hooks.OnPreDeserializeGrpcResponseBodyIntoContainer != nil { - run, errJson := endpoint.Hooks.OnPreDeserializeGrpcResponseBodyIntoContainer(grpcResponseBody, resp) - if errJson != nil { - return errJson - } - if !run { - runDefault = false - } - } - if runDefault { - if errJson := DeserializeGrpcResponseBodyIntoContainer(grpcResponseBody, resp); errJson != nil { - return errJson - } - } - return nil -} - -func serializeMiddlewareResponseIntoJsonWrapped(endpoint *Endpoint, respJson []byte, resp interface{}) ([]byte, ErrorJson) { - runDefault := true - var errJson ErrorJson - if endpoint.Hooks.OnPreSerializeMiddlewareResponseIntoJson != nil { - var run RunDefault - run, respJson, errJson = endpoint.Hooks.OnPreSerializeMiddlewareResponseIntoJson(resp) - if errJson != nil { - return nil, errJson - } - if !run { - runDefault = false - } - } - if runDefault { - respJson, errJson = SerializeMiddlewareResponseIntoJson(resp) - if errJson != nil { - return nil, errJson - } - } - return respJson, nil -} diff --git a/api/gateway/apimiddleware/log.go b/api/gateway/apimiddleware/log.go deleted file mode 100644 index 5ab6a4d90b..0000000000 --- a/api/gateway/apimiddleware/log.go +++ /dev/null @@ -1,5 +0,0 @@ -package apimiddleware - -import "github.com/sirupsen/logrus" - -var log = logrus.WithField("prefix", "apimiddleware") diff --git a/api/gateway/apimiddleware/param_handling.go b/api/gateway/apimiddleware/param_handling.go deleted file mode 100644 index ca7cb716b6..0000000000 --- a/api/gateway/apimiddleware/param_handling.go +++ /dev/null @@ -1,103 +0,0 @@ -package apimiddleware - -import ( - "encoding/base64" - "net/http" - "net/url" - "strings" - - "github.com/gorilla/mux" - butil "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" - "github.com/wealdtech/go-bytesutil" -) - -// HandleURLParameters processes URL parameters, allowing parameterized URLs to be safely and correctly proxied to grpc-gateway. -func HandleURLParameters(url string, req *http.Request, literals []string) ErrorJson { - segments := strings.Split(url, "/") - -segmentsLoop: - for i, s := range segments { - // We only care about segments which are parameterized. - if isRequestParam(s) { - // Don't do anything with parameters which should be forwarded literally to gRPC. - for _, l := range literals { - if s == "{"+l+"}" { - continue segmentsLoop - } - } - - routeVar := mux.Vars(req)[s[1:len(s)-1]] - bRouteVar := []byte(routeVar) - if butil.IsHex(bRouteVar) { - var err error - bRouteVar, err = bytesutil.FromHexString(string(bRouteVar)) - if err != nil { - return InternalServerErrorWithMessage(err, "could not process URL parameter") - } - } - // Converting hex to base64 may result in a value which malforms the URL. - // We use URLEncoding to safely escape such values. - base64RouteVar := base64.URLEncoding.EncodeToString(bRouteVar) - - // Merge segments back into the full URL. - splitPath := strings.Split(req.URL.Path, "/") - splitPath[i] = base64RouteVar - req.URL.Path = strings.Join(splitPath, "/") - } - } - return nil -} - -// HandleQueryParameters processes query parameters, allowing them to be safely and correctly proxied to grpc-gateway. -func HandleQueryParameters(req *http.Request, params []QueryParam) ErrorJson { - queryParams := req.URL.Query() - - normalizeQueryValues(queryParams) - - for key, vals := range queryParams { - for _, p := range params { - if key == p.Name { - if p.Hex { - queryParams.Del(key) - for _, v := range vals { - b := []byte(v) - if butil.IsHex(b) { - var err error - b, err = bytesutil.FromHexString(v) - if err != nil { - return InternalServerErrorWithMessage(err, "could not process query parameter") - } - } - queryParams.Add(key, base64.URLEncoding.EncodeToString(b)) - } - } - if p.Enum { - queryParams.Del(key) - for _, v := range vals { - // gRPC expects uppercase enum values. - queryParams.Add(key, strings.ToUpper(v)) - } - } - } - } - } - req.URL.RawQuery = queryParams.Encode() - return nil -} - -// isRequestParam verifies whether the passed string is a request parameter. -// Request parameters are enclosed in { and }. -func isRequestParam(s string) bool { - return len(s) > 2 && s[0] == '{' && s[len(s)-1] == '}' -} - -func normalizeQueryValues(queryParams url.Values) { - // Replace comma-separated values with individual values. - for key, vals := range queryParams { - splitVals := make([]string, 0) - for _, v := range vals { - splitVals = append(splitVals, strings.Split(v, ",")...) - } - queryParams[key] = splitVals - } -} diff --git a/api/gateway/apimiddleware/param_handling_test.go b/api/gateway/apimiddleware/param_handling_test.go deleted file mode 100644 index 4c9164ac8f..0000000000 --- a/api/gateway/apimiddleware/param_handling_test.go +++ /dev/null @@ -1,124 +0,0 @@ -package apimiddleware - -import ( - "bytes" - "net/http/httptest" - "testing" - - "github.com/gorilla/mux" - "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/require" -) - -func TestHandleURLParameters(t *testing.T) { - var body bytes.Buffer - - t.Run("no_params", func(t *testing.T) { - request := httptest.NewRequest("GET", "http://foo.example/bar", &body) - - errJson := HandleURLParameters("/not_param", request, []string{}) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "/bar", request.URL.Path) - }) - - t.Run("with_params", func(t *testing.T) { - muxVars := make(map[string]string) - muxVars["bar_param"] = "bar" - muxVars["quux_param"] = "quux" - request := httptest.NewRequest("GET", "http://foo.example/bar/baz/quux", &body) - request = mux.SetURLVars(request, muxVars) - - errJson := HandleURLParameters("/{bar_param}/not_param/{quux_param}", request, []string{}) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "/YmFy/baz/cXV1eA==", request.URL.Path) - }) - - t.Run("with_literal", func(t *testing.T) { - muxVars := make(map[string]string) - muxVars["bar_param"] = "bar" - request := httptest.NewRequest("GET", "http://foo.example/bar/baz", &body) - request = mux.SetURLVars(request, muxVars) - - errJson := HandleURLParameters("/{bar_param}/not_param/", request, []string{"bar_param"}) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "/bar/baz", request.URL.Path) - }) - - t.Run("with_hex", func(t *testing.T) { - muxVars := make(map[string]string) - muxVars["hex_param"] = "0x626172" - request := httptest.NewRequest("GET", "http://foo.example/0x626172/baz", &body) - request = mux.SetURLVars(request, muxVars) - - errJson := HandleURLParameters("/{hex_param}/not_param/", request, []string{}) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "/YmFy/baz", request.URL.Path) - }) -} - -func TestHandleQueryParameters(t *testing.T) { - var body bytes.Buffer - - t.Run("regular_params", func(t *testing.T) { - request := httptest.NewRequest("GET", "http://foo.example?bar=bar&baz=baz", &body) - - errJson := HandleQueryParameters(request, []QueryParam{{Name: "bar"}, {Name: "baz"}}) - require.Equal(t, true, errJson == nil) - query := request.URL.Query() - v, ok := query["bar"] - require.Equal(t, true, ok, "query param not found") - require.Equal(t, 1, len(v), "wrong number of query param values") - assert.Equal(t, "bar", v[0]) - v, ok = query["baz"] - require.Equal(t, true, ok, "query param not found") - require.Equal(t, 1, len(v), "wrong number of query param values") - assert.Equal(t, "baz", v[0]) - }) - - t.Run("hex_and_enum_params", func(t *testing.T) { - request := httptest.NewRequest("GET", "http://foo.example?hex=0x626172&baz=baz", &body) - - errJson := HandleQueryParameters(request, []QueryParam{{Name: "hex", Hex: true}, {Name: "baz", Enum: true}}) - require.Equal(t, true, errJson == nil) - query := request.URL.Query() - v, ok := query["hex"] - require.Equal(t, true, ok, "query param not found") - require.Equal(t, 1, len(v), "wrong number of query param values") - assert.Equal(t, "YmFy", v[0]) - v, ok = query["baz"] - require.Equal(t, true, ok, "query param not found") - require.Equal(t, 1, len(v), "wrong number of query param values") - assert.Equal(t, "BAZ", v[0]) - }) -} - -func TestIsRequestParam(t *testing.T) { - tests := []struct { - s string - b bool - }{ - {"", false}, - {"{", false}, - {"}", false}, - {"{}", false}, - {"{x}", true}, - {"{very_long_parameter_name_with_underscores}", true}, - } - for _, tt := range tests { - b := isRequestParam(tt.s) - assert.Equal(t, tt.b, b) - } -} - -func TestNormalizeQueryValues(t *testing.T) { - input := make(map[string][]string) - input["key"] = []string{"value1", "value2,value3,value4", "value5"} - - normalizeQueryValues(input) - require.Equal(t, 5, len(input["key"])) - assert.Equal(t, "value1", input["key"][0]) - assert.Equal(t, "value2", input["key"][1]) - assert.Equal(t, "value3", input["key"][2]) - assert.Equal(t, "value4", input["key"][3]) - assert.Equal(t, "value5", input["key"][4]) -} diff --git a/api/gateway/apimiddleware/process_field.go b/api/gateway/apimiddleware/process_field.go deleted file mode 100644 index d364fdd5c4..0000000000 --- a/api/gateway/apimiddleware/process_field.go +++ /dev/null @@ -1,179 +0,0 @@ -package apimiddleware - -import ( - "encoding/base64" - "fmt" - "math/big" - "reflect" - "strconv" - "strings" - "time" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/pkg/errors" - "github.com/wealdtech/go-bytesutil" -) - -// processField calls each processor function on any field that has the matching tag set. -// It is a recursive function. -func processField(s interface{}, processors []fieldProcessor) error { - kind := reflect.TypeOf(s).Kind() - if kind != reflect.Ptr && kind != reflect.Slice && kind != reflect.Array { - return fmt.Errorf("processing fields of kind '%v' is unsupported", kind) - } - - t := reflect.TypeOf(s).Elem() - v := reflect.Indirect(reflect.ValueOf(s)) - - for i := 0; i < t.NumField(); i++ { - switch v.Field(i).Kind() { - case reflect.Slice: - sliceElem := t.Field(i).Type.Elem() - kind := sliceElem.Kind() - // Recursively process slices to struct pointers. - switch { - case kind == reflect.Ptr && sliceElem.Elem().Kind() == reflect.Struct: - for j := 0; j < v.Field(i).Len(); j++ { - if err := processField(v.Field(i).Index(j).Interface(), processors); err != nil { - return errors.Wrapf(err, "could not process field '%s'", t.Field(i).Name) - } - } - // Process each string in string slices. - case kind == reflect.String: - for _, proc := range processors { - _, hasTag := t.Field(i).Tag.Lookup(proc.tag) - if !hasTag { - continue - } - for j := 0; j < v.Field(i).Len(); j++ { - if err := proc.f(v.Field(i).Index(j)); err != nil { - return errors.Wrapf(err, "could not process field '%s'", t.Field(i).Name) - } - } - } - } - // Recursively process struct pointers. - case reflect.Ptr: - if v.Field(i).Elem().Kind() == reflect.Struct { - if err := processField(v.Field(i).Interface(), processors); err != nil { - return errors.Wrapf(err, "could not process field '%s'", t.Field(i).Name) - } - } - default: - field := t.Field(i) - for _, proc := range processors { - if _, hasTag := field.Tag.Lookup(proc.tag); hasTag { - if err := proc.f(v.Field(i)); err != nil { - return errors.Wrapf(err, "could not process field '%s'", t.Field(i).Name) - } - } - } - } - } - return nil -} - -func hexToBase64Processor(v reflect.Value) error { - if v.String() == "0x" { - v.SetString("") - return nil - } - b, err := bytesutil.FromHexString(v.String()) - if err != nil { - return err - } - v.SetString(base64.StdEncoding.EncodeToString(b)) - return nil -} - -func base64ToHexProcessor(v reflect.Value) error { - if v.String() == "" { - // Empty hex values are represented as "0x". - v.SetString("0x") - return nil - } - b, err := base64.StdEncoding.DecodeString(v.String()) - if err != nil { - return err - } - v.SetString(hexutil.Encode(b)) - return nil -} - -func base64ToChecksumAddressProcessor(v reflect.Value) error { - if v.String() == "" { - // Empty hex values are represented as "0x". - v.SetString("0x") - return nil - } - b, err := base64.StdEncoding.DecodeString(v.String()) - if err != nil { - return err - } - v.SetString(common.BytesToAddress(b).Hex()) - return nil -} - -func base64ToUint256Processor(v reflect.Value) error { - if v.String() == "" { - return nil - } - littleEndian, err := base64.StdEncoding.DecodeString(v.String()) - if err != nil { - return err - } - if len(littleEndian) != 32 { - return errors.New("invalid length for Uint256") - } - - // Integers are stored as little-endian, but - // big.Int expects big-endian. So we need to reverse - // the byte order before decoding. - var bigEndian [32]byte - for i := 0; i < len(littleEndian); i++ { - bigEndian[i] = littleEndian[len(littleEndian)-1-i] - } - var uint256 big.Int - uint256.SetBytes(bigEndian[:]) - v.SetString(uint256.String()) - return nil -} - -func uint256ToBase64Processor(v reflect.Value) error { - if v.String() == "" { - return nil - } - uint256, ok := new(big.Int).SetString(v.String(), 10) - if !ok { - return fmt.Errorf("could not parse Uint256") - } - bigEndian := uint256.Bytes() - if len(bigEndian) > 32 { - return fmt.Errorf("number too big for Uint256") - } - - // Integers are stored as little-endian, but - // big.Int gives big-endian. So we need to reverse - // the byte order before encoding. - var littleEndian [32]byte - for i := 0; i < len(bigEndian); i++ { - littleEndian[i] = bigEndian[len(bigEndian)-1-i] - } - v.SetString(base64.StdEncoding.EncodeToString(littleEndian[:])) - return nil -} - -func enumToLowercaseProcessor(v reflect.Value) error { - v.SetString(strings.ToLower(v.String())) - return nil -} - -func timeToUnixProcessor(v reflect.Value) error { - t, err := time.Parse(time.RFC3339, v.String()) - if err != nil { - return err - } - v.SetString(strconv.FormatUint(uint64(t.Unix()), 10)) - return nil -} diff --git a/api/gateway/apimiddleware/process_request.go b/api/gateway/apimiddleware/process_request.go deleted file mode 100644 index 73e78ffd2a..0000000000 --- a/api/gateway/apimiddleware/process_request.go +++ /dev/null @@ -1,283 +0,0 @@ -package apimiddleware - -import ( - "bytes" - "encoding/json" - "io" - "net" - "net/http" - "strconv" - "strings" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/api" - "github.com/prysmaticlabs/prysm/v4/api/grpc" -) - -// DeserializeRequestBodyIntoContainer deserializes the request's body into an endpoint-specific struct. -func DeserializeRequestBodyIntoContainer(body io.Reader, requestContainer interface{}) ErrorJson { - decoder := json.NewDecoder(body) - decoder.DisallowUnknownFields() - if err := decoder.Decode(&requestContainer); err != nil { - if strings.Contains(err.Error(), "json: unknown field") { - e := errors.Wrap(err, "could not decode request body") - return &DefaultErrorJson{ - Message: e.Error(), - Code: http.StatusBadRequest, - } - } - return InternalServerErrorWithMessage(err, "could not decode request body") - } - return nil -} - -// ProcessRequestContainerFields processes fields of an endpoint-specific container according to field tags. -func ProcessRequestContainerFields(requestContainer interface{}) ErrorJson { - if err := processField(requestContainer, []fieldProcessor{ - { - tag: "hex", - f: hexToBase64Processor, - }, - { - tag: "uint256", - f: uint256ToBase64Processor, - }, - }); err != nil { - return InternalServerErrorWithMessage(err, "could not process request data") - } - return nil -} - -// SetRequestBodyToRequestContainer makes the endpoint-specific container the new body of the request. -func SetRequestBodyToRequestContainer(requestContainer interface{}, req *http.Request) ErrorJson { - // Serialize the struct, which now includes a base64-encoded value, into JSON. - j, err := json.Marshal(requestContainer) - if err != nil { - return InternalServerErrorWithMessage(err, "could not marshal request") - } - // Set the body to the new JSON. - req.Body = io.NopCloser(bytes.NewReader(j)) - req.Header.Set("Content-Length", strconv.Itoa(len(j))) - req.ContentLength = int64(len(j)) - return nil -} - -// PrepareRequestForProxying applies additional logic to the request so that it can be correctly proxied to grpc-gateway. -func (m *ApiProxyMiddleware) PrepareRequestForProxying(endpoint Endpoint, req *http.Request) ErrorJson { - req.URL.Scheme = "http" - req.URL.Host = m.GatewayAddress - req.RequestURI = "" - if errJson := HandleURLParameters(endpoint.Path, req, endpoint.RequestURLLiterals); errJson != nil { - return errJson - } - if errJson := HandleQueryParameters(req, endpoint.RequestQueryParams); errJson != nil { - return errJson - } - // We have to add the prefix after handling parameters because adding the prefix changes URL segment indexing. - req.URL.Path = "/internal" + req.URL.Path - return nil -} - -// ProxyRequest proxies the request to grpc-gateway. -func (m *ApiProxyMiddleware) ProxyRequest(req *http.Request) (*http.Response, ErrorJson) { - // We do not use http.DefaultClient because it does not have any timeout. - netClient := &http.Client{Timeout: m.Timeout} - grpcResp, err := netClient.Do(req) - if err != nil { - if err, ok := err.(net.Error); ok && err.Timeout() { - return nil, TimeoutError() - } - return nil, InternalServerErrorWithMessage(err, "could not proxy request") - } - if grpcResp == nil { - return nil, &DefaultErrorJson{Message: "nil response from gRPC-gateway", Code: http.StatusInternalServerError} - } - return grpcResp, nil -} - -// ReadGrpcResponseBody reads the body from the grpc-gateway's response. -func ReadGrpcResponseBody(r io.Reader) ([]byte, ErrorJson) { - body, err := io.ReadAll(r) - if err != nil { - return nil, InternalServerErrorWithMessage(err, "could not read response body") - } - return body, nil -} - -// HandleGrpcResponseError acts on an error that resulted from a grpc-gateway's response. -// Whether there was an error is indicated by the bool return value. In case of an error, -// there is no need to write to the response because it's taken care of by the function. -func HandleGrpcResponseError(errJson ErrorJson, resp *http.Response, respBody []byte, w http.ResponseWriter) (bool, ErrorJson) { - responseHasError := false - if err := json.Unmarshal(respBody, errJson); err != nil { - return false, InternalServerErrorWithMessage(err, "could not unmarshal error") - } - if errJson.Msg() != "" { - responseHasError = true - // Something went wrong, but the request completed, meaning we can write headers and the error message. - for h, vs := range resp.Header { - for _, v := range vs { - if strings.HasSuffix(h, api.VersionHeader) { - w.Header().Set(api.VersionHeader, v) - } else { - w.Header().Set(h, v) - } - } - } - // Handle gRPC timeout. - if resp.StatusCode == http.StatusGatewayTimeout { - WriteError(w, TimeoutError(), resp.Header) - } else { - // Set code to HTTP code because unmarshalled body contained gRPC code. - errJson.SetCode(resp.StatusCode) - WriteError(w, errJson, resp.Header) - } - } - return responseHasError, nil -} - -// GrpcResponseIsEmpty determines whether the grpc-gateway's response body contains no data. -func GrpcResponseIsEmpty(grpcResponseBody []byte) bool { - return len(grpcResponseBody) == 0 || string(grpcResponseBody) == "{}" -} - -// DeserializeGrpcResponseBodyIntoContainer deserializes the grpc-gateway's response body into an endpoint-specific struct. -func DeserializeGrpcResponseBodyIntoContainer(body []byte, responseContainer interface{}) ErrorJson { - if err := json.Unmarshal(body, &responseContainer); err != nil { - return InternalServerErrorWithMessage(err, "could not unmarshal response") - } - return nil -} - -// ProcessMiddlewareResponseFields processes fields of an endpoint-specific container according to field tags. -func ProcessMiddlewareResponseFields(responseContainer interface{}) ErrorJson { - if err := processField(responseContainer, []fieldProcessor{ - { - tag: "hex", - f: base64ToHexProcessor, - }, - { - tag: "address", - f: base64ToChecksumAddressProcessor, - }, - { - tag: "enum", - f: enumToLowercaseProcessor, - }, - { - tag: "time", - f: timeToUnixProcessor, - }, - { - tag: "uint256", - f: base64ToUint256Processor, - }, - }); err != nil { - return InternalServerErrorWithMessage(err, "could not process response data") - } - return nil -} - -// SerializeMiddlewareResponseIntoJson serializes the endpoint-specific response struct into a JSON representation. -func SerializeMiddlewareResponseIntoJson(responseContainer interface{}) (jsonResponse []byte, errJson ErrorJson) { - j, err := json.Marshal(responseContainer) - if err != nil { - return nil, InternalServerErrorWithMessage(err, "could not marshal response") - } - return j, nil -} - -// WriteMiddlewareResponseHeadersAndBody populates headers and the body of the final response. -func WriteMiddlewareResponseHeadersAndBody(grpcResp *http.Response, responseJson []byte, w http.ResponseWriter) ErrorJson { - var statusCodeHeader string - for h, vs := range grpcResp.Header { - // We don't want to expose any gRPC metadata in the HTTP response, so we skip forwarding metadata headers. - if strings.HasPrefix(h, grpc.MetadataPrefix) { - if h == grpc.WithPrefix(grpc.HttpCodeMetadataKey) { - statusCodeHeader = vs[0] - } else if strings.HasSuffix(h, api.VersionHeader) { - w.Header().Set(api.VersionHeader, vs[0]) - } - } else { - for _, v := range vs { - w.Header().Set(h, v) - } - } - } - if !GrpcResponseIsEmpty(responseJson) { - w.Header().Set("Content-Length", strconv.Itoa(len(responseJson))) - if statusCodeHeader != "" { - code, err := strconv.Atoi(statusCodeHeader) - if err != nil { - return InternalServerErrorWithMessage(err, "could not parse status code") - } - w.WriteHeader(code) - } else { - w.WriteHeader(grpcResp.StatusCode) - } - if _, err := io.Copy(w, io.NopCloser(bytes.NewReader(responseJson))); err != nil { - return InternalServerErrorWithMessage(err, "could not write response message") - } - } else { - w.Header().Set("Content-Length", "0") - w.WriteHeader(grpcResp.StatusCode) - } - return nil -} - -// WriteError writes the error by manipulating headers and the body of the final response. -func WriteError(w http.ResponseWriter, errJson ErrorJson, responseHeader http.Header) { - // Include custom error in the error JSON. - hasCustomError := false - if responseHeader != nil { - customError, ok := responseHeader[grpc.WithPrefix(grpc.CustomErrorMetadataKey)] - if ok { - hasCustomError = true - // Assume header has only one value and read the 0 index. - if err := json.Unmarshal([]byte(customError[0]), errJson); err != nil { - log.WithError(err).Error("Could not unmarshal custom error message") - return - } - } - } - - var j []byte - if hasCustomError { - var err error - j, err = json.Marshal(errJson) - if err != nil { - log.WithError(err).Error("Could not marshal error message") - return - } - } else { - var err error - // We marshal the response body into a DefaultErrorJson if the custom error is not present. - // This is because the ErrorJson argument is the endpoint's error definition, which may contain custom fields. - // In such a scenario marhaling the endpoint's error would populate the resulting JSON - // with these fields even if they are not present in the gRPC header. - d := &DefaultErrorJson{ - Message: errJson.Msg(), - Code: errJson.StatusCode(), - } - j, err = json.Marshal(d) - if err != nil { - log.WithError(err).Error("Could not marshal error message") - return - } - } - - w.Header().Set("Content-Length", strconv.Itoa(len(j))) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(errJson.StatusCode()) - if _, err := io.Copy(w, io.NopCloser(bytes.NewReader(j))); err != nil { - log.WithError(err).Error("Could not write error message") - } -} - -// Cleanup performs final cleanup on the initial response from grpc-gateway. -func Cleanup(grpcResponseBody io.ReadCloser) ErrorJson { - if err := grpcResponseBody.Close(); err != nil { - return InternalServerErrorWithMessage(err, "could not close response body") - } - return nil -} diff --git a/api/gateway/apimiddleware/process_request_test.go b/api/gateway/apimiddleware/process_request_test.go deleted file mode 100644 index a9edf3370d..0000000000 --- a/api/gateway/apimiddleware/process_request_test.go +++ /dev/null @@ -1,435 +0,0 @@ -package apimiddleware - -import ( - "bytes" - "encoding/json" - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/prysmaticlabs/prysm/v4/api" - "github.com/prysmaticlabs/prysm/v4/api/grpc" - "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/require" - "github.com/sirupsen/logrus/hooks/test" -) - -type testRequestContainer struct { - TestString string - TestHexString string `hex:"true"` - TestEmptyHexString string `hex:"true"` - TestUint256String string `uint256:"true"` -} - -func defaultRequestContainer() *testRequestContainer { - return &testRequestContainer{ - TestString: "test string", - TestHexString: "0x666F6F", // hex encoding of "foo" - TestEmptyHexString: "0x", - TestUint256String: "4196", - } -} - -type testResponseContainer struct { - TestString string - TestHex string `hex:"true"` - TestEmptyHex string `hex:"true"` - TestAddress string `address:"true"` - TestEmptyAddress string `address:"true"` - TestUint256 string `uint256:"true"` - TestEnum string `enum:"true"` - TestTime string `time:"true"` -} - -func defaultResponseContainer() *testResponseContainer { - return &testResponseContainer{ - TestString: "test string", - TestHex: "Zm9v", // base64 encoding of "foo" - TestEmptyHex: "", - TestAddress: "Zm9v", - TestEmptyAddress: "", - TestEnum: "Test Enum", - TestTime: "2006-01-02T15:04:05Z", - - // base64 encoding of 4196 in little-endian - TestUint256: "ZBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", - } -} - -type testErrorJson struct { - Message string - Code int - CustomField string -} - -// StatusCode returns the error's underlying error code. -func (e *testErrorJson) StatusCode() int { - return e.Code -} - -// Msg returns the error's underlying message. -func (e *testErrorJson) Msg() string { - return e.Message -} - -// SetCode sets the error's underlying error code. -func (e *testErrorJson) SetCode(code int) { - e.Code = code -} - -// SetMsg sets the error's underlying message. -func (e *testErrorJson) SetMsg(msg string) { - e.Message = msg -} - -func TestDeserializeRequestBodyIntoContainer(t *testing.T) { - t.Run("ok", func(t *testing.T) { - var bodyJson bytes.Buffer - err := json.NewEncoder(&bodyJson).Encode(defaultRequestContainer()) - require.NoError(t, err) - - container := &testRequestContainer{} - errJson := DeserializeRequestBodyIntoContainer(&bodyJson, container) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "test string", container.TestString) - }) - - t.Run("error", func(t *testing.T) { - var bodyJson bytes.Buffer - bodyJson.Write([]byte("foo")) - errJson := DeserializeRequestBodyIntoContainer(&bodyJson, &testRequestContainer{}) - require.NotNil(t, errJson) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not decode request body")) - assert.Equal(t, http.StatusInternalServerError, errJson.StatusCode()) - }) - - t.Run("unknown field", func(t *testing.T) { - var bodyJson bytes.Buffer - bodyJson.Write([]byte("{\"foo\":\"foo\"}")) - errJson := DeserializeRequestBodyIntoContainer(&bodyJson, &testRequestContainer{}) - require.NotNil(t, errJson) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not decode request body")) - assert.Equal(t, http.StatusBadRequest, errJson.StatusCode()) - }) -} - -func TestProcessRequestContainerFields(t *testing.T) { - t.Run("ok", func(t *testing.T) { - container := defaultRequestContainer() - - errJson := ProcessRequestContainerFields(container) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "Zm9v", container.TestHexString) - assert.Equal(t, "", container.TestEmptyHexString) - assert.Equal(t, "ZBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", container.TestUint256String) - }) - - t.Run("error", func(t *testing.T) { - errJson := ProcessRequestContainerFields("foo") - require.NotNil(t, errJson) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not process request data")) - assert.Equal(t, http.StatusInternalServerError, errJson.StatusCode()) - }) -} - -func TestSetRequestBodyToRequestContainer(t *testing.T) { - var body bytes.Buffer - request := httptest.NewRequest("GET", "http://foo.example", &body) - - errJson := SetRequestBodyToRequestContainer(defaultRequestContainer(), request) - require.Equal(t, true, errJson == nil) - container := &testRequestContainer{} - require.NoError(t, json.NewDecoder(request.Body).Decode(container)) - assert.Equal(t, "test string", container.TestString) - contentLengthHeader, ok := request.Header["Content-Length"] - require.Equal(t, true, ok) - require.Equal(t, 1, len(contentLengthHeader), "wrong number of header values") - assert.Equal(t, "108", contentLengthHeader[0]) - assert.Equal(t, int64(108), request.ContentLength) -} - -func TestPrepareRequestForProxying(t *testing.T) { - middleware := &ApiProxyMiddleware{ - GatewayAddress: "http://gateway.example", - } - // We will set some params to make the request more interesting. - endpoint := Endpoint{ - Path: "/{url_param}", - RequestURLLiterals: []string{"url_param"}, - RequestQueryParams: []QueryParam{{Name: "query_param"}}, - } - var body bytes.Buffer - request := httptest.NewRequest("GET", "http://foo.example?query_param=bar", &body) - - errJson := middleware.PrepareRequestForProxying(endpoint, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "http", request.URL.Scheme) - assert.Equal(t, middleware.GatewayAddress, request.URL.Host) - assert.Equal(t, "", request.RequestURI) -} - -func TestReadGrpcResponseBody(t *testing.T) { - var b bytes.Buffer - b.Write([]byte("foo")) - - body, jsonErr := ReadGrpcResponseBody(&b) - require.Equal(t, true, jsonErr == nil) - assert.Equal(t, "foo", string(body)) -} - -func TestHandleGrpcResponseError(t *testing.T) { - response := &http.Response{ - StatusCode: 400, - Header: http.Header{ - "Foo": []string{"foo"}, - "Bar": []string{"bar"}, - }, - } - writer := httptest.NewRecorder() - errJson := &testErrorJson{ - Message: "foo", - Code: 400, - } - b, err := json.Marshal(errJson) - require.NoError(t, err) - - hasError, e := HandleGrpcResponseError(errJson, response, b, writer) - require.Equal(t, true, e == nil) - assert.Equal(t, true, hasError) - v, ok := writer.Header()["Foo"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "foo", v[0]) - v, ok = writer.Header()["Bar"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "bar", v[0]) - assert.Equal(t, 400, errJson.StatusCode()) -} - -func TestGrpcResponseIsEmpty(t *testing.T) { - t.Run("nil", func(t *testing.T) { - assert.Equal(t, true, GrpcResponseIsEmpty(nil)) - }) - t.Run("empty_slice", func(t *testing.T) { - assert.Equal(t, true, GrpcResponseIsEmpty(make([]byte, 0))) - }) - t.Run("empty_brackets", func(t *testing.T) { - assert.Equal(t, true, GrpcResponseIsEmpty([]byte("{}"))) - }) - t.Run("non_empty", func(t *testing.T) { - assert.Equal(t, false, GrpcResponseIsEmpty([]byte("{\"foo\":\"bar\"})"))) - }) -} - -func TestDeserializeGrpcResponseBodyIntoContainer(t *testing.T) { - t.Run("ok", func(t *testing.T) { - body, err := json.Marshal(defaultRequestContainer()) - require.NoError(t, err) - - container := &testRequestContainer{} - errJson := DeserializeGrpcResponseBodyIntoContainer(body, container) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "test string", container.TestString) - }) - - t.Run("error", func(t *testing.T) { - var bodyJson bytes.Buffer - bodyJson.Write([]byte("foo")) - errJson := DeserializeGrpcResponseBodyIntoContainer(bodyJson.Bytes(), &testRequestContainer{}) - require.NotNil(t, errJson) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not unmarshal response")) - assert.Equal(t, http.StatusInternalServerError, errJson.StatusCode()) - }) -} - -func TestProcessMiddlewareResponseFields(t *testing.T) { - t.Run("Ok", func(t *testing.T) { - container := defaultResponseContainer() - - errJson := ProcessMiddlewareResponseFields(container) - require.Equal(t, true, errJson == nil) - assert.Equal(t, "0x666f6f", container.TestHex) - assert.Equal(t, "0x", container.TestEmptyHex) - assert.Equal(t, "0x0000000000000000000000000000000000666F6f", container.TestAddress) - assert.Equal(t, "0x", container.TestEmptyAddress) - assert.Equal(t, "4196", container.TestUint256) - assert.Equal(t, "test enum", container.TestEnum) - assert.Equal(t, "1136214245", container.TestTime) - }) - - t.Run("error", func(t *testing.T) { - errJson := ProcessMiddlewareResponseFields("foo") - require.NotNil(t, errJson) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not process response data")) - assert.Equal(t, http.StatusInternalServerError, errJson.StatusCode()) - }) -} - -func TestSerializeMiddlewareResponseIntoJson(t *testing.T) { - container := defaultResponseContainer() - j, errJson := SerializeMiddlewareResponseIntoJson(container) - assert.Equal(t, true, errJson == nil) - cToDeserialize := &testResponseContainer{} - require.NoError(t, json.Unmarshal(j, cToDeserialize)) - assert.Equal(t, "test string", cToDeserialize.TestString) -} - -func TestWriteMiddlewareResponseHeadersAndBody(t *testing.T) { - t.Run("GET", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{ - "Foo": []string{"foo"}, - grpc.WithPrefix(grpc.HttpCodeMetadataKey): []string{"204"}, - grpc.WithPrefix(api.VersionHeader): []string{"capella"}, - }, - } - container := defaultResponseContainer() - responseJson, err := json.Marshal(container) - require.NoError(t, err) - writer := httptest.NewRecorder() - writer.Body = &bytes.Buffer{} - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, true, errJson == nil) - v, ok := writer.Header()["Foo"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "foo", v[0]) - v, ok = writer.Header()["Content-Length"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "224", v[0]) - v, ok = writer.Header()["Eth-Consensus-Version"] - require.Equal(t, true, ok, "header not found") - assert.Equal(t, "capella", v[0]) - assert.Equal(t, 204, writer.Code) - assert.DeepEqual(t, responseJson, writer.Body.Bytes()) - }) - - t.Run("GET_no_grpc_status_code_header", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{}, - StatusCode: 204, - } - container := defaultResponseContainer() - responseJson, err := json.Marshal(container) - require.NoError(t, err) - writer := httptest.NewRecorder() - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, true, errJson == nil) - assert.Equal(t, 204, writer.Code) - }) - - t.Run("GET_invalid_status_code", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{"Grpc-Metadata-Eth-Consensus-Version": []string{"capella"}}, - } - - // Set invalid status code. - response.Header[grpc.WithPrefix(grpc.HttpCodeMetadataKey)] = []string{"invalid"} - response.Header[grpc.WithPrefix(api.VersionHeader)] = []string{"capella"} - - container := defaultResponseContainer() - responseJson, err := json.Marshal(container) - require.NoError(t, err) - writer := httptest.NewRecorder() - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, false, errJson == nil) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "could not parse status code")) - assert.Equal(t, http.StatusInternalServerError, errJson.StatusCode()) - }) - - t.Run("POST", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{}, - StatusCode: 204, - } - container := defaultResponseContainer() - responseJson, err := json.Marshal(container) - require.NoError(t, err) - writer := httptest.NewRecorder() - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, true, errJson == nil) - assert.Equal(t, 204, writer.Code) - }) - - t.Run("POST_with_response_body", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{}, - StatusCode: 204, - } - container := defaultResponseContainer() - responseJson, err := json.Marshal(container) - require.NoError(t, err) - writer := httptest.NewRecorder() - writer.Body = &bytes.Buffer{} - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, true, errJson == nil) - assert.Equal(t, 204, writer.Code) - assert.DeepEqual(t, responseJson, writer.Body.Bytes()) - }) - - t.Run("POST_with_empty_json_body", func(t *testing.T) { - response := &http.Response{ - Header: http.Header{}, - StatusCode: 204, - } - responseJson, err := json.Marshal(struct{}{}) - require.NoError(t, err) - writer := httptest.NewRecorder() - writer.Body = &bytes.Buffer{} - - errJson := WriteMiddlewareResponseHeadersAndBody(response, responseJson, writer) - require.Equal(t, true, errJson == nil) - assert.Equal(t, 204, writer.Code) - assert.DeepEqual(t, []byte(nil), writer.Body.Bytes()) - assert.Equal(t, "0", writer.Header()["Content-Length"][0]) - }) -} - -func TestWriteError(t *testing.T) { - t.Run("ok", func(t *testing.T) { - responseHeader := http.Header{ - grpc.WithPrefix(grpc.CustomErrorMetadataKey): []string{"{\"CustomField\":\"bar\"}"}, - } - errJson := &testErrorJson{ - Message: "foo", - Code: 500, - } - writer := httptest.NewRecorder() - writer.Body = &bytes.Buffer{} - - WriteError(writer, errJson, responseHeader) - v, ok := writer.Header()["Content-Length"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "48", v[0]) - v, ok = writer.Header()["Content-Type"] - require.Equal(t, true, ok, "header not found") - require.Equal(t, 1, len(v), "wrong number of header values") - assert.Equal(t, "application/json", v[0]) - assert.Equal(t, 500, writer.Code) - eDeserialize := &testErrorJson{} - require.NoError(t, json.Unmarshal(writer.Body.Bytes(), eDeserialize)) - assert.Equal(t, "foo", eDeserialize.Message) - assert.Equal(t, 500, eDeserialize.Code) - assert.Equal(t, "bar", eDeserialize.CustomField) - }) - - t.Run("invalid_custom_error_header", func(t *testing.T) { - logHook := test.NewGlobal() - - responseHeader := http.Header{ - grpc.WithPrefix(grpc.CustomErrorMetadataKey): []string{"invalid"}, - } - - WriteError(httptest.NewRecorder(), &testErrorJson{}, responseHeader) - assert.LogsContain(t, logHook, "Could not unmarshal custom error message") - }) -} diff --git a/api/gateway/apimiddleware/structs.go b/api/gateway/apimiddleware/structs.go deleted file mode 100644 index 7103875b80..0000000000 --- a/api/gateway/apimiddleware/structs.go +++ /dev/null @@ -1,69 +0,0 @@ -package apimiddleware - -import ( - "net/http" - - "github.com/pkg/errors" -) - -// --------------- -// Error handling. -// --------------- - -// ErrorJson describes common functionality of all JSON error representations. -type ErrorJson interface { - StatusCode() int - SetCode(code int) - Msg() string - SetMsg(msg string) -} - -// DefaultErrorJson is a JSON representation of a simple error value, containing only a message and an error code. -type DefaultErrorJson struct { - Message string `json:"message"` - Code int `json:"code"` -} - -// InternalServerErrorWithMessage returns a DefaultErrorJson with 500 code and a custom message. -func InternalServerErrorWithMessage(err error, message string) *DefaultErrorJson { - e := errors.Wrapf(err, message) - return &DefaultErrorJson{ - Message: e.Error(), - Code: http.StatusInternalServerError, - } -} - -// InternalServerError returns a DefaultErrorJson with 500 code. -func InternalServerError(err error) *DefaultErrorJson { - return &DefaultErrorJson{ - Message: err.Error(), - Code: http.StatusInternalServerError, - } -} - -func TimeoutError() *DefaultErrorJson { - return &DefaultErrorJson{ - Message: "Request timeout", - Code: http.StatusRequestTimeout, - } -} - -// StatusCode returns the error's underlying error code. -func (e *DefaultErrorJson) StatusCode() int { - return e.Code -} - -// Msg returns the error's underlying message. -func (e *DefaultErrorJson) Msg() string { - return e.Message -} - -// SetCode sets the error's underlying error code. -func (e *DefaultErrorJson) SetCode(code int) { - e.Code = code -} - -// SetMsg sets the error's underlying message. -func (e *DefaultErrorJson) SetMsg(msg string) { - e.Message = msg -} diff --git a/api/gateway/gateway.go b/api/gateway/gateway.go index 1e76c7287a..32f47dabed 100644 --- a/api/gateway/gateway.go +++ b/api/gateway/gateway.go @@ -11,7 +11,6 @@ import ( "github.com/gorilla/mux" gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" "github.com/prysmaticlabs/prysm/v4/runtime" "github.com/rs/cors" "google.golang.org/grpc" @@ -34,7 +33,6 @@ type PbHandlerRegistration func(context.Context, *gwruntime.ServeMux, *grpc.Clie // MuxHandler is a function that implements the mux handler functionality. type MuxHandler func( - apiMiddlewareHandler *apimiddleware.ApiProxyMiddleware, h http.HandlerFunc, w http.ResponseWriter, req *http.Request, @@ -42,16 +40,15 @@ type MuxHandler func( // Config parameters for setting up the gateway service. type config struct { - maxCallRecvMsgSize uint64 - remoteCert string - gatewayAddr string - remoteAddr string - allowedOrigins []string - apiMiddlewareEndpointFactory apimiddleware.EndpointFactory - muxHandler MuxHandler - pbHandlers []*PbMux - router *mux.Router - timeout time.Duration + maxCallRecvMsgSize uint64 + remoteCert string + gatewayAddr string + remoteAddr string + allowedOrigins []string + muxHandler MuxHandler + pbHandlers []*PbMux + router *mux.Router + timeout time.Duration } // Gateway is the gRPC gateway to serve HTTP JSON traffic as a proxy and forward it to the gRPC server. @@ -60,7 +57,6 @@ type Gateway struct { conn *grpc.ClientConn server *http.Server cancel context.CancelFunc - proxy *apimiddleware.ApiProxyMiddleware ctx context.Context startFailure error } @@ -110,13 +106,9 @@ func (g *Gateway) Start() { corsMux := g.corsMiddleware(g.cfg.router) - if g.cfg.apiMiddlewareEndpointFactory != nil && !g.cfg.apiMiddlewareEndpointFactory.IsNil() { - g.registerApiMiddleware() - } - if g.cfg.muxHandler != nil { g.cfg.router.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - g.cfg.muxHandler(g.proxy, corsMux.ServeHTTP, w, r) + g.cfg.muxHandler(corsMux.ServeHTTP, w, r) }) } @@ -229,13 +221,3 @@ func (g *Gateway) dialUnix(ctx context.Context, addr string) (*grpc.ClientConn, } return grpc.DialContext(ctx, addr, opts...) } - -func (g *Gateway) registerApiMiddleware() { - g.proxy = &apimiddleware.ApiProxyMiddleware{ - GatewayAddress: g.cfg.gatewayAddr, - EndpointCreator: g.cfg.apiMiddlewareEndpointFactory, - Timeout: g.cfg.timeout, - } - log.Info("Starting API middleware") - g.proxy.Run(g.cfg.router) -} diff --git a/api/gateway/gateway_test.go b/api/gateway/gateway_test.go index bba4883ccd..64ec4ba433 100644 --- a/api/gateway/gateway_test.go +++ b/api/gateway/gateway_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/gorilla/mux" - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" "github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -18,36 +17,18 @@ import ( "github.com/urfave/cli/v2" ) -type mockEndpointFactory struct { -} - -func (*mockEndpointFactory) Paths() []string { - return []string{} -} - -func (*mockEndpointFactory) Create(_ string) (*apimiddleware.Endpoint, error) { - return nil, nil -} - -func (*mockEndpointFactory) IsNil() bool { - return false -} - func TestGateway_Customized(t *testing.T) { r := mux.NewRouter() cert := "cert" origins := []string{"origin"} size := uint64(100) - endpointFactory := &mockEndpointFactory{} opts := []Option{ WithRouter(r), WithRemoteCert(cert), WithAllowedOrigins(origins), WithMaxCallRecvMsgSize(size), - WithApiMiddleware(endpointFactory), WithMuxHandler(func( - _ *apimiddleware.ApiProxyMiddleware, _ http.HandlerFunc, _ http.ResponseWriter, _ *http.Request, @@ -63,7 +44,6 @@ func TestGateway_Customized(t *testing.T) { require.Equal(t, 1, len(g.cfg.allowedOrigins)) assert.Equal(t, origins[0], g.cfg.allowedOrigins[0]) assert.Equal(t, size, g.cfg.maxCallRecvMsgSize) - assert.Equal(t, endpointFactory, g.cfg.apiMiddlewareEndpointFactory) } func TestGateway_StartStop(t *testing.T) { @@ -83,7 +63,6 @@ func TestGateway_StartStop(t *testing.T) { WithGatewayAddr(gatewayAddress), WithRemoteAddr(selfAddress), WithMuxHandler(func( - _ *apimiddleware.ApiProxyMiddleware, _ http.HandlerFunc, _ http.ResponseWriter, _ *http.Request, diff --git a/api/gateway/options.go b/api/gateway/options.go index 337aa60ccb..f029314214 100644 --- a/api/gateway/options.go +++ b/api/gateway/options.go @@ -5,7 +5,6 @@ import ( "github.com/gorilla/mux" gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" ) type Option func(g *Gateway) error @@ -70,14 +69,6 @@ func WithMaxCallRecvMsgSize(size uint64) Option { } } -// WithApiMiddleware allows adding an API middleware proxy to the gateway. -func WithApiMiddleware(endpointFactory apimiddleware.EndpointFactory) Option { - return func(g *Gateway) error { - g.cfg.apiMiddlewareEndpointFactory = endpointFactory - return nil - } -} - // WithTimeout allows changing the timeout value for API calls. func WithTimeout(seconds uint64) Option { return func(g *Gateway) error { diff --git a/beacon-chain/node/BUILD.bazel b/beacon-chain/node/BUILD.bazel index c87144c60e..f3a503434b 100644 --- a/beacon-chain/node/BUILD.bazel +++ b/beacon-chain/node/BUILD.bazel @@ -41,7 +41,6 @@ go_library( "//beacon-chain/operations/voluntaryexits:go_default_library", "//beacon-chain/p2p:go_default_library", "//beacon-chain/rpc:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/slasher:go_default_library", "//beacon-chain/startup:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index b6f580c278..37f2fbf427 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -43,7 +43,6 @@ import ( "github.com/prysmaticlabs/prysm/v4/beacon-chain/operations/voluntaryexits" "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/slasher" "github.com/prysmaticlabs/prysm/v4/beacon-chain/startup" "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" @@ -939,9 +938,6 @@ func (b *BeaconNode) registerGRPCGateway(router *mux.Router) error { apigateway.WithAllowedOrigins(allowedOrigins), apigateway.WithTimeout(uint64(timeout)), } - if flags.EnableHTTPEthAPI(httpModules) { - opts = append(opts, apigateway.WithApiMiddleware(&apimiddleware.BeaconEndpointFactory{})) - } g, err := apigateway.New(b.ctx, opts...) if err != nil { return err diff --git a/beacon-chain/rpc/apimiddleware/BUILD.bazel b/beacon-chain/rpc/apimiddleware/BUILD.bazel deleted file mode 100644 index 67777be96b..0000000000 --- a/beacon-chain/rpc/apimiddleware/BUILD.bazel +++ /dev/null @@ -1,37 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "custom_hooks.go", - "endpoint_factory.go", - "structs.go", - "structs_marshalling.go", - ], - importpath = "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware", - visibility = ["//visibility:public"], - deps = [ - "//api/gateway/apimiddleware:go_default_library", - "//config/params:go_default_library", - "//consensus-types/primitives:go_default_library", - "//time/slots:go_default_library", - "@com_github_pkg_errors//:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "custom_hooks_test.go", - "endpoint_factory_test.go", - "structs_marshalling_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//api/gateway/apimiddleware:go_default_library", - "//config/params:go_default_library", - "//testing/assert:go_default_library", - "//testing/require:go_default_library", - "//time/slots:go_default_library", - ], -) diff --git a/beacon-chain/rpc/apimiddleware/custom_hooks.go b/beacon-chain/rpc/apimiddleware/custom_hooks.go deleted file mode 100644 index 0e735f382f..0000000000 --- a/beacon-chain/rpc/apimiddleware/custom_hooks.go +++ /dev/null @@ -1,277 +0,0 @@ -package apimiddleware - -import ( - "bytes" - "encoding/json" - "io" - "net/http" - "strconv" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" - "github.com/prysmaticlabs/prysm/v4/config/params" - "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v4/time/slots" -) - -// https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Beacon/submitPoolBLSToExecutionChange -// expects posting a top-level array. We make it more proto-friendly by wrapping it in a struct. - -type v1alpha1SignedPhase0Block struct { - Block *BeaconBlockJson `json:"block"` // tech debt on phase 0 called this block instead of "message" - Signature string `json:"signature" hex:"true"` -} - -type phase0PublishBlockRequestJson struct { - Message *v1alpha1SignedPhase0Block `json:"phase0_block"` -} - -type altairPublishBlockRequestJson struct { - AltairBlock *SignedBeaconBlockAltairJson `json:"altair_block"` -} - -type bellatrixPublishBlockRequestJson struct { - BellatrixBlock *SignedBeaconBlockBellatrixJson `json:"bellatrix_block"` -} - -type bellatrixPublishBlindedBlockRequestJson struct { - BellatrixBlock *SignedBlindedBeaconBlockBellatrixJson `json:"bellatrix_block"` -} - -type capellaPublishBlockRequestJson struct { - CapellaBlock *SignedBeaconBlockCapellaJson `json:"capella_block"` -} - -type capellaPublishBlindedBlockRequestJson struct { - CapellaBlock *SignedBlindedBeaconBlockCapellaJson `json:"capella_block"` -} - -type denebPublishBlockRequestJson struct { - DenebContents *SignedBeaconBlockContentsDenebJson `json:"deneb_contents"` -} - -type denebPublishBlindedBlockRequestJson struct { - DenebContents *SignedBlindedBeaconBlockContentsDenebJson `json:"deneb_contents"` -} - -// setInitialPublishBlockPostRequest is triggered before we deserialize the request JSON into a struct. -// We don't know which version of the block got posted, but we can determine it from the slot. -// We know that blocks of all versions have a Message field with a Slot field, -// so we deserialize the request into a struct s, which has the right fields, to obtain the slot. -// Once we know the slot, we can determine what the PostRequest field of the endpoint should be, and we set it appropriately. -func setInitialPublishBlockPostRequest(endpoint *apimiddleware.Endpoint, - _ http.ResponseWriter, - req *http.Request, -) (apimiddleware.RunDefault, apimiddleware.ErrorJson) { - s := struct { - Slot string - }{} - - buf, err := io.ReadAll(req.Body) - if err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not read body") - } - - typeParseMap := make(map[string]json.RawMessage) - if err := json.Unmarshal(buf, &typeParseMap); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not parse object") - } - if val, ok := typeParseMap["message"]; ok { - if err := json.Unmarshal(val, &s); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not unmarshal field 'message' ") - } - } else if val, ok := typeParseMap["signed_block"]; ok { - temp := struct { - Message struct { - Slot string - } - }{} - if err := json.Unmarshal(val, &temp); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not unmarshal field 'signed_block' ") - } - s.Slot = temp.Message.Slot - } else { - return false, &apimiddleware.DefaultErrorJson{Message: "could not parse slot from request", Code: http.StatusInternalServerError} - } - slot, err := strconv.ParseUint(s.Slot, 10, 64) - if err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "slot is not an unsigned integer") - } - currentEpoch := slots.ToEpoch(primitives.Slot(slot)) - if currentEpoch < params.BeaconConfig().AltairForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockJson{} - } else if currentEpoch < params.BeaconConfig().BellatrixForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockAltairJson{} - } else if currentEpoch < params.BeaconConfig().CapellaForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockBellatrixJson{} - } else if currentEpoch < params.BeaconConfig().DenebForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockCapellaJson{} - } else { - endpoint.PostRequest = &SignedBeaconBlockContentsDenebJson{} - } - req.Body = io.NopCloser(bytes.NewBuffer(buf)) - return true, nil -} - -// In preparePublishedBlock we transform the PostRequest. -// gRPC expects an XXX_block field in the JSON object, but we have a message field at this point. -// We do a simple conversion depending on the type of endpoint.PostRequest -// (which was filled out previously in setInitialPublishBlockPostRequest). -func preparePublishedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson { - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - endpoint.PostRequest = &phase0PublishBlockRequestJson{ - Message: &v1alpha1SignedPhase0Block{ - Block: block.Message, - Signature: block.Signature, - }, - } - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - endpoint.PostRequest = &altairPublishBlockRequestJson{ - AltairBlock: block, - } - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockBellatrixJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - endpoint.PostRequest = &bellatrixPublishBlockRequestJson{ - BellatrixBlock: block, - } - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockCapellaJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - endpoint.PostRequest = &capellaPublishBlockRequestJson{ - CapellaBlock: block, - } - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockContentsDenebJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - endpoint.PostRequest = &denebPublishBlockRequestJson{ - DenebContents: block, - } - return nil - } - return apimiddleware.InternalServerError(errors.New("unsupported block type")) -} - -// setInitialPublishBlindedBlockPostRequest is triggered before we deserialize the request JSON into a struct. -// We don't know which version of the block got posted, but we can determine it from the slot. -// We know that blocks of all versions have a Message field with a Slot field, -// so we deserialize the request into a struct s, which has the right fields, to obtain the slot. -// Once we know the slot, we can determine what the PostRequest field of the endpoint should be, and we set it appropriately. -func setInitialPublishBlindedBlockPostRequest(endpoint *apimiddleware.Endpoint, - _ http.ResponseWriter, - req *http.Request, -) (apimiddleware.RunDefault, apimiddleware.ErrorJson) { - s := struct { - Slot string - }{} - - buf, err := io.ReadAll(req.Body) - if err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not read body") - } - - typeParseMap := make(map[string]json.RawMessage) - if err = json.Unmarshal(buf, &typeParseMap); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not parse object") - } - if val, ok := typeParseMap["message"]; ok { - if err = json.Unmarshal(val, &s); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not unmarshal field 'message' ") - } - } else if val, ok = typeParseMap["signed_blinded_block"]; ok { - temp := struct { - Message struct { - Slot string - } - }{} - if err = json.Unmarshal(val, &temp); err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "could not unmarshal field 'signed_block' ") - } - s.Slot = temp.Message.Slot - } else { - return false, &apimiddleware.DefaultErrorJson{Message: "could not parse slot from request", Code: http.StatusInternalServerError} - } - slot, err := strconv.ParseUint(s.Slot, 10, 64) - if err != nil { - return false, apimiddleware.InternalServerErrorWithMessage(err, "slot is not an unsigned integer") - } - currentEpoch := slots.ToEpoch(primitives.Slot(slot)) - if currentEpoch < params.BeaconConfig().AltairForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockJson{} - } else if currentEpoch < params.BeaconConfig().BellatrixForkEpoch { - endpoint.PostRequest = &SignedBeaconBlockAltairJson{} - } else if currentEpoch < params.BeaconConfig().CapellaForkEpoch { - endpoint.PostRequest = &SignedBlindedBeaconBlockBellatrixJson{} - } else if currentEpoch < params.BeaconConfig().DenebForkEpoch { - endpoint.PostRequest = &SignedBlindedBeaconBlockCapellaJson{} - } else { - endpoint.PostRequest = &SignedBlindedBeaconBlockContentsDenebJson{} - } - req.Body = io.NopCloser(bytes.NewBuffer(buf)) - return true, nil -} - -// In preparePublishedBlindedBlock we transform the PostRequest. -// gRPC expects either an XXX_block field in the JSON object, but we have a message field at this point. -// We do a simple conversion depending on the type of endpoint.PostRequest -// (which was filled out previously in setInitialPublishBlockPostRequest). -func preparePublishedBlindedBlock(endpoint *apimiddleware.Endpoint, _ http.ResponseWriter, _ *http.Request) apimiddleware.ErrorJson { - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockJson); ok { - endpoint.PostRequest = &phase0PublishBlockRequestJson{ - Message: &v1alpha1SignedPhase0Block{ - Block: block.Message, - Signature: block.Signature, - }, - } - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBeaconBlockAltairJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - actualPostReq := &altairPublishBlockRequestJson{ - AltairBlock: block, - } - endpoint.PostRequest = actualPostReq - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBlindedBeaconBlockBellatrixJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - actualPostReq := &bellatrixPublishBlindedBlockRequestJson{ - BellatrixBlock: &SignedBlindedBeaconBlockBellatrixJson{ - Message: block.Message, - Signature: block.Signature, - }, - } - endpoint.PostRequest = actualPostReq - return nil - } - if block, ok := endpoint.PostRequest.(*SignedBlindedBeaconBlockCapellaJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - actualPostReq := &capellaPublishBlindedBlockRequestJson{ - CapellaBlock: &SignedBlindedBeaconBlockCapellaJson{ - Message: block.Message, - Signature: block.Signature, - }, - } - endpoint.PostRequest = actualPostReq - return nil - } - if blockContents, ok := endpoint.PostRequest.(*SignedBlindedBeaconBlockContentsDenebJson); ok { - // Prepare post request that can be properly decoded on gRPC side. - actualPostReq := &denebPublishBlindedBlockRequestJson{ - DenebContents: &SignedBlindedBeaconBlockContentsDenebJson{ - SignedBlindedBlock: blockContents.SignedBlindedBlock, - SignedBlindedBlobSidecars: blockContents.SignedBlindedBlobSidecars, - }, - } - endpoint.PostRequest = actualPostReq - return nil - } - return apimiddleware.InternalServerError(errors.New("unsupported block type")) -} diff --git a/beacon-chain/rpc/apimiddleware/custom_hooks_test.go b/beacon-chain/rpc/apimiddleware/custom_hooks_test.go deleted file mode 100644 index 817957b949..0000000000 --- a/beacon-chain/rpc/apimiddleware/custom_hooks_test.go +++ /dev/null @@ -1,359 +0,0 @@ -package apimiddleware - -import ( - "bytes" - "encoding/json" - "net/http/httptest" - "reflect" - "strconv" - "strings" - "testing" - - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" - "github.com/prysmaticlabs/prysm/v4/config/params" - "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/require" - "github.com/prysmaticlabs/prysm/v4/time/slots" -) - -func TestSetInitialPublishBlockPostRequest(t *testing.T) { - params.SetupTestConfigCleanup(t) - cfg := params.BeaconConfig().Copy() - cfg.BellatrixForkEpoch = params.BeaconConfig().AltairForkEpoch + 1 - cfg.CapellaForkEpoch = params.BeaconConfig().BellatrixForkEpoch + 1 - cfg.DenebForkEpoch = params.BeaconConfig().CapellaForkEpoch + 1 - params.OverrideBeaconConfig(cfg) - - endpoint := &apimiddleware.Endpoint{} - s := struct { - Message struct { - Slot string - } `json:"message"` - }{} - t.Run("Phase 0", func(t *testing.T) { - s.Message = struct{ Slot string }{Slot: "0"} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Altair", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockAltairJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Bellatrix", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockBellatrixJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Capella", func(t *testing.T) { - params.SetupTestConfigCleanup(t) - cfg := params.BeaconConfig() - cfg.CapellaForkEpoch = cfg.BellatrixForkEpoch.Add(2) - params.OverrideBeaconConfig(cfg) - - slot, err := slots.EpochStart(params.BeaconConfig().CapellaForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockCapellaJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Deneb", func(t *testing.T) { - params.SetupTestConfigCleanup(t) - cfg := params.BeaconConfig() - cfg.DenebForkEpoch = cfg.CapellaForkEpoch.Add(2) - params.OverrideBeaconConfig(cfg) - slot, err := slots.EpochStart(params.BeaconConfig().DenebForkEpoch) - require.NoError(t, err) - denebS := struct { - SignedBlock struct { - Message struct { - Slot string - } `json:"message"` - } `json:"signed_block"` - }{} - denebS.SignedBlock = struct { - Message struct { - Slot string - } `json:"message"` - }{ - Message: struct { - Slot string - }{Slot: strconv.FormatUint(uint64(slot), 10)}, - } - j, err := json.Marshal(denebS) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockContentsDenebJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) -} - -func TestPreparePublishedBlock(t *testing.T) { - t.Run("Phase 0", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBeaconBlockJson{ - Message: &BeaconBlockJson{ - Body: &BeaconBlockBodyJson{}, - }, - }, - } - errJson := preparePublishedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*phase0PublishBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("Altair", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBeaconBlockAltairJson{ - Message: &BeaconBlockAltairJson{ - Body: &BeaconBlockBodyAltairJson{}, - }, - }, - } - errJson := preparePublishedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*altairPublishBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("Bellatrix", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBeaconBlockBellatrixJson{ - Message: &BeaconBlockBellatrixJson{ - Body: &BeaconBlockBodyBellatrixJson{}, - }, - }, - } - errJson := preparePublishedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*bellatrixPublishBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("unsupported block type", func(t *testing.T) { - errJson := preparePublishedBlock(&apimiddleware.Endpoint{}, nil, nil) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "unsupported block type")) - }) -} - -func TestSetInitialPublishBlindedBlockPostRequest(t *testing.T) { - params.SetupTestConfigCleanup(t) - cfg := params.BeaconConfig().Copy() - cfg.BellatrixForkEpoch = params.BeaconConfig().AltairForkEpoch + 1 - cfg.CapellaForkEpoch = params.BeaconConfig().BellatrixForkEpoch + 1 - cfg.DenebForkEpoch = params.BeaconConfig().CapellaForkEpoch + 1 - params.OverrideBeaconConfig(cfg) - - endpoint := &apimiddleware.Endpoint{} - s := struct { - Message struct { - Slot string - } `json:"message"` - }{} - t.Run("Phase 0", func(t *testing.T) { - s.Message = struct{ Slot string }{Slot: "0"} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlindedBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Altair", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlindedBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBeaconBlockAltairJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Bellatrix", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().BellatrixForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlindedBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBlindedBeaconBlockBellatrixJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Capella", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().CapellaForkEpoch) - require.NoError(t, err) - s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} - j, err := json.Marshal(s) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlindedBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBlindedBeaconBlockCapellaJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) - t.Run("Deneb", func(t *testing.T) { - slot, err := slots.EpochStart(params.BeaconConfig().DenebForkEpoch) - require.NoError(t, err) - denebS := struct { - SignedBlindedBlock struct { - Message struct { - Slot string - } `json:"message"` - } `json:"signed_blinded_block"` - }{} - denebS.SignedBlindedBlock = struct { - Message struct { - Slot string - } `json:"message"` - }{ - Message: struct { - Slot string - }{Slot: strconv.FormatUint(uint64(slot), 10)}, - } - j, err := json.Marshal(denebS) - require.NoError(t, err) - var body bytes.Buffer - _, err = body.Write(j) - require.NoError(t, err) - request := httptest.NewRequest("POST", "http://foo.example", &body) - runDefault, errJson := setInitialPublishBlindedBlockPostRequest(endpoint, nil, request) - require.Equal(t, true, errJson == nil) - assert.Equal(t, apimiddleware.RunDefault(true), runDefault) - assert.Equal(t, reflect.TypeOf(SignedBlindedBeaconBlockContentsDenebJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) - }) -} - -func TestPreparePublishedBlindedBlock(t *testing.T) { - t.Run("Phase 0", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBeaconBlockJson{ - Message: &BeaconBlockJson{ - Body: &BeaconBlockBodyJson{}, - }, - }, - } - errJson := preparePublishedBlindedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*phase0PublishBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("Altair", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBeaconBlockAltairJson{ - Message: &BeaconBlockAltairJson{ - Body: &BeaconBlockBodyAltairJson{}, - }, - }, - } - errJson := preparePublishedBlindedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*altairPublishBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("Bellatrix", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBlindedBeaconBlockBellatrixJson{ - Message: &BlindedBeaconBlockBellatrixJson{ - Body: &BlindedBeaconBlockBodyBellatrixJson{}, - }, - }, - } - errJson := preparePublishedBlindedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*bellatrixPublishBlindedBlockRequestJson) - assert.Equal(t, true, ok) - }) - t.Run("Capella", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBlindedBeaconBlockCapellaJson{ - Message: &BlindedBeaconBlockCapellaJson{ - Body: &BlindedBeaconBlockBodyCapellaJson{}, - }, - }, - } - errJson := preparePublishedBlindedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*capellaPublishBlindedBlockRequestJson) - assert.Equal(t, true, ok) - }) - - t.Run("Deneb", func(t *testing.T) { - endpoint := &apimiddleware.Endpoint{ - PostRequest: &SignedBlindedBeaconBlockContentsDenebJson{ - SignedBlindedBlock: &SignedBlindedBeaconBlockDenebJson{ - Message: &BlindedBeaconBlockDenebJson{}, - }, - SignedBlindedBlobSidecars: []*SignedBlindedBlobSidecarJson{}, - }, - } - errJson := preparePublishedBlindedBlock(endpoint, nil, nil) - require.Equal(t, true, errJson == nil) - _, ok := endpoint.PostRequest.(*denebPublishBlindedBlockRequestJson) - assert.Equal(t, true, ok) - }) - t.Run("unsupported block type", func(t *testing.T) { - errJson := preparePublishedBlock(&apimiddleware.Endpoint{}, nil, nil) - assert.Equal(t, true, strings.Contains(errJson.Msg(), "unsupported block type")) - }) -} diff --git a/beacon-chain/rpc/apimiddleware/endpoint_factory.go b/beacon-chain/rpc/apimiddleware/endpoint_factory.go deleted file mode 100644 index 5ce7800ce4..0000000000 --- a/beacon-chain/rpc/apimiddleware/endpoint_factory.go +++ /dev/null @@ -1,25 +0,0 @@ -package apimiddleware - -import ( - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" -) - -// BeaconEndpointFactory creates endpoints used for running beacon chain API calls through the API Middleware. -type BeaconEndpointFactory struct { -} - -func (f *BeaconEndpointFactory) IsNil() bool { - return f == nil -} - -// Paths is a collection of all valid beacon chain API paths. -func (_ *BeaconEndpointFactory) Paths() []string { - return []string{} -} - -// Create returns a new endpoint for the provided API path. -func (_ *BeaconEndpointFactory) Create(path string) (*apimiddleware.Endpoint, error) { - endpoint := apimiddleware.DefaultEndpoint() - endpoint.Path = path - return &endpoint, nil -} diff --git a/beacon-chain/rpc/apimiddleware/endpoint_factory_test.go b/beacon-chain/rpc/apimiddleware/endpoint_factory_test.go deleted file mode 100644 index 2f351521a3..0000000000 --- a/beacon-chain/rpc/apimiddleware/endpoint_factory_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package apimiddleware_test - -import ( - "testing" - - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" - "github.com/prysmaticlabs/prysm/v4/testing/require" -) - -func TestBeaconEndpointFactory_AllPathsRegistered(t *testing.T) { - f := &apimiddleware.BeaconEndpointFactory{} - - for _, p := range f.Paths() { - _, err := f.Create(p) - require.NoError(t, err, "failed to register %s", p) - } -} diff --git a/beacon-chain/rpc/apimiddleware/structs.go b/beacon-chain/rpc/apimiddleware/structs.go deleted file mode 100644 index bd76124264..0000000000 --- a/beacon-chain/rpc/apimiddleware/structs.go +++ /dev/null @@ -1,668 +0,0 @@ -package apimiddleware - -import ( - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" -) - -//---------------- -// Requests and responses. -//---------------- - -type BlockRootResponseJson struct { - Data *BlockRootContainerJson `json:"data"` - ExecutionOptimistic bool `json:"execution_optimistic"` - Finalized bool `json:"finalized"` -} - -type DepositContractResponseJson struct { - Data *DepositContractJson `json:"data"` -} - -type AggregateAttestationResponseJson struct { - Data *AttestationJson `json:"data"` -} - -type BeaconCommitteeSubscribeJson struct { - ValidatorIndex string `json:"validator_index"` - CommitteeIndex string `json:"committee_index"` - CommitteesAtSlot string `json:"committees_at_slot"` - Slot string `json:"slot"` - IsAggregator bool `json:"is_aggregator"` -} - -type ProduceSyncCommitteeContributionResponseJson struct { - Data *SyncCommitteeContributionJson `json:"data"` -} - -type ForkChoiceNodeResponseJson struct { - Slot string `json:"slot"` - BlockRoot string `json:"block_root" hex:"true"` - ParentRoot string `json:"parent_root" hex:"true"` - JustifiedEpoch string `json:"justified_epoch"` - FinalizedEpoch string `json:"finalized_epoch"` - Weight string `json:"weight"` - Validity string `json:"validity" enum:"true"` - ExecutionBlockHash string `json:"execution_block_hash" hex:"true"` - ExtraData *ForkChoiceNodeExtraDataJson `json:"extra_data"` -} - -type ForkChoiceNodeExtraDataJson struct { - UnrealizedJustifiedEpoch string `json:"unrealized_justified_epoch"` - UnrealizedFinalizedEpoch string `json:"unrealized_finalized_epoch"` - Balance string `json:"balance"` - ExecutionOptimistic bool `json:"execution_optimistic"` - TimeStamp string `json:"timestamp"` -} - -type ForkChoiceResponseJson struct { - JustifiedCheckpoint *CheckpointJson `json:"justified_checkpoint"` - FinalizedCheckpoint *CheckpointJson `json:"finalized_checkpoint"` - ForkChoiceNodes []*ForkChoiceNodeResponseJson `json:"fork_choice_nodes"` - ExtraData *ForkChoiceResponseExtraDataJson `json:"extra_data"` -} - -type ForkChoiceResponseExtraDataJson struct { - BestJustifiedCheckpoint *CheckpointJson `json:"best_justified_checkpoint"` - UnrealizedJustifiedCheckpoint *CheckpointJson `json:"unrealized_justified_checkpoint"` - UnrealizedFinalizedCheckpoint *CheckpointJson `json:"unrealized_finalized_checkpoint"` - ProposerBoostRoot string `json:"proposer_boost_root" hex:"true"` - PreviousProposerBoostRoot string `json:"previous_proposer_boost_root" hex:"true"` - HeadRoot string `json:"head_root" hex:"true"` -} - -//---------------- -// Reusable types. -//---------------- - -type CheckpointJson struct { - Epoch string `json:"epoch"` - Root string `json:"root" hex:"true"` -} - -type BlockRootContainerJson struct { - Root string `json:"root" hex:"true"` -} - -type SignedBeaconBlockJson struct { - Message *BeaconBlockJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type BeaconBlockJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BeaconBlockBodyJson `json:"body"` -} - -type BeaconBlockBodyJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` -} - -type BeaconBlockContainerV2Json struct { - Phase0Block *BeaconBlockJson `json:"phase0_block"` - AltairBlock *BeaconBlockAltairJson `json:"altair_block"` - BellatrixBlock *BeaconBlockBellatrixJson `json:"bellatrix_block"` - CapellaBlock *BeaconBlockCapellaJson `json:"capella_block"` - DenebContents *BeaconBlockContentsDenebJson `json:"deneb_contents"` -} - -type BlindedBeaconBlockContainerJson struct { - Phase0Block *BeaconBlockJson `json:"phase0_block"` - AltairBlock *BeaconBlockAltairJson `json:"altair_block"` - BellatrixBlock *BlindedBeaconBlockBellatrixJson `json:"bellatrix_block"` - CapellaBlock *BlindedBeaconBlockCapellaJson `json:"capella_block"` - DenebContents *BlindedBeaconBlockContentsDenebJson `json:"deneb_contents"` -} - -type SignedBeaconBlockAltairJson struct { - Message *BeaconBlockAltairJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBeaconBlockBellatrixJson struct { - Message *BeaconBlockBellatrixJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBeaconBlockCapellaJson struct { - Message *BeaconBlockCapellaJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBeaconBlockContentsDenebJson struct { - SignedBlock *SignedBeaconBlockDenebJson `json:"signed_block"` - SignedBlobSidecars []*SignedBlobSidecarJson `json:"signed_blob_sidecars"` -} - -type SignedBlobSidecarJson struct { - Message *BlobSidecarJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type BlobSidecarJson struct { - BlockRoot string `json:"block_root" hex:"true"` - Index string `json:"index"` - Slot string `json:"slot"` - BlockParentRoot string `json:"block_parent_root" hex:"true"` - ProposerIndex string `json:"proposer_index"` - Blob string `json:"blob" hex:"true"` // pattern: "^0x[a-fA-F0-9]{262144}$" - KzgCommitment string `json:"kzg_commitment" hex:"true"` // pattern: "^0x[a-fA-F0-9]{96}$" ssz-size:"48" - KzgProof string `json:"kzg_proof,omitempty" hex:"true"` // pattern: "^0x[a-fA-F0-9]{96}$" ssz-size:"48" -} - -type BlindedBlobSidecarJson struct { - BlockRoot string `json:"block_root" hex:"true"` - Index string `json:"index"` - Slot string `json:"slot"` - BlockParentRoot string `json:"block_parent_root" hex:"true"` - ProposerIndex string `json:"proposer_index"` - BlobRoot string `json:"blob_root" hex:"true"` - KzgCommitment string `json:"kzg_commitment" hex:"true"` // pattern: "^0x[a-fA-F0-9]{96}$" ssz-size:"48" - KzgProof string `json:"kzg_proof,omitempty" hex:"true"` // pattern: "^0x[a-fA-F0-9]{96}$" ssz-size:"48" -} - -type SignedBeaconBlockDenebJson struct { - Message *BeaconBlockDenebJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBlindedBeaconBlockBellatrixJson struct { - Message *BlindedBeaconBlockBellatrixJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBlindedBeaconBlockCapellaJson struct { - Message *BlindedBeaconBlockCapellaJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBlindedBeaconBlockContentsDenebJson struct { - SignedBlindedBlock *SignedBlindedBeaconBlockDenebJson `json:"signed_blinded_block"` - SignedBlindedBlobSidecars []*SignedBlindedBlobSidecarJson `json:"signed_blinded_blob_sidecars"` -} - -type SignedBlindedBeaconBlockDenebJson struct { - Message *BlindedBeaconBlockDenebJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type SignedBlindedBlobSidecarJson struct { - Message *BlindedBlobSidecarJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type BeaconBlockAltairJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BeaconBlockBodyAltairJson `json:"body"` -} - -type BeaconBlockBellatrixJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BeaconBlockBodyBellatrixJson `json:"body"` -} - -type BeaconBlockCapellaJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BeaconBlockBodyCapellaJson `json:"body"` -} - -type BeaconBlockContentsDenebJson struct { - Block *BeaconBlockDenebJson `json:"block"` - BlobSidecars []*BlobSidecarJson `json:"blob_sidecars"` -} - -type BeaconBlockDenebJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BeaconBlockBodyDenebJson `json:"body"` -} - -type BlindedBeaconBlockBellatrixJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BlindedBeaconBlockBodyBellatrixJson `json:"body"` -} - -type BlindedBeaconBlockCapellaJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BlindedBeaconBlockBodyCapellaJson `json:"body"` -} - -type BlindedBeaconBlockDenebJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - Body *BlindedBeaconBlockBodyDenebJson `json:"body"` -} - -type BlindedBeaconBlockContentsDenebJson struct { - BlindedBlock *BlindedBeaconBlockDenebJson `json:"blinded_block"` - BlindedBlobSidecars []*BlindedBlobSidecarJson `json:"blinded_blob_sidecars"` -} - -type BeaconBlockBodyAltairJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` -} - -type BeaconBlockBodyBellatrixJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayload *ExecutionPayloadJson `json:"execution_payload"` -} - -type BeaconBlockBodyCapellaJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayload *ExecutionPayloadCapellaJson `json:"execution_payload"` - BLSToExecutionChanges []*SignedBLSToExecutionChangeJson `json:"bls_to_execution_changes"` -} - -type BeaconBlockBodyDenebJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayload *ExecutionPayloadDenebJson `json:"execution_payload"` - BLSToExecutionChanges []*SignedBLSToExecutionChangeJson `json:"bls_to_execution_changes"` - BlobKzgCommitments []string `json:"blob_kzg_commitments" hex:"true"` -} - -type BlindedBeaconBlockBodyBellatrixJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayloadHeader *ExecutionPayloadHeaderJson `json:"execution_payload_header"` -} - -type BlindedBeaconBlockBodyCapellaJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayloadHeader *ExecutionPayloadHeaderCapellaJson `json:"execution_payload_header"` - BLSToExecutionChanges []*SignedBLSToExecutionChangeJson `json:"bls_to_execution_changes"` -} - -type BlindedBeaconBlockBodyDenebJson struct { - RandaoReveal string `json:"randao_reveal" hex:"true"` - Eth1Data *Eth1DataJson `json:"eth1_data"` - Graffiti string `json:"graffiti" hex:"true"` - ProposerSlashings []*ProposerSlashingJson `json:"proposer_slashings"` - AttesterSlashings []*AttesterSlashingJson `json:"attester_slashings"` - Attestations []*AttestationJson `json:"attestations"` - Deposits []*DepositJson `json:"deposits"` - VoluntaryExits []*SignedVoluntaryExitJson `json:"voluntary_exits"` - SyncAggregate *SyncAggregateJson `json:"sync_aggregate"` - ExecutionPayloadHeader *ExecutionPayloadHeaderDenebJson `json:"execution_payload_header"` - BLSToExecutionChanges []*SignedBLSToExecutionChangeJson `json:"bls_to_execution_changes"` - BlobKzgCommitments []string `json:"blob_kzg_commitments" hex:"true"` -} - -type ExecutionPayloadJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlockHash string `json:"block_hash" hex:"true"` - Transactions []string `json:"transactions" hex:"true"` -} - -type ExecutionPayloadCapellaJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlockHash string `json:"block_hash" hex:"true"` - Transactions []string `json:"transactions" hex:"true"` - Withdrawals []*WithdrawalJson `json:"withdrawals"` -} - -type ExecutionPayloadDenebJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlobGasUsed string `json:"blob_gas_used"` // new in deneb - ExcessBlobGas string `json:"excess_blob_gas"` // new in deneb - BlockHash string `json:"block_hash" hex:"true"` - Transactions []string `json:"transactions" hex:"true"` - Withdrawals []*WithdrawalJson `json:"withdrawals"` -} - -type ExecutionPayloadHeaderJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlockHash string `json:"block_hash" hex:"true"` - TransactionsRoot string `json:"transactions_root" hex:"true"` -} - -type ExecutionPayloadHeaderCapellaJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlockHash string `json:"block_hash" hex:"true"` - TransactionsRoot string `json:"transactions_root" hex:"true"` - WithdrawalsRoot string `json:"withdrawals_root" hex:"true"` -} - -type ExecutionPayloadHeaderDenebJson struct { - ParentHash string `json:"parent_hash" hex:"true"` - FeeRecipient string `json:"fee_recipient" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - ReceiptsRoot string `json:"receipts_root" hex:"true"` - LogsBloom string `json:"logs_bloom" hex:"true"` - PrevRandao string `json:"prev_randao" hex:"true"` - BlockNumber string `json:"block_number"` - GasLimit string `json:"gas_limit"` - GasUsed string `json:"gas_used"` - TimeStamp string `json:"timestamp"` - ExtraData string `json:"extra_data" hex:"true"` - BaseFeePerGas string `json:"base_fee_per_gas" uint256:"true"` - BlobGasUsed string `json:"blob_gas_used"` // new in deneb - ExcessBlobGas string `json:"excess_blob_gas"` // new in deneb - BlockHash string `json:"block_hash" hex:"true"` - TransactionsRoot string `json:"transactions_root" hex:"true"` - WithdrawalsRoot string `json:"withdrawals_root" hex:"true"` -} - -type SyncAggregateJson struct { - SyncCommitteeBits string `json:"sync_committee_bits" hex:"true"` - SyncCommitteeSignature string `json:"sync_committee_signature" hex:"true"` -} - -type SignedBeaconBlockHeaderJson struct { - Header *BeaconBlockHeaderJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type BeaconBlockHeaderJson struct { - Slot string `json:"slot"` - ProposerIndex string `json:"proposer_index"` - ParentRoot string `json:"parent_root" hex:"true"` - StateRoot string `json:"state_root" hex:"true"` - BodyRoot string `json:"body_root" hex:"true"` -} - -type Eth1DataJson struct { - DepositRoot string `json:"deposit_root" hex:"true"` - DepositCount string `json:"deposit_count"` - BlockHash string `json:"block_hash" hex:"true"` -} - -type ProposerSlashingJson struct { - Header_1 *SignedBeaconBlockHeaderJson `json:"signed_header_1"` - Header_2 *SignedBeaconBlockHeaderJson `json:"signed_header_2"` -} - -type AttesterSlashingJson struct { - Attestation_1 *IndexedAttestationJson `json:"attestation_1"` - Attestation_2 *IndexedAttestationJson `json:"attestation_2"` -} - -type IndexedAttestationJson struct { - AttestingIndices []string `json:"attesting_indices"` - Data *AttestationDataJson `json:"data"` - Signature string `json:"signature" hex:"true"` -} - -type AttestationJson struct { - AggregationBits string `json:"aggregation_bits" hex:"true"` - Data *AttestationDataJson `json:"data"` - Signature string `json:"signature" hex:"true"` -} - -type AttestationDataJson struct { - Slot string `json:"slot"` - CommitteeIndex string `json:"index"` - BeaconBlockRoot string `json:"beacon_block_root" hex:"true"` - Source *CheckpointJson `json:"source"` - Target *CheckpointJson `json:"target"` -} - -type SignedBLSToExecutionChangeJson struct { - Message *BLSToExecutionChangeJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type BLSToExecutionChangeJson struct { - ValidatorIndex string `json:"validator_index"` - FromBLSPubkey string `json:"from_bls_pubkey" hex:"true"` - ToExecutionAddress string `json:"to_execution_address" hex:"true"` -} - -type DepositJson struct { - Proof []string `json:"proof" hex:"true"` - Data *Deposit_DataJson `json:"data"` -} - -type Deposit_DataJson struct { - PublicKey string `json:"pubkey" hex:"true"` - WithdrawalCredentials string `json:"withdrawal_credentials" hex:"true"` - Amount string `json:"amount"` - Signature string `json:"signature" hex:"true"` -} - -type SignedVoluntaryExitJson struct { - Exit *VoluntaryExitJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type VoluntaryExitJson struct { - Epoch string `json:"epoch"` - ValidatorIndex string `json:"validator_index"` -} - -type WithdrawalJson struct { - WithdrawalIndex string `json:"index"` - ValidatorIndex string `json:"validator_index"` - ExecutionAddress string `json:"address" hex:"true"` - Amount string `json:"amount"` -} - -type ForkJson struct { - PreviousVersion string `json:"previous_version" hex:"true"` - CurrentVersion string `json:"current_version" hex:"true"` - Epoch string `json:"epoch"` -} - -type ValidatorJson struct { - PublicKey string `json:"pubkey" hex:"true"` - WithdrawalCredentials string `json:"withdrawal_credentials" hex:"true"` - EffectiveBalance string `json:"effective_balance"` - Slashed bool `json:"slashed"` - ActivationEligibilityEpoch string `json:"activation_eligibility_epoch"` - ActivationEpoch string `json:"activation_epoch"` - ExitEpoch string `json:"exit_epoch"` - WithdrawableEpoch string `json:"withdrawable_epoch"` -} - -type SyncCommitteeJson struct { - Pubkeys []string `json:"pubkeys" hex:"true"` - AggregatePubkey string `json:"aggregate_pubkey" hex:"true"` -} - -type PendingAttestationJson struct { - AggregationBits string `json:"aggregation_bits" hex:"true"` - Data *AttestationDataJson `json:"data"` - InclusionDelay string `json:"inclusion_delay"` - ProposerIndex string `json:"proposer_index"` -} - -type DepositContractJson struct { - ChainId string `json:"chain_id"` - Address string `json:"address"` -} - -type SignedAggregateAttestationAndProofJson struct { - Message *AggregateAttestationAndProofJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type AggregateAttestationAndProofJson struct { - AggregatorIndex string `json:"aggregator_index"` - Aggregate *AttestationJson `json:"aggregate"` - SelectionProof string `json:"selection_proof" hex:"true"` -} - -type SignedContributionAndProofJson struct { - Message *ContributionAndProofJson `json:"message"` - Signature string `json:"signature" hex:"true"` -} - -type ContributionAndProofJson struct { - AggregatorIndex string `json:"aggregator_index"` - Contribution *SyncCommitteeContributionJson `json:"contribution"` - SelectionProof string `json:"selection_proof" hex:"true"` -} - -type SyncCommitteeContributionJson struct { - Slot string `json:"slot"` - BeaconBlockRoot string `json:"beacon_block_root" hex:"true"` - SubcommitteeIndex string `json:"subcommittee_index"` - AggregationBits string `json:"aggregation_bits" hex:"true"` - Signature string `json:"signature" hex:"true"` -} - -type HistoricalSummaryJson struct { - BlockSummaryRoot string `json:"block_summary_root" hex:"true"` - StateSummaryRoot string `json:"state_summary_root" hex:"true"` -} - -//---------------- -// SSZ -// --------------- - -type SszRequestJson struct { - Data string `json:"data"` -} - -// SszResponse is a common abstraction over all SSZ responses. -type SszResponse interface { - SSZVersion() string - SSZOptimistic() bool - SSZData() string - SSZFinalized() bool -} - -// --------------- -// Error handling. -// --------------- - -// IndexedVerificationFailureErrorJson is a JSON representation of the error returned when verifying an indexed object. -type IndexedVerificationFailureErrorJson struct { - apimiddleware.DefaultErrorJson - Failures []*SingleIndexedVerificationFailureJson `json:"failures"` -} - -// SingleIndexedVerificationFailureJson is a JSON representation of a an issue when verifying a single indexed object e.g. an item in an array. -type SingleIndexedVerificationFailureJson struct { - Index int `json:"index"` - Message string `json:"message"` -} diff --git a/beacon-chain/rpc/apimiddleware/structs_marshalling.go b/beacon-chain/rpc/apimiddleware/structs_marshalling.go deleted file mode 100644 index f664258439..0000000000 --- a/beacon-chain/rpc/apimiddleware/structs_marshalling.go +++ /dev/null @@ -1,38 +0,0 @@ -package apimiddleware - -import ( - "encoding/base64" - "strconv" - "strings" - - "github.com/pkg/errors" -) - -// EpochParticipation represents participation of validators in their duties. -type EpochParticipation []string - -func (p *EpochParticipation) UnmarshalJSON(b []byte) error { - if string(b) == "null" { - return nil - } - if len(b) < 2 { - return errors.New("epoch participation length must be at least 2") - } - if b[0] != '"' || b[len(b)-1] != '"' { - return errors.Errorf("provided epoch participation json string is malformed: %s", string(b)) - } - - // Remove leading and trailing quotation marks. - jsonString := string(b) - jsonString = strings.Trim(jsonString, "\"") - decoded, err := base64.StdEncoding.DecodeString(jsonString) - if err != nil { - return errors.Wrapf(err, "could not decode epoch participation base64 value") - } - - *p = make([]string, len(decoded)) - for i, participation := range decoded { - (*p)[i] = strconv.FormatUint(uint64(participation), 10) - } - return nil -} diff --git a/beacon-chain/rpc/apimiddleware/structs_marshalling_test.go b/beacon-chain/rpc/apimiddleware/structs_marshalling_test.go deleted file mode 100644 index 0374bb1c3c..0000000000 --- a/beacon-chain/rpc/apimiddleware/structs_marshalling_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package apimiddleware - -import ( - "encoding/base64" - "testing" - - "github.com/prysmaticlabs/prysm/v4/testing/assert" - "github.com/prysmaticlabs/prysm/v4/testing/require" -) - -func TestUnmarshalEpochParticipation(t *testing.T) { - t.Run("ok", func(t *testing.T) { - b := []byte{3, 3, 0} - b64 := []byte("\"" + base64.StdEncoding.EncodeToString(b) + "\"") - ep := EpochParticipation{} - require.NoError(t, ep.UnmarshalJSON(b64)) - require.Equal(t, 3, len(ep)) - assert.Equal(t, "3", ep[0]) - assert.Equal(t, "3", ep[1]) - assert.Equal(t, "0", ep[2]) - }) - t.Run("incorrect value", func(t *testing.T) { - ep := EpochParticipation{} - err := ep.UnmarshalJSON([]byte(":illegal:")) - require.NotNil(t, err) - assert.ErrorContains(t, "provided epoch participation json string is malformed", err) - }) - t.Run("length too small", func(t *testing.T) { - ep := EpochParticipation{} - err := ep.UnmarshalJSON([]byte("x")) - require.NotNil(t, err) - assert.ErrorContains(t, "epoch participation length must be at least 2", err) - }) - t.Run("null value", func(t *testing.T) { - ep := EpochParticipation{} - require.NoError(t, ep.UnmarshalJSON([]byte("null"))) - assert.DeepEqual(t, EpochParticipation([]string{}), ep) - }) - t.Run("invalid value", func(t *testing.T) { - ep := EpochParticipation{} - require.ErrorContains(t, "provided epoch participation json string is malformed", ep.UnmarshalJSON([]byte("XdHJ1ZQ==X"))) - }) -} diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index f829555bd3..c1fbfd397b 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -87,7 +87,6 @@ go_test( "//beacon-chain/operations/synccommittee:go_default_library", "//beacon-chain/operations/voluntaryexits/mock:go_default_library", "//beacon-chain/p2p/testing:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/core:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//beacon-chain/rpc/eth/shared/testing:go_default_library", diff --git a/beacon-chain/rpc/eth/beacon/handlers.go b/beacon-chain/rpc/eth/beacon/handlers.go index 304e3d796c..2c0b666ff9 100644 --- a/beacon-chain/rpc/eth/beacon/handlers.go +++ b/beacon-chain/rpc/eth/beacon/handlers.go @@ -1549,9 +1549,7 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) { return } response := &BlockRootResponse{ - Data: &struct { - Root string `json:"root"` - }{ + Data: &BlockRoot{ Root: hexutil.Encode(root), }, ExecutionOptimistic: isOptimistic, diff --git a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go index 6e5645d33c..e84651d684 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_pool_test.go +++ b/beacon-chain/rpc/eth/beacon/handlers_pool_test.go @@ -24,7 +24,6 @@ import ( "github.com/prysmaticlabs/prysm/v4/beacon-chain/operations/synccommittee" "github.com/prysmaticlabs/prysm/v4/beacon-chain/operations/voluntaryexits/mock" p2pMock "github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/testing" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/core" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" @@ -306,7 +305,7 @@ func TestSubmitAttestations(t *testing.T) { s.SubmitAttestations(writer, request) assert.Equal(t, http.StatusBadRequest, writer.Code) - e := &apimiddleware.IndexedVerificationFailureErrorJson{} + e := &shared.IndexedVerificationFailureError{} require.NoError(t, json.Unmarshal(writer.Body.Bytes(), e)) assert.Equal(t, http.StatusBadRequest, e.Code) require.Equal(t, 1, len(e.Failures)) diff --git a/beacon-chain/rpc/eth/beacon/structs.go b/beacon-chain/rpc/eth/beacon/structs.go index 496d8811ad..fc7c51681c 100644 --- a/beacon-chain/rpc/eth/beacon/structs.go +++ b/beacon-chain/rpc/eth/beacon/structs.go @@ -7,11 +7,13 @@ import ( ) type BlockRootResponse struct { - Data *struct { - Root string `json:"root"` - } `json:"data"` - ExecutionOptimistic bool `json:"execution_optimistic"` - Finalized bool `json:"finalized"` + Data *BlockRoot `json:"data"` + ExecutionOptimistic bool `json:"execution_optimistic"` + Finalized bool `json:"finalized"` +} + +type BlockRoot struct { + Root string `json:"root"` } type GetCommitteesResponse struct { diff --git a/beacon-chain/rpc/eth/shared/structs_blocks.go b/beacon-chain/rpc/eth/shared/structs_blocks.go index 1ed712c1ae..422456fca4 100644 --- a/beacon-chain/rpc/eth/shared/structs_blocks.go +++ b/beacon-chain/rpc/eth/shared/structs_blocks.go @@ -137,7 +137,7 @@ type BeaconBlockBodyCapella struct { VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" validate:"required,dive"` SyncAggregate *SyncAggregate `json:"sync_aggregate" validate:"required"` ExecutionPayload *ExecutionPayloadCapella `json:"execution_payload" validate:"required"` - BlsToExecutionChanges []*SignedBlsToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` + BlsToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` } type SignedBlindedBeaconBlockCapella struct { @@ -164,7 +164,7 @@ type BlindedBeaconBlockBodyCapella struct { VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" validate:"required,dive"` SyncAggregate *SyncAggregate `json:"sync_aggregate" validate:"required"` ExecutionPayloadHeader *ExecutionPayloadHeaderCapella `json:"execution_payload_header" validate:"required"` - BlsToExecutionChanges []*SignedBlsToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` + BlsToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` } type SignedBeaconBlockContentsDeneb struct { @@ -201,7 +201,7 @@ type BeaconBlockBodyDeneb struct { VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" validate:"required,dive"` SyncAggregate *SyncAggregate `json:"sync_aggregate" validate:"required"` ExecutionPayload *ExecutionPayloadDeneb `json:"execution_payload" validate:"required"` - BlsToExecutionChanges []*SignedBlsToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` + BlsToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` BlobKzgCommitments []string `json:"blob_kzg_commitments" validate:"required,dive"` } @@ -259,7 +259,7 @@ type BlindedBeaconBlockBodyDeneb struct { VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits" validate:"required,dive"` SyncAggregate *SyncAggregate `json:"sync_aggregate" validate:"required"` ExecutionPayloadHeader *ExecutionPayloadHeaderDeneb `json:"execution_payload_header" validate:"required"` - BlsToExecutionChanges []*SignedBlsToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` + BlsToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes" validate:"required,dive"` BlobKzgCommitments []string `json:"blob_kzg_commitments" validate:"required,dive,hexadecimal"` } @@ -578,14 +578,3 @@ func WithdrawalFromConsensus(w *enginev1.Withdrawal) *Withdrawal { Amount: fmt.Sprintf("%d", w.Amount), } } - -type SignedBlsToExecutionChange struct { - Message *BlsToExecutionChange `json:"message" validate:"required"` - Signature string `json:"signature" validate:"required"` -} - -type BlsToExecutionChange struct { - ValidatorIndex string `json:"validator_index" validate:"required"` - FromBlsPubkey string `json:"from_bls_pubkey" validate:"required"` - ToExecutionAddress string `json:"to_execution_address" validate:"required"` -} diff --git a/beacon-chain/rpc/eth/shared/structs_blocks_conversions.go b/beacon-chain/rpc/eth/shared/structs_blocks_conversions.go index 9430b3e61e..10d05216be 100644 --- a/beacon-chain/rpc/eth/shared/structs_blocks_conversions.go +++ b/beacon-chain/rpc/eth/shared/structs_blocks_conversions.go @@ -3069,7 +3069,7 @@ func ExitsFromConsensus(src []*eth.SignedVoluntaryExit) ([]*SignedVoluntaryExit, return exits, nil } -func BlsChangesToConsensus(src []*SignedBlsToExecutionChange) ([]*eth.SignedBLSToExecutionChange, error) { +func BlsChangesToConsensus(src []*SignedBLSToExecutionChange) ([]*eth.SignedBLSToExecutionChange, error) { if src == nil { return nil, errNilValue } @@ -3092,7 +3092,7 @@ func BlsChangesToConsensus(src []*SignedBlsToExecutionChange) ([]*eth.SignedBLST if err != nil { return nil, NewDecodeError(err, fmt.Sprintf("[%d].Message.ValidatorIndex", i)) } - pubkey, err := DecodeHexWithLength(ch.Message.FromBlsPubkey, fieldparams.BLSPubkeyLength) + pubkey, err := DecodeHexWithLength(ch.Message.FromBLSPubkey, fieldparams.BLSPubkeyLength) if err != nil { return nil, NewDecodeError(err, fmt.Sprintf("[%d].Message.FromBlsPubkey", i)) } @@ -3112,13 +3112,13 @@ func BlsChangesToConsensus(src []*SignedBlsToExecutionChange) ([]*eth.SignedBLST return changes, nil } -func BlsChangesFromConsensus(src []*eth.SignedBLSToExecutionChange) ([]*SignedBlsToExecutionChange, error) { - changes := make([]*SignedBlsToExecutionChange, len(src)) +func BlsChangesFromConsensus(src []*eth.SignedBLSToExecutionChange) ([]*SignedBLSToExecutionChange, error) { + changes := make([]*SignedBLSToExecutionChange, len(src)) for i, ch := range src { - changes[i] = &SignedBlsToExecutionChange{ - Message: &BlsToExecutionChange{ + changes[i] = &SignedBLSToExecutionChange{ + Message: &BLSToExecutionChange{ ValidatorIndex: fmt.Sprintf("%d", ch.Message.ValidatorIndex), - FromBlsPubkey: hexutil.Encode(ch.Message.FromBlsPubkey), + FromBLSPubkey: hexutil.Encode(ch.Message.FromBlsPubkey), ToExecutionAddress: hexutil.Encode(ch.Message.ToExecutionAddress), }, Signature: hexutil.Encode(ch.Signature), diff --git a/cmd/prysmctl/validator/BUILD.bazel b/cmd/prysmctl/validator/BUILD.bazel index 41cff0cf47..9ae84bba78 100644 --- a/cmd/prysmctl/validator/BUILD.bazel +++ b/cmd/prysmctl/validator/BUILD.bazel @@ -14,7 +14,6 @@ go_library( "//api/client:go_default_library", "//api/client/beacon:go_default_library", "//api/client/validator:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//cmd:go_default_library", "//cmd/validator/accounts:go_default_library", @@ -47,7 +46,6 @@ go_test( data = glob(["testdata/**"]), embed = [":go_default_library"], deps = [ - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/beacon:go_default_library", "//beacon-chain/rpc/eth/config:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", diff --git a/cmd/prysmctl/validator/withdraw.go b/cmd/prysmctl/validator/withdraw.go index c0312fdb74..abadb571cf 100644 --- a/cmd/prysmctl/validator/withdraw.go +++ b/cmd/prysmctl/validator/withdraw.go @@ -14,7 +14,6 @@ import ( "github.com/logrusorgru/aurora" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v4/api/client/beacon" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" @@ -52,7 +51,7 @@ func getWithdrawalMessagesFromPathFlag(c *cli.Context) ([]*shared.SignedBLSToExe if err != nil { return setWithdrawalAddressJsons, errors.Wrap(err, "failed to open file") } - var to []*apimiddleware.SignedBLSToExecutionChangeJson + var to []*shared.SignedBLSToExecutionChange if err := json.Unmarshal(b, &to); err != nil { log.Warnf("provided file: %s, is not a list of signed withdrawal messages. Error:%s", foundFilePath, err.Error()) continue diff --git a/cmd/prysmctl/validator/withdraw_test.go b/cmd/prysmctl/validator/withdraw_test.go index 07d05efba5..0c954e1601 100644 --- a/cmd/prysmctl/validator/withdraw_test.go +++ b/cmd/prysmctl/validator/withdraw_test.go @@ -12,7 +12,6 @@ import ( "testing" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/config" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" @@ -221,8 +220,8 @@ func TestCallWithdrawalEndpoint_Errors(t *testing.T) { if r.Method == http.MethodPost && r.RequestURI == "/eth/v1/beacon/pool/bls_to_execution_changes" { w.WriteHeader(400) w.Header().Set("Content-Type", "application/json") - err = json.NewEncoder(w).Encode(&apimiddleware.IndexedVerificationFailureErrorJson{ - Failures: []*apimiddleware.SingleIndexedVerificationFailureJson{ + err = json.NewEncoder(w).Encode(&shared.IndexedVerificationFailureError{ + Failures: []*shared.IndexedVerificationFailure{ {Index: 0, Message: "Could not validate SignedBLSToExecutionChange"}, }, }) diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index 6e578b9ec2..c05c96af53 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -73,7 +73,7 @@ go_test( data = glob(["testdata/**"]), embed = [":go_default_library"], deps = [ - "//beacon-chain/rpc/apimiddleware:go_default_library", + "//beacon-chain/rpc/eth/shared:go_default_library", "//build/bazel:go_default_library", "//cmd/validator/flags:go_default_library", "//config/fieldparams:go_default_library", diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index 0538d4b535..287a94efad 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -188,7 +188,7 @@ func writeSignedVoluntaryExitJSON(sve *eth.SignedVoluntaryExit, outputDirectory return errors.Wrap(err, "failed to marshal JSON signed voluntary exit") } - filepath := path.Join(outputDirectory, fmt.Sprintf("validator-exit-%s.json", jsve.Exit.ValidatorIndex)) + filepath := path.Join(outputDirectory, fmt.Sprintf("validator-exit-%s.json", jsve.Message.ValidatorIndex)) if err := file.WriteFile(filepath, b); err != nil { return errors.Wrap(err, "failed to write validator exist json") } diff --git a/validator/accounts/accounts_exit_test.go b/validator/accounts/accounts_exit_test.go index 34f8cb4f61..c6d91fbeca 100644 --- a/validator/accounts/accounts_exit_test.go +++ b/validator/accounts/accounts_exit_test.go @@ -6,7 +6,7 @@ import ( "path" "testing" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/build/bazel" fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" @@ -57,10 +57,10 @@ func TestWriteSignedVoluntaryExitJSON(t *testing.T) { b, err := file.ReadFileAsBytes(path.Join(output, "validator-exit-300.json")) require.NoError(t, err) - svej := &apimiddleware.SignedVoluntaryExitJson{} + svej := &shared.SignedVoluntaryExit{} require.NoError(t, json.Unmarshal(b, svej)) - require.Equal(t, fmt.Sprintf("%d", sve.Exit.Epoch), svej.Exit.Epoch) - require.Equal(t, fmt.Sprintf("%d", sve.Exit.ValidatorIndex), svej.Exit.ValidatorIndex) + require.Equal(t, fmt.Sprintf("%d", sve.Exit.Epoch), svej.Message.Epoch) + require.Equal(t, fmt.Sprintf("%d", sve.Exit.ValidatorIndex), svej.Message.ValidatorIndex) require.Equal(t, "0x0102", svej.Signature) } diff --git a/validator/client/beacon-api/BUILD.bazel b/validator/client/beacon-api/BUILD.bazel index b3644dc709..76e1dc98f1 100644 --- a/validator/client/beacon-api/BUILD.bazel +++ b/validator/client/beacon-api/BUILD.bazel @@ -42,8 +42,8 @@ go_library( "//api:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/beacon:go_default_library", + "//beacon-chain/rpc/eth/config:go_default_library", "//beacon-chain/rpc/eth/node:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//beacon-chain/rpc/eth/validator:go_default_library", @@ -115,8 +115,8 @@ go_test( embed = [":go_default_library"], deps = [ "//api:go_default_library", - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/beacon:go_default_library", + "//beacon-chain/rpc/eth/config:go_default_library", "//beacon-chain/rpc/eth/node:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//beacon-chain/rpc/eth/shared/testing:go_default_library", diff --git a/validator/client/beacon-api/beacon_api_node_client.go b/validator/client/beacon-api/beacon_api_node_client.go index 2b6ccf4f71..01912dfddc 100644 --- a/validator/client/beacon-api/beacon_api_node_client.go +++ b/validator/client/beacon-api/beacon_api_node_client.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/config" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/node" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/validator/client/iface" @@ -60,7 +60,7 @@ func (c *beaconApiNodeClient) GetGenesis(ctx context.Context, _ *empty.Empty) (* return nil, errors.Wrapf(err, "failed to parse genesis time `%s`", genesisJson.GenesisTime) } - depositContractJson := apimiddleware.DepositContractResponseJson{} + depositContractJson := config.GetDepositContractResponse{} errJson, err = c.jsonRestHandler.Get(ctx, "/eth/v1/config/deposit_contract", &depositContractJson) if err != nil { return nil, errors.Wrapf(err, msgUnexpectedError) diff --git a/validator/client/beacon-api/beacon_api_node_client_test.go b/validator/client/beacon-api/beacon_api_node_client_test.go index c0f7936655..f530ce4161 100644 --- a/validator/client/beacon-api/beacon_api_node_client_test.go +++ b/validator/client/beacon-api/beacon_api_node_client_test.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/config" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/node" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -22,7 +22,7 @@ func TestGetGenesis(t *testing.T) { name string genesisResponse *beacon.Genesis genesisError error - depositContractResponse apimiddleware.DepositContractResponseJson + depositContractResponse config.GetDepositContractResponse depositContractError error queriesDepositContract bool expectedResponse *ethpb.Genesis @@ -66,7 +66,7 @@ func TestGetGenesis(t *testing.T) { GenesisValidatorsRoot: hexutil.Encode([]byte{2}), }, queriesDepositContract: true, - depositContractResponse: apimiddleware.DepositContractResponseJson{ + depositContractResponse: config.GetDepositContractResponse{ Data: nil, }, expectedError: "deposit contract data is nil", @@ -78,8 +78,8 @@ func TestGetGenesis(t *testing.T) { GenesisValidatorsRoot: hexutil.Encode([]byte{2}), }, queriesDepositContract: true, - depositContractResponse: apimiddleware.DepositContractResponseJson{ - Data: &apimiddleware.DepositContractJson{ + depositContractResponse: config.GetDepositContractResponse{ + Data: &config.DepositContractData{ Address: "foo", }, }, @@ -92,8 +92,8 @@ func TestGetGenesis(t *testing.T) { GenesisValidatorsRoot: hexutil.Encode([]byte{2}), }, queriesDepositContract: true, - depositContractResponse: apimiddleware.DepositContractResponseJson{ - Data: &apimiddleware.DepositContractJson{ + depositContractResponse: config.GetDepositContractResponse{ + Data: &config.DepositContractData{ Address: hexutil.Encode([]byte{3}), }, }, @@ -122,7 +122,7 @@ func TestGetGenesis(t *testing.T) { testCase.genesisError, ) - depositContractJson := apimiddleware.DepositContractResponseJson{} + depositContractJson := config.GetDepositContractResponse{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) if testCase.queriesDepositContract { diff --git a/validator/client/beacon-api/beacon_api_validator_client.go b/validator/client/beacon-api/beacon_api_validator_client.go index 504877f110..2af7464e68 100644 --- a/validator/client/beacon-api/beacon_api_validator_client.go +++ b/validator/client/beacon-api/beacon_api_validator_client.go @@ -19,7 +19,7 @@ type beaconApiValidatorClient struct { dutiesProvider dutiesProvider stateValidatorsProvider StateValidatorsProvider jsonRestHandler JsonRestHandler - beaconBlockConverter beaconBlockConverter + beaconBlockConverter BeaconBlockConverter prysmBeaconChainCLient iface.PrysmBeaconChainClient } diff --git a/validator/client/beacon-api/beacon_block_converter.go b/validator/client/beacon-api/beacon_block_converter.go index aafb858b16..dc783b2f93 100644 --- a/validator/client/beacon-api/beacon_block_converter.go +++ b/validator/client/beacon-api/beacon_block_converter.go @@ -6,24 +6,24 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) -type beaconBlockConverter interface { - ConvertRESTPhase0BlockToProto(block *apimiddleware.BeaconBlockJson) (*ethpb.BeaconBlock, error) - ConvertRESTAltairBlockToProto(block *apimiddleware.BeaconBlockAltairJson) (*ethpb.BeaconBlockAltair, error) - ConvertRESTBellatrixBlockToProto(block *apimiddleware.BeaconBlockBellatrixJson) (*ethpb.BeaconBlockBellatrix, error) - ConvertRESTCapellaBlockToProto(block *apimiddleware.BeaconBlockCapellaJson) (*ethpb.BeaconBlockCapella, error) +type BeaconBlockConverter interface { + ConvertRESTPhase0BlockToProto(block *shared.BeaconBlock) (*ethpb.BeaconBlock, error) + ConvertRESTAltairBlockToProto(block *shared.BeaconBlockAltair) (*ethpb.BeaconBlockAltair, error) + ConvertRESTBellatrixBlockToProto(block *shared.BeaconBlockBellatrix) (*ethpb.BeaconBlockBellatrix, error) + ConvertRESTCapellaBlockToProto(block *shared.BeaconBlockCapella) (*ethpb.BeaconBlockCapella, error) } type beaconApiBeaconBlockConverter struct{} // ConvertRESTPhase0BlockToProto converts a Phase0 JSON beacon block to its protobuf equivalent -func (c beaconApiBeaconBlockConverter) ConvertRESTPhase0BlockToProto(block *apimiddleware.BeaconBlockJson) (*ethpb.BeaconBlock, error) { +func (c beaconApiBeaconBlockConverter) ConvertRESTPhase0BlockToProto(block *shared.BeaconBlock) (*ethpb.BeaconBlock, error) { blockSlot, err := strconv.ParseUint(block.Slot, 10, 64) if err != nil { return nil, errors.Wrapf(err, "failed to parse slot `%s`", block.Slot) @@ -125,19 +125,19 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTPhase0BlockToProto(block *apim } // ConvertRESTAltairBlockToProto converts an Altair JSON beacon block to its protobuf equivalent -func (c beaconApiBeaconBlockConverter) ConvertRESTAltairBlockToProto(block *apimiddleware.BeaconBlockAltairJson) (*ethpb.BeaconBlockAltair, error) { +func (c beaconApiBeaconBlockConverter) ConvertRESTAltairBlockToProto(block *shared.BeaconBlockAltair) (*ethpb.BeaconBlockAltair, error) { if block.Body == nil { return nil, errors.New("block body is nil") } // Call convertRESTPhase0BlockToProto to set the phase0 fields because all the error handling and the heavy lifting // has already been done - phase0Block, err := c.ConvertRESTPhase0BlockToProto(&apimiddleware.BeaconBlockJson{ + phase0Block, err := c.ConvertRESTPhase0BlockToProto(&shared.BeaconBlock{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: block.ParentRoot, StateRoot: block.StateRoot, - Body: &apimiddleware.BeaconBlockBodyJson{ + Body: &shared.BeaconBlockBody{ RandaoReveal: block.Body.RandaoReveal, Eth1Data: block.Body.Eth1Data, Graffiti: block.Body.Graffiti, @@ -189,19 +189,19 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTAltairBlockToProto(block *apim } // ConvertRESTBellatrixBlockToProto converts a Bellatrix JSON beacon block to its protobuf equivalent -func (c beaconApiBeaconBlockConverter) ConvertRESTBellatrixBlockToProto(block *apimiddleware.BeaconBlockBellatrixJson) (*ethpb.BeaconBlockBellatrix, error) { +func (c beaconApiBeaconBlockConverter) ConvertRESTBellatrixBlockToProto(block *shared.BeaconBlockBellatrix) (*ethpb.BeaconBlockBellatrix, error) { if block.Body == nil { return nil, errors.New("block body is nil") } // Call convertRESTAltairBlockToProto to set the altair fields because all the error handling and the heavy lifting // has already been done - altairBlock, err := c.ConvertRESTAltairBlockToProto(&apimiddleware.BeaconBlockAltairJson{ + altairBlock, err := c.ConvertRESTAltairBlockToProto(&shared.BeaconBlockAltair{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: block.ParentRoot, StateRoot: block.StateRoot, - Body: &apimiddleware.BeaconBlockBodyAltairJson{ + Body: &shared.BeaconBlockBodyAltair{ RandaoReveal: block.Body.RandaoReveal, Eth1Data: block.Body.Eth1Data, Graffiti: block.Body.Graffiti, @@ -266,9 +266,9 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTBellatrixBlockToProto(block *a return nil, errors.Wrapf(err, "failed to parse execution payload gas used `%s`", block.Body.ExecutionPayload.GasUsed) } - timestamp, err := strconv.ParseUint(block.Body.ExecutionPayload.TimeStamp, 10, 64) + timestamp, err := strconv.ParseUint(block.Body.ExecutionPayload.Timestamp, 10, 64) if err != nil { - return nil, errors.Wrapf(err, "failed to parse execution payload timestamp `%s`", block.Body.ExecutionPayload.TimeStamp) + return nil, errors.Wrapf(err, "failed to parse execution payload timestamp `%s`", block.Body.ExecutionPayload.Timestamp) } extraData, err := hexutil.Decode(block.Body.ExecutionPayload.ExtraData) @@ -327,7 +327,7 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTBellatrixBlockToProto(block *a } // ConvertRESTCapellaBlockToProto converts a Capella JSON beacon block to its protobuf equivalent -func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *apimiddleware.BeaconBlockCapellaJson) (*ethpb.BeaconBlockCapella, error) { +func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *shared.BeaconBlockCapella) (*ethpb.BeaconBlockCapella, error) { if block.Body == nil { return nil, errors.New("block body is nil") } @@ -338,12 +338,12 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *api // Call convertRESTBellatrixBlockToProto to set the bellatrix fields because all the error handling and the heavy // lifting has already been done - bellatrixBlock, err := c.ConvertRESTBellatrixBlockToProto(&apimiddleware.BeaconBlockBellatrixJson{ + bellatrixBlock, err := c.ConvertRESTBellatrixBlockToProto(&shared.BeaconBlockBellatrix{ Slot: block.Slot, ProposerIndex: block.ProposerIndex, ParentRoot: block.ParentRoot, StateRoot: block.StateRoot, - Body: &apimiddleware.BeaconBlockBodyBellatrixJson{ + Body: &shared.BeaconBlockBodyBellatrix{ RandaoReveal: block.Body.RandaoReveal, Eth1Data: block.Body.Eth1Data, Graffiti: block.Body.Graffiti, @@ -353,7 +353,7 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *api Deposits: block.Body.Deposits, VoluntaryExits: block.Body.VoluntaryExits, SyncAggregate: block.Body.SyncAggregate, - ExecutionPayload: &apimiddleware.ExecutionPayloadJson{ + ExecutionPayload: &shared.ExecutionPayload{ ParentHash: block.Body.ExecutionPayload.ParentHash, FeeRecipient: block.Body.ExecutionPayload.FeeRecipient, StateRoot: block.Body.ExecutionPayload.StateRoot, @@ -363,7 +363,7 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *api BlockNumber: block.Body.ExecutionPayload.BlockNumber, GasLimit: block.Body.ExecutionPayload.GasLimit, GasUsed: block.Body.ExecutionPayload.GasUsed, - TimeStamp: block.Body.ExecutionPayload.TimeStamp, + Timestamp: block.Body.ExecutionPayload.Timestamp, ExtraData: block.Body.ExecutionPayload.ExtraData, BaseFeePerGas: block.Body.ExecutionPayload.BaseFeePerGas, BlockHash: block.Body.ExecutionPayload.BlockHash, @@ -380,7 +380,7 @@ func (c beaconApiBeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *api return nil, errors.Wrap(err, "failed to get withdrawals") } - blsToExecutionChanges, err := convertBlsToExecutionChangesToProto(block.Body.BLSToExecutionChanges) + blsToExecutionChanges, err := convertBlsToExecutionChangesToProto(block.Body.BlsToExecutionChanges) if err != nil { return nil, errors.Wrap(err, "failed to get bls to execution changes") } diff --git a/validator/client/beacon-api/beacon_block_converter_test.go b/validator/client/beacon-api/beacon_block_converter_test.go index feb0f00ff2..0a70209643 100644 --- a/validator/client/beacon-api/beacon_block_converter_test.go +++ b/validator/client/beacon-api/beacon_block_converter_test.go @@ -3,7 +3,7 @@ package beacon_api import ( "testing" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" test_helpers "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/test-helpers" @@ -21,12 +21,12 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { testCases := []struct { name string expectedErrorMessage string - generateData func() *apimiddleware.BeaconBlockJson + generateData func() *shared.BeaconBlock }{ { name: "nil body", expectedErrorMessage: "block body is nil", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body = nil return beaconBlock @@ -35,7 +35,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "nil eth1 data", expectedErrorMessage: "eth1 data is nil", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Eth1Data = nil return beaconBlock @@ -44,7 +44,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad slot", expectedErrorMessage: "failed to parse slot `foo`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Slot = "foo" return beaconBlock @@ -53,7 +53,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad proposer index", expectedErrorMessage: "failed to parse proposer index `bar`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.ProposerIndex = "bar" return beaconBlock @@ -62,7 +62,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad parent root", expectedErrorMessage: "failed to decode parent root `foo`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.ParentRoot = "foo" return beaconBlock @@ -71,7 +71,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad state root", expectedErrorMessage: "failed to decode state root `bar`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.StateRoot = "bar" return beaconBlock @@ -80,7 +80,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad randao reveal", expectedErrorMessage: "failed to decode randao reveal `foo`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.RandaoReveal = "foo" return beaconBlock @@ -89,7 +89,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad deposit root", expectedErrorMessage: "failed to decode deposit root `bar`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Eth1Data.DepositRoot = "bar" return beaconBlock @@ -98,7 +98,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad deposit count", expectedErrorMessage: "failed to parse deposit count `foo`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Eth1Data.DepositCount = "foo" return beaconBlock @@ -107,7 +107,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad block hash", expectedErrorMessage: "failed to decode block hash `bar`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Eth1Data.BlockHash = "bar" return beaconBlock @@ -116,7 +116,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad graffiti", expectedErrorMessage: "failed to decode graffiti `foo`", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Graffiti = "foo" return beaconBlock @@ -125,7 +125,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad proposer slashings", expectedErrorMessage: "failed to get proposer slashings", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.ProposerSlashings[0] = nil return beaconBlock @@ -134,7 +134,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad attester slashings", expectedErrorMessage: "failed to get attester slashings", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.AttesterSlashings[0] = nil return beaconBlock @@ -143,7 +143,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad attestations", expectedErrorMessage: "failed to get attestations", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Attestations[0] = nil return beaconBlock @@ -152,7 +152,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad deposits", expectedErrorMessage: "failed to get deposits", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.Deposits[0] = nil return beaconBlock @@ -161,7 +161,7 @@ func TestGetBeaconBlockConverter_Phase0Error(t *testing.T) { { name: "bad voluntary exits", expectedErrorMessage: "failed to get voluntary exits", - generateData: func() *apimiddleware.BeaconBlockJson { + generateData: func() *shared.BeaconBlock { beaconBlock := test_helpers.GenerateJsonPhase0BeaconBlock() beaconBlock.Body.VoluntaryExits[0] = nil return beaconBlock @@ -192,12 +192,12 @@ func TestGetBeaconBlockConverter_AltairError(t *testing.T) { testCases := []struct { name string expectedErrorMessage string - generateData func() *apimiddleware.BeaconBlockAltairJson + generateData func() *shared.BeaconBlockAltair }{ { name: "nil body", expectedErrorMessage: "block body is nil", - generateData: func() *apimiddleware.BeaconBlockAltairJson { + generateData: func() *shared.BeaconBlockAltair { beaconBlock := test_helpers.GenerateJsonAltairBeaconBlock() beaconBlock.Body = nil return beaconBlock @@ -206,7 +206,7 @@ func TestGetBeaconBlockConverter_AltairError(t *testing.T) { { name: "nil sync aggregate", expectedErrorMessage: "sync aggregate is nil", - generateData: func() *apimiddleware.BeaconBlockAltairJson { + generateData: func() *shared.BeaconBlockAltair { beaconBlock := test_helpers.GenerateJsonAltairBeaconBlock() beaconBlock.Body.SyncAggregate = nil return beaconBlock @@ -215,7 +215,7 @@ func TestGetBeaconBlockConverter_AltairError(t *testing.T) { { name: "bad phase0 fields", expectedErrorMessage: "failed to get the phase0 fields of the altair block", - generateData: func() *apimiddleware.BeaconBlockAltairJson { + generateData: func() *shared.BeaconBlockAltair { beaconBlock := test_helpers.GenerateJsonAltairBeaconBlock() beaconBlock.Body.Eth1Data = nil return beaconBlock @@ -224,7 +224,7 @@ func TestGetBeaconBlockConverter_AltairError(t *testing.T) { { name: "bad sync committee bits", expectedErrorMessage: "failed to decode sync committee bits `foo`", - generateData: func() *apimiddleware.BeaconBlockAltairJson { + generateData: func() *shared.BeaconBlockAltair { beaconBlock := test_helpers.GenerateJsonAltairBeaconBlock() beaconBlock.Body.SyncAggregate.SyncCommitteeBits = "foo" return beaconBlock @@ -233,7 +233,7 @@ func TestGetBeaconBlockConverter_AltairError(t *testing.T) { { name: "bad sync committee signature", expectedErrorMessage: "failed to decode sync committee signature `bar`", - generateData: func() *apimiddleware.BeaconBlockAltairJson { + generateData: func() *shared.BeaconBlockAltair { beaconBlock := test_helpers.GenerateJsonAltairBeaconBlock() beaconBlock.Body.SyncAggregate.SyncCommitteeSignature = "bar" return beaconBlock @@ -264,12 +264,12 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { testCases := []struct { name string expectedErrorMessage string - generateData func() *apimiddleware.BeaconBlockBellatrixJson + generateData func() *shared.BeaconBlockBellatrix }{ { name: "nil body", expectedErrorMessage: "block body is nil", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body = nil return beaconBlock @@ -278,7 +278,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "nil execution payload", expectedErrorMessage: "execution payload is nil", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload = nil return beaconBlock @@ -287,7 +287,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad altair fields", expectedErrorMessage: "failed to get the altair fields of the bellatrix block", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.Eth1Data = nil return beaconBlock @@ -296,7 +296,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad parent hash", expectedErrorMessage: "failed to decode execution payload parent hash `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.ParentHash = "foo" return beaconBlock @@ -305,7 +305,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad fee recipient", expectedErrorMessage: "failed to decode execution payload fee recipient `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.FeeRecipient = "bar" return beaconBlock @@ -314,7 +314,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad state root", expectedErrorMessage: "failed to decode execution payload state root `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.StateRoot = "foo" return beaconBlock @@ -323,7 +323,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad receipts root", expectedErrorMessage: "failed to decode execution payload receipts root `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.ReceiptsRoot = "bar" return beaconBlock @@ -332,7 +332,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad logs bloom", expectedErrorMessage: "failed to decode execution payload logs bloom `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.LogsBloom = "foo" return beaconBlock @@ -341,7 +341,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad prev randao", expectedErrorMessage: "failed to decode execution payload prev randao `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.PrevRandao = "bar" return beaconBlock @@ -350,7 +350,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad block number", expectedErrorMessage: "failed to parse execution payload block number `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.BlockNumber = "foo" return beaconBlock @@ -359,7 +359,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad gas limit", expectedErrorMessage: "failed to parse execution payload gas limit `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.GasLimit = "bar" return beaconBlock @@ -368,7 +368,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad gas used", expectedErrorMessage: "failed to parse execution payload gas used `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.GasUsed = "foo" return beaconBlock @@ -377,16 +377,16 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad timestamp", expectedErrorMessage: "failed to parse execution payload timestamp `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() - beaconBlock.Body.ExecutionPayload.TimeStamp = "bar" + beaconBlock.Body.ExecutionPayload.Timestamp = "bar" return beaconBlock }, }, { name: "bad extra data", expectedErrorMessage: "failed to decode execution payload extra data `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.ExtraData = "foo" return beaconBlock @@ -395,7 +395,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad base fee per gas", expectedErrorMessage: "failed to parse execution payload base fee per gas `bar`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.BaseFeePerGas = "bar" return beaconBlock @@ -404,7 +404,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad block hash", expectedErrorMessage: "failed to decode execution payload block hash `foo`", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.BlockHash = "foo" return beaconBlock @@ -413,7 +413,7 @@ func TestGetBeaconBlockConverter_BellatrixError(t *testing.T) { { name: "bad transactions", expectedErrorMessage: "failed to get execution payload transactions", - generateData: func() *apimiddleware.BeaconBlockBellatrixJson { + generateData: func() *shared.BeaconBlockBellatrix { beaconBlock := test_helpers.GenerateJsonBellatrixBeaconBlock() beaconBlock.Body.ExecutionPayload.Transactions[0] = "bar" return beaconBlock @@ -444,12 +444,12 @@ func TestGetBeaconBlockConverter_CapellaError(t *testing.T) { testCases := []struct { name string expectedErrorMessage string - generateData func() *apimiddleware.BeaconBlockCapellaJson + generateData func() *shared.BeaconBlockCapella }{ { name: "nil body", expectedErrorMessage: "block body is nil", - generateData: func() *apimiddleware.BeaconBlockCapellaJson { + generateData: func() *shared.BeaconBlockCapella { beaconBlock := test_helpers.GenerateJsonCapellaBeaconBlock() beaconBlock.Body = nil return beaconBlock @@ -458,7 +458,7 @@ func TestGetBeaconBlockConverter_CapellaError(t *testing.T) { { name: "nil execution payload", expectedErrorMessage: "execution payload is nil", - generateData: func() *apimiddleware.BeaconBlockCapellaJson { + generateData: func() *shared.BeaconBlockCapella { beaconBlock := test_helpers.GenerateJsonCapellaBeaconBlock() beaconBlock.Body.ExecutionPayload = nil return beaconBlock @@ -467,7 +467,7 @@ func TestGetBeaconBlockConverter_CapellaError(t *testing.T) { { name: "bad bellatrix fields", expectedErrorMessage: "failed to get the bellatrix fields of the capella block", - generateData: func() *apimiddleware.BeaconBlockCapellaJson { + generateData: func() *shared.BeaconBlockCapella { beaconBlock := test_helpers.GenerateJsonCapellaBeaconBlock() beaconBlock.Body.Eth1Data = nil return beaconBlock @@ -476,7 +476,7 @@ func TestGetBeaconBlockConverter_CapellaError(t *testing.T) { { name: "bad withdrawals", expectedErrorMessage: "failed to get withdrawals", - generateData: func() *apimiddleware.BeaconBlockCapellaJson { + generateData: func() *shared.BeaconBlockCapella { beaconBlock := test_helpers.GenerateJsonCapellaBeaconBlock() beaconBlock.Body.ExecutionPayload.Withdrawals[0] = nil return beaconBlock @@ -485,9 +485,9 @@ func TestGetBeaconBlockConverter_CapellaError(t *testing.T) { { name: "bad bls execution changes", expectedErrorMessage: "failed to get bls to execution changes", - generateData: func() *apimiddleware.BeaconBlockCapellaJson { + generateData: func() *shared.BeaconBlockCapella { beaconBlock := test_helpers.GenerateJsonCapellaBeaconBlock() - beaconBlock.Body.BLSToExecutionChanges[0] = nil + beaconBlock.Body.BlsToExecutionChanges[0] = nil return beaconBlock }, }, diff --git a/validator/client/beacon-api/beacon_block_json_helpers.go b/validator/client/beacon-api/beacon_block_json_helpers.go index 599e12798f..ce314ecd4e 100644 --- a/validator/client/beacon-api/beacon_block_json_helpers.go +++ b/validator/client/beacon-api/beacon_block_json_helpers.go @@ -4,7 +4,7 @@ import ( "strconv" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -18,16 +18,15 @@ func jsonifyTransactions(transactions [][]byte) []string { return jsonTransactions } -// TODO: remove when apimiddleware is migrated away -func jsonifyBlsToExecutionChanges(blsToExecutionChanges []*ethpb.SignedBLSToExecutionChange) []*apimiddleware.SignedBLSToExecutionChangeJson { - jsonBlsToExecutionChanges := make([]*apimiddleware.SignedBLSToExecutionChangeJson, len(blsToExecutionChanges)) +func jsonifyBlsToExecutionChanges(blsToExecutionChanges []*ethpb.SignedBLSToExecutionChange) []*shared.SignedBLSToExecutionChange { + jsonBlsToExecutionChanges := make([]*shared.SignedBLSToExecutionChange, len(blsToExecutionChanges)) for index, signedBlsToExecutionChange := range blsToExecutionChanges { - blsToExecutionChangeJson := &apimiddleware.BLSToExecutionChangeJson{ + blsToExecutionChangeJson := &shared.BLSToExecutionChange{ ValidatorIndex: uint64ToString(signedBlsToExecutionChange.Message.ValidatorIndex), FromBLSPubkey: hexutil.Encode(signedBlsToExecutionChange.Message.FromBlsPubkey), ToExecutionAddress: hexutil.Encode(signedBlsToExecutionChange.Message.ToExecutionAddress), } - signedJson := &apimiddleware.SignedBLSToExecutionChangeJson{ + signedJson := &shared.SignedBLSToExecutionChange{ Message: blsToExecutionChangeJson, Signature: hexutil.Encode(signedBlsToExecutionChange.Signature), } @@ -36,46 +35,46 @@ func jsonifyBlsToExecutionChanges(blsToExecutionChanges []*ethpb.SignedBLSToExec return jsonBlsToExecutionChanges } -func jsonifyEth1Data(eth1Data *ethpb.Eth1Data) *apimiddleware.Eth1DataJson { - return &apimiddleware.Eth1DataJson{ +func jsonifyEth1Data(eth1Data *ethpb.Eth1Data) *shared.Eth1Data { + return &shared.Eth1Data{ BlockHash: hexutil.Encode(eth1Data.BlockHash), DepositCount: uint64ToString(eth1Data.DepositCount), DepositRoot: hexutil.Encode(eth1Data.DepositRoot), } } -func jsonifyAttestations(attestations []*ethpb.Attestation) []*apimiddleware.AttestationJson { - jsonAttestations := make([]*apimiddleware.AttestationJson, len(attestations)) +func jsonifyAttestations(attestations []*ethpb.Attestation) []*shared.Attestation { + jsonAttestations := make([]*shared.Attestation, len(attestations)) for index, attestation := range attestations { jsonAttestations[index] = jsonifyAttestation(attestation) } return jsonAttestations } -func jsonifyAttesterSlashings(attesterSlashings []*ethpb.AttesterSlashing) []*apimiddleware.AttesterSlashingJson { - jsonAttesterSlashings := make([]*apimiddleware.AttesterSlashingJson, len(attesterSlashings)) +func jsonifyAttesterSlashings(attesterSlashings []*ethpb.AttesterSlashing) []*shared.AttesterSlashing { + jsonAttesterSlashings := make([]*shared.AttesterSlashing, len(attesterSlashings)) for index, attesterSlashing := range attesterSlashings { - jsonAttesterSlashing := &apimiddleware.AttesterSlashingJson{ - Attestation_1: jsonifyIndexedAttestation(attesterSlashing.Attestation_1), - Attestation_2: jsonifyIndexedAttestation(attesterSlashing.Attestation_2), + jsonAttesterSlashing := &shared.AttesterSlashing{ + Attestation1: jsonifyIndexedAttestation(attesterSlashing.Attestation_1), + Attestation2: jsonifyIndexedAttestation(attesterSlashing.Attestation_2), } jsonAttesterSlashings[index] = jsonAttesterSlashing } return jsonAttesterSlashings } -func jsonifyDeposits(deposits []*ethpb.Deposit) []*apimiddleware.DepositJson { - jsonDeposits := make([]*apimiddleware.DepositJson, len(deposits)) +func jsonifyDeposits(deposits []*ethpb.Deposit) []*shared.Deposit { + jsonDeposits := make([]*shared.Deposit, len(deposits)) for depositIndex, deposit := range deposits { proofs := make([]string, len(deposit.Proof)) for proofIndex, proof := range deposit.Proof { proofs[proofIndex] = hexutil.Encode(proof) } - jsonDeposit := &apimiddleware.DepositJson{ - Data: &apimiddleware.Deposit_DataJson{ + jsonDeposit := &shared.Deposit{ + Data: &shared.DepositData{ Amount: uint64ToString(deposit.Data.Amount), - PublicKey: hexutil.Encode(deposit.Data.PublicKey), + Pubkey: hexutil.Encode(deposit.Data.PublicKey), Signature: hexutil.Encode(deposit.Data.Signature), WithdrawalCredentials: hexutil.Encode(deposit.Data.WithdrawalCredentials), }, @@ -86,12 +85,12 @@ func jsonifyDeposits(deposits []*ethpb.Deposit) []*apimiddleware.DepositJson { return jsonDeposits } -func jsonifyProposerSlashings(proposerSlashings []*ethpb.ProposerSlashing) []*apimiddleware.ProposerSlashingJson { - jsonProposerSlashings := make([]*apimiddleware.ProposerSlashingJson, len(proposerSlashings)) +func jsonifyProposerSlashings(proposerSlashings []*ethpb.ProposerSlashing) []*shared.ProposerSlashing { + jsonProposerSlashings := make([]*shared.ProposerSlashing, len(proposerSlashings)) for index, proposerSlashing := range proposerSlashings { - jsonProposerSlashing := &apimiddleware.ProposerSlashingJson{ - Header_1: jsonifySignedBeaconBlockHeader(proposerSlashing.Header_1), - Header_2: jsonifySignedBeaconBlockHeader(proposerSlashing.Header_2), + jsonProposerSlashing := &shared.ProposerSlashing{ + SignedHeader1: jsonifySignedBeaconBlockHeader(proposerSlashing.Header_1), + SignedHeader2: jsonifySignedBeaconBlockHeader(proposerSlashing.Header_2), } jsonProposerSlashings[index] = jsonProposerSlashing } @@ -99,11 +98,11 @@ func jsonifyProposerSlashings(proposerSlashings []*ethpb.ProposerSlashing) []*ap } // JsonifySignedVoluntaryExits converts an array of voluntary exit structs to a JSON hex string compatible format. -func JsonifySignedVoluntaryExits(voluntaryExits []*ethpb.SignedVoluntaryExit) []*apimiddleware.SignedVoluntaryExitJson { - jsonSignedVoluntaryExits := make([]*apimiddleware.SignedVoluntaryExitJson, len(voluntaryExits)) +func JsonifySignedVoluntaryExits(voluntaryExits []*ethpb.SignedVoluntaryExit) []*shared.SignedVoluntaryExit { + jsonSignedVoluntaryExits := make([]*shared.SignedVoluntaryExit, len(voluntaryExits)) for index, signedVoluntaryExit := range voluntaryExits { - jsonSignedVoluntaryExit := &apimiddleware.SignedVoluntaryExitJson{ - Exit: &apimiddleware.VoluntaryExitJson{ + jsonSignedVoluntaryExit := &shared.SignedVoluntaryExit{ + Message: &shared.VoluntaryExit{ Epoch: uint64ToString(signedVoluntaryExit.Exit.Epoch), ValidatorIndex: uint64ToString(signedVoluntaryExit.Exit.ValidatorIndex), }, @@ -114,9 +113,9 @@ func JsonifySignedVoluntaryExits(voluntaryExits []*ethpb.SignedVoluntaryExit) [] return jsonSignedVoluntaryExits } -func jsonifySignedBeaconBlockHeader(signedBeaconBlockHeader *ethpb.SignedBeaconBlockHeader) *apimiddleware.SignedBeaconBlockHeaderJson { - return &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ +func jsonifySignedBeaconBlockHeader(signedBeaconBlockHeader *ethpb.SignedBeaconBlockHeader) *shared.SignedBeaconBlockHeader { + return &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ BodyRoot: hexutil.Encode(signedBeaconBlockHeader.Header.BodyRoot), ParentRoot: hexutil.Encode(signedBeaconBlockHeader.Header.ParentRoot), ProposerIndex: uint64ToString(signedBeaconBlockHeader.Header.ProposerIndex), @@ -127,47 +126,47 @@ func jsonifySignedBeaconBlockHeader(signedBeaconBlockHeader *ethpb.SignedBeaconB } } -func jsonifyIndexedAttestation(indexedAttestation *ethpb.IndexedAttestation) *apimiddleware.IndexedAttestationJson { +func jsonifyIndexedAttestation(indexedAttestation *ethpb.IndexedAttestation) *shared.IndexedAttestation { attestingIndices := make([]string, len(indexedAttestation.AttestingIndices)) for index, attestingIndex := range indexedAttestation.AttestingIndices { attestingIndex := uint64ToString(attestingIndex) attestingIndices[index] = attestingIndex } - return &apimiddleware.IndexedAttestationJson{ + return &shared.IndexedAttestation{ AttestingIndices: attestingIndices, Data: jsonifyAttestationData(indexedAttestation.Data), Signature: hexutil.Encode(indexedAttestation.Signature), } } -func jsonifyAttestationData(attestationData *ethpb.AttestationData) *apimiddleware.AttestationDataJson { - return &apimiddleware.AttestationDataJson{ +func jsonifyAttestationData(attestationData *ethpb.AttestationData) *shared.AttestationData { + return &shared.AttestationData{ BeaconBlockRoot: hexutil.Encode(attestationData.BeaconBlockRoot), CommitteeIndex: uint64ToString(attestationData.CommitteeIndex), Slot: uint64ToString(attestationData.Slot), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: uint64ToString(attestationData.Source.Epoch), Root: hexutil.Encode(attestationData.Source.Root), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: uint64ToString(attestationData.Target.Epoch), Root: hexutil.Encode(attestationData.Target.Root), }, } } -func jsonifyAttestation(attestation *ethpb.Attestation) *apimiddleware.AttestationJson { - return &apimiddleware.AttestationJson{ +func jsonifyAttestation(attestation *ethpb.Attestation) *shared.Attestation { + return &shared.Attestation{ AggregationBits: hexutil.Encode(attestation.AggregationBits), Data: jsonifyAttestationData(attestation.Data), Signature: hexutil.Encode(attestation.Signature), } } -func jsonifySignedAggregateAndProof(signedAggregateAndProof *ethpb.SignedAggregateAttestationAndProof) *apimiddleware.SignedAggregateAttestationAndProofJson { - return &apimiddleware.SignedAggregateAttestationAndProofJson{ - Message: &apimiddleware.AggregateAttestationAndProofJson{ +func jsonifySignedAggregateAndProof(signedAggregateAndProof *ethpb.SignedAggregateAttestationAndProof) *shared.SignedAggregateAttestationAndProof { + return &shared.SignedAggregateAttestationAndProof{ + Message: &shared.AggregateAttestationAndProof{ AggregatorIndex: uint64ToString(signedAggregateAndProof.Message.AggregatorIndex), Aggregate: jsonifyAttestation(signedAggregateAndProof.Message.Aggregate), SelectionProof: hexutil.Encode(signedAggregateAndProof.Message.SelectionProof), @@ -176,10 +175,10 @@ func jsonifySignedAggregateAndProof(signedAggregateAndProof *ethpb.SignedAggrega } } -func jsonifyWithdrawals(withdrawals []*enginev1.Withdrawal) []*apimiddleware.WithdrawalJson { - jsonWithdrawals := make([]*apimiddleware.WithdrawalJson, len(withdrawals)) +func jsonifyWithdrawals(withdrawals []*enginev1.Withdrawal) []*shared.Withdrawal { + jsonWithdrawals := make([]*shared.Withdrawal, len(withdrawals)) for index, withdrawal := range withdrawals { - jsonWithdrawals[index] = &apimiddleware.WithdrawalJson{ + jsonWithdrawals[index] = &shared.Withdrawal{ WithdrawalIndex: strconv.FormatUint(withdrawal.Index, 10), ValidatorIndex: strconv.FormatUint(uint64(withdrawal.ValidatorIndex), 10), ExecutionAddress: hexutil.Encode(withdrawal.Address), diff --git a/validator/client/beacon-api/beacon_block_json_helpers_test.go b/validator/client/beacon-api/beacon_block_json_helpers_test.go index 2b5e18859f..97ef526f73 100644 --- a/validator/client/beacon-api/beacon_block_json_helpers_test.go +++ b/validator/client/beacon-api/beacon_block_json_helpers_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -77,7 +76,7 @@ func TestBeaconBlockJsonHelpers_JsonifyEth1Data(t *testing.T) { BlockHash: []byte{3}, } - expectedResult := &apimiddleware.Eth1DataJson{ + expectedResult := &shared.Eth1Data{ DepositRoot: hexutil.Encode([]byte{1}), DepositCount: "2", BlockHash: hexutil.Encode([]byte{3}), @@ -125,18 +124,18 @@ func TestBeaconBlockJsonHelpers_JsonifyAttestations(t *testing.T) { }, } - expectedResult := []*apimiddleware.AttestationJson{ + expectedResult := []*shared.Attestation{ { AggregationBits: hexutil.Encode([]byte{1}), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "2", CommitteeIndex: "3", BeaconBlockRoot: hexutil.Encode([]byte{4}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "5", Root: hexutil.Encode([]byte{6}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "7", Root: hexutil.Encode([]byte{8}), }, @@ -145,15 +144,15 @@ func TestBeaconBlockJsonHelpers_JsonifyAttestations(t *testing.T) { }, { AggregationBits: hexutil.Encode([]byte{10}), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "11", CommitteeIndex: "12", BeaconBlockRoot: hexutil.Encode([]byte{13}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "14", Root: hexutil.Encode([]byte{15}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "16", Root: hexutil.Encode([]byte{17}), }, @@ -242,36 +241,36 @@ func TestBeaconBlockJsonHelpers_JsonifyAttesterSlashings(t *testing.T) { }, } - expectedResult := []*apimiddleware.AttesterSlashingJson{ + expectedResult := []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"1", "2"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "3", CommitteeIndex: "4", BeaconBlockRoot: hexutil.Encode([]byte{5}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "8", Root: hexutil.Encode([]byte{9}), }, }, Signature: hexutil.Encode([]byte{10}), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"11", "12"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "13", CommitteeIndex: "14", BeaconBlockRoot: hexutil.Encode([]byte{15}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "16", Root: hexutil.Encode([]byte{17}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "18", Root: hexutil.Encode([]byte{19}), }, @@ -280,34 +279,34 @@ func TestBeaconBlockJsonHelpers_JsonifyAttesterSlashings(t *testing.T) { }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"21", "22"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "23", CommitteeIndex: "24", BeaconBlockRoot: hexutil.Encode([]byte{25}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "26", Root: hexutil.Encode([]byte{27}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "28", Root: hexutil.Encode([]byte{29}), }, }, Signature: hexutil.Encode([]byte{30}), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"31", "32"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "33", CommitteeIndex: "34", BeaconBlockRoot: hexutil.Encode([]byte{35}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "36", Root: hexutil.Encode([]byte{37}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "38", Root: hexutil.Encode([]byte{39}), }, @@ -346,14 +345,14 @@ func TestBeaconBlockJsonHelpers_JsonifyDeposits(t *testing.T) { }, } - expectedResult := []*apimiddleware.DepositJson{ + expectedResult := []*shared.Deposit{ { Proof: []string{ hexutil.Encode([]byte{1}), hexutil.Encode([]byte{2}), }, - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: hexutil.Encode([]byte{3}), + Data: &shared.DepositData{ + Pubkey: hexutil.Encode([]byte{3}), WithdrawalCredentials: hexutil.Encode([]byte{4}), Amount: "5", Signature: hexutil.Encode([]byte{6}), @@ -364,8 +363,8 @@ func TestBeaconBlockJsonHelpers_JsonifyDeposits(t *testing.T) { hexutil.Encode([]byte{7}), hexutil.Encode([]byte{8}), }, - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: hexutil.Encode([]byte{9}), + Data: &shared.DepositData{ + Pubkey: hexutil.Encode([]byte{9}), WithdrawalCredentials: hexutil.Encode([]byte{10}), Amount: "11", Signature: hexutil.Encode([]byte{12}), @@ -425,10 +424,10 @@ func TestBeaconBlockJsonHelpers_JsonifyProposerSlashings(t *testing.T) { }, } - expectedResult := []*apimiddleware.ProposerSlashingJson{ + expectedResult := []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "1", ProposerIndex: "2", ParentRoot: hexutil.Encode([]byte{3}), @@ -437,8 +436,8 @@ func TestBeaconBlockJsonHelpers_JsonifyProposerSlashings(t *testing.T) { }, Signature: hexutil.Encode([]byte{6}), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "7", ProposerIndex: "8", ParentRoot: hexutil.Encode([]byte{9}), @@ -449,8 +448,8 @@ func TestBeaconBlockJsonHelpers_JsonifyProposerSlashings(t *testing.T) { }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "13", ProposerIndex: "14", ParentRoot: hexutil.Encode([]byte{15}), @@ -459,8 +458,8 @@ func TestBeaconBlockJsonHelpers_JsonifyProposerSlashings(t *testing.T) { }, Signature: hexutil.Encode([]byte{18}), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "19", ProposerIndex: "20", ParentRoot: hexutil.Encode([]byte{21}), @@ -494,16 +493,16 @@ func TestBeaconBlockJsonHelpers_JsonifySignedVoluntaryExits(t *testing.T) { }, } - expectedResult := []*apimiddleware.SignedVoluntaryExitJson{ + expectedResult := []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "1", ValidatorIndex: "2", }, Signature: hexutil.Encode([]byte{3}), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "4", ValidatorIndex: "5", }, @@ -527,8 +526,8 @@ func TestBeaconBlockJsonHelpers_JsonifySignedBeaconBlockHeader(t *testing.T) { Signature: []byte{6}, } - expectedResult := &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + expectedResult := &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "1", ProposerIndex: "2", ParentRoot: hexutil.Encode([]byte{3}), @@ -561,17 +560,17 @@ func TestBeaconBlockJsonHelpers_JsonifyIndexedAttestation(t *testing.T) { Signature: []byte{10}, } - expectedResult := &apimiddleware.IndexedAttestationJson{ + expectedResult := &shared.IndexedAttestation{ AttestingIndices: []string{"1", "2"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "3", CommitteeIndex: "4", BeaconBlockRoot: hexutil.Encode([]byte{5}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "8", Root: hexutil.Encode([]byte{9}), }, @@ -598,15 +597,15 @@ func TestBeaconBlockJsonHelpers_JsonifyAttestationData(t *testing.T) { }, } - expectedResult := &apimiddleware.AttestationDataJson{ + expectedResult := &shared.AttestationData{ Slot: "1", CommitteeIndex: "2", BeaconBlockRoot: hexutil.Encode([]byte{3}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "4", Root: hexutil.Encode([]byte{5}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, @@ -632,7 +631,7 @@ func TestBeaconBlockJsonHelpers_JsonifyWithdrawals(t *testing.T) { }, } - expectedResult := []*apimiddleware.WithdrawalJson{ + expectedResult := []*shared.Withdrawal{ { WithdrawalIndex: "1", ValidatorIndex: "2", diff --git a/validator/client/beacon-api/beacon_block_proto_helpers.go b/validator/client/beacon-api/beacon_block_proto_helpers.go index 5ed016a36b..e5e6cfb210 100644 --- a/validator/client/beacon-api/beacon_block_proto_helpers.go +++ b/validator/client/beacon-api/beacon_block_proto_helpers.go @@ -5,13 +5,13 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) -func convertProposerSlashingsToProto(jsonProposerSlashings []*apimiddleware.ProposerSlashingJson) ([]*ethpb.ProposerSlashing, error) { +func convertProposerSlashingsToProto(jsonProposerSlashings []*shared.ProposerSlashing) ([]*ethpb.ProposerSlashing, error) { proposerSlashings := make([]*ethpb.ProposerSlashing, len(jsonProposerSlashings)) for index, jsonProposerSlashing := range jsonProposerSlashings { @@ -19,12 +19,12 @@ func convertProposerSlashingsToProto(jsonProposerSlashings []*apimiddleware.Prop return nil, errors.Errorf("proposer slashing at index `%d` is nil", index) } - header1, err := convertProposerSlashingSignedHeaderToProto(jsonProposerSlashing.Header_1) + header1, err := convertProposerSlashingSignedHeaderToProto(jsonProposerSlashing.SignedHeader1) if err != nil { return nil, errors.Wrap(err, "failed to get proposer header 1") } - header2, err := convertProposerSlashingSignedHeaderToProto(jsonProposerSlashing.Header_2) + header2, err := convertProposerSlashingSignedHeaderToProto(jsonProposerSlashing.SignedHeader2) if err != nil { return nil, errors.Wrap(err, "failed to get proposer header 2") } @@ -38,38 +38,38 @@ func convertProposerSlashingsToProto(jsonProposerSlashings []*apimiddleware.Prop return proposerSlashings, nil } -func convertProposerSlashingSignedHeaderToProto(signedHeader *apimiddleware.SignedBeaconBlockHeaderJson) (*ethpb.SignedBeaconBlockHeader, error) { +func convertProposerSlashingSignedHeaderToProto(signedHeader *shared.SignedBeaconBlockHeader) (*ethpb.SignedBeaconBlockHeader, error) { if signedHeader == nil { return nil, errors.New("signed header is nil") } - if signedHeader.Header == nil { + if signedHeader.Message == nil { return nil, errors.New("header is nil") } - slot, err := strconv.ParseUint(signedHeader.Header.Slot, 10, 64) + slot, err := strconv.ParseUint(signedHeader.Message.Slot, 10, 64) if err != nil { - return nil, errors.Wrapf(err, "failed to parse header slot `%s`", signedHeader.Header.Slot) + return nil, errors.Wrapf(err, "failed to parse header slot `%s`", signedHeader.Message.Slot) } - proposerIndex, err := strconv.ParseUint(signedHeader.Header.ProposerIndex, 10, 64) + proposerIndex, err := strconv.ParseUint(signedHeader.Message.ProposerIndex, 10, 64) if err != nil { - return nil, errors.Wrapf(err, "failed to parse header proposer index `%s`", signedHeader.Header.ProposerIndex) + return nil, errors.Wrapf(err, "failed to parse header proposer index `%s`", signedHeader.Message.ProposerIndex) } - parentRoot, err := hexutil.Decode(signedHeader.Header.ParentRoot) + parentRoot, err := hexutil.Decode(signedHeader.Message.ParentRoot) if err != nil { - return nil, errors.Wrapf(err, "failed to decode header parent root `%s`", signedHeader.Header.ParentRoot) + return nil, errors.Wrapf(err, "failed to decode header parent root `%s`", signedHeader.Message.ParentRoot) } - stateRoot, err := hexutil.Decode(signedHeader.Header.StateRoot) + stateRoot, err := hexutil.Decode(signedHeader.Message.StateRoot) if err != nil { - return nil, errors.Wrapf(err, "failed to decode header state root `%s`", signedHeader.Header.StateRoot) + return nil, errors.Wrapf(err, "failed to decode header state root `%s`", signedHeader.Message.StateRoot) } - bodyRoot, err := hexutil.Decode(signedHeader.Header.BodyRoot) + bodyRoot, err := hexutil.Decode(signedHeader.Message.BodyRoot) if err != nil { - return nil, errors.Wrapf(err, "failed to decode header body root `%s`", signedHeader.Header.BodyRoot) + return nil, errors.Wrapf(err, "failed to decode header body root `%s`", signedHeader.Message.BodyRoot) } signature, err := hexutil.Decode(signedHeader.Signature) @@ -89,7 +89,7 @@ func convertProposerSlashingSignedHeaderToProto(signedHeader *apimiddleware.Sign }, nil } -func convertAttesterSlashingsToProto(jsonAttesterSlashings []*apimiddleware.AttesterSlashingJson) ([]*ethpb.AttesterSlashing, error) { +func convertAttesterSlashingsToProto(jsonAttesterSlashings []*shared.AttesterSlashing) ([]*ethpb.AttesterSlashing, error) { attesterSlashings := make([]*ethpb.AttesterSlashing, len(jsonAttesterSlashings)) for index, jsonAttesterSlashing := range jsonAttesterSlashings { @@ -97,12 +97,12 @@ func convertAttesterSlashingsToProto(jsonAttesterSlashings []*apimiddleware.Atte return nil, errors.Errorf("attester slashing at index `%d` is nil", index) } - attestation1, err := convertIndexedAttestationToProto(jsonAttesterSlashing.Attestation_1) + attestation1, err := convertIndexedAttestationToProto(jsonAttesterSlashing.Attestation1) if err != nil { return nil, errors.Wrap(err, "failed to get attestation 1") } - attestation2, err := convertIndexedAttestationToProto(jsonAttesterSlashing.Attestation_2) + attestation2, err := convertIndexedAttestationToProto(jsonAttesterSlashing.Attestation2) if err != nil { return nil, errors.Wrap(err, "failed to get attestation 2") } @@ -116,7 +116,7 @@ func convertAttesterSlashingsToProto(jsonAttesterSlashings []*apimiddleware.Atte return attesterSlashings, nil } -func convertIndexedAttestationToProto(jsonAttestation *apimiddleware.IndexedAttestationJson) (*ethpb.IndexedAttestation, error) { +func convertIndexedAttestationToProto(jsonAttestation *shared.IndexedAttestation) (*ethpb.IndexedAttestation, error) { if jsonAttestation == nil { return nil, errors.New("indexed attestation is nil") } @@ -149,7 +149,7 @@ func convertIndexedAttestationToProto(jsonAttestation *apimiddleware.IndexedAtte }, nil } -func convertCheckpointToProto(jsonCheckpoint *apimiddleware.CheckpointJson) (*ethpb.Checkpoint, error) { +func convertCheckpointToProto(jsonCheckpoint *shared.Checkpoint) (*ethpb.Checkpoint, error) { if jsonCheckpoint == nil { return nil, errors.New("checkpoint is nil") } @@ -170,7 +170,7 @@ func convertCheckpointToProto(jsonCheckpoint *apimiddleware.CheckpointJson) (*et }, nil } -func convertAttestationToProto(jsonAttestation *apimiddleware.AttestationJson) (*ethpb.Attestation, error) { +func convertAttestationToProto(jsonAttestation *shared.Attestation) (*ethpb.Attestation, error) { if jsonAttestation == nil { return nil, errors.New("json attestation is nil") } @@ -197,7 +197,7 @@ func convertAttestationToProto(jsonAttestation *apimiddleware.AttestationJson) ( }, nil } -func convertAttestationsToProto(jsonAttestations []*apimiddleware.AttestationJson) ([]*ethpb.Attestation, error) { +func convertAttestationsToProto(jsonAttestations []*shared.Attestation) ([]*ethpb.Attestation, error) { var attestations []*ethpb.Attestation for index, jsonAttestation := range jsonAttestations { if jsonAttestation == nil { @@ -215,7 +215,7 @@ func convertAttestationsToProto(jsonAttestations []*apimiddleware.AttestationJso return attestations, nil } -func convertAttestationDataToProto(jsonAttestationData *apimiddleware.AttestationDataJson) (*ethpb.AttestationData, error) { +func convertAttestationDataToProto(jsonAttestationData *shared.AttestationData) (*ethpb.AttestationData, error) { if jsonAttestationData == nil { return nil, errors.New("attestation data is nil") } @@ -254,7 +254,7 @@ func convertAttestationDataToProto(jsonAttestationData *apimiddleware.Attestatio }, nil } -func convertDepositsToProto(jsonDeposits []*apimiddleware.DepositJson) ([]*ethpb.Deposit, error) { +func convertDepositsToProto(jsonDeposits []*shared.Deposit) ([]*ethpb.Deposit, error) { deposits := make([]*ethpb.Deposit, len(jsonDeposits)) for depositIndex, jsonDeposit := range jsonDeposits { @@ -276,9 +276,9 @@ func convertDepositsToProto(jsonDeposits []*apimiddleware.DepositJson) ([]*ethpb return nil, errors.Errorf("deposit data at index `%d` is nil", depositIndex) } - pubkey, err := hexutil.Decode(jsonDeposit.Data.PublicKey) + pubkey, err := hexutil.Decode(jsonDeposit.Data.Pubkey) if err != nil { - return nil, errors.Wrapf(err, "failed to decode deposit public key `%s`", jsonDeposit.Data.PublicKey) + return nil, errors.Wrapf(err, "failed to decode deposit public key `%s`", jsonDeposit.Data.Pubkey) } withdrawalCredentials, err := hexutil.Decode(jsonDeposit.Data.WithdrawalCredentials) @@ -310,7 +310,7 @@ func convertDepositsToProto(jsonDeposits []*apimiddleware.DepositJson) ([]*ethpb return deposits, nil } -func convertVoluntaryExitsToProto(jsonVoluntaryExits []*apimiddleware.SignedVoluntaryExitJson) ([]*ethpb.SignedVoluntaryExit, error) { +func convertVoluntaryExitsToProto(jsonVoluntaryExits []*shared.SignedVoluntaryExit) ([]*ethpb.SignedVoluntaryExit, error) { attestingIndices := make([]*ethpb.SignedVoluntaryExit, len(jsonVoluntaryExits)) for index, jsonVoluntaryExit := range jsonVoluntaryExits { @@ -318,18 +318,18 @@ func convertVoluntaryExitsToProto(jsonVoluntaryExits []*apimiddleware.SignedVolu return nil, errors.Errorf("signed voluntary exit at index `%d` is nil", index) } - if jsonVoluntaryExit.Exit == nil { + if jsonVoluntaryExit.Message == nil { return nil, errors.Errorf("voluntary exit at index `%d` is nil", index) } - epoch, err := strconv.ParseUint(jsonVoluntaryExit.Exit.Epoch, 10, 64) + epoch, err := strconv.ParseUint(jsonVoluntaryExit.Message.Epoch, 10, 64) if err != nil { - return nil, errors.Wrapf(err, "failed to parse voluntary exit epoch `%s`", jsonVoluntaryExit.Exit.Epoch) + return nil, errors.Wrapf(err, "failed to parse voluntary exit epoch `%s`", jsonVoluntaryExit.Message.Epoch) } - validatorIndex, err := strconv.ParseUint(jsonVoluntaryExit.Exit.ValidatorIndex, 10, 64) + validatorIndex, err := strconv.ParseUint(jsonVoluntaryExit.Message.ValidatorIndex, 10, 64) if err != nil { - return nil, errors.Wrapf(err, "failed to parse voluntary exit validator index `%s`", jsonVoluntaryExit.Exit.ValidatorIndex) + return nil, errors.Wrapf(err, "failed to parse voluntary exit validator index `%s`", jsonVoluntaryExit.Message.ValidatorIndex) } signature, err := hexutil.Decode(jsonVoluntaryExit.Signature) @@ -364,7 +364,7 @@ func convertTransactionsToProto(jsonTransactions []string) ([][]byte, error) { return transactions, nil } -func convertWithdrawalsToProto(jsonWithdrawals []*apimiddleware.WithdrawalJson) ([]*enginev1.Withdrawal, error) { +func convertWithdrawalsToProto(jsonWithdrawals []*shared.Withdrawal) ([]*enginev1.Withdrawal, error) { withdrawals := make([]*enginev1.Withdrawal, len(jsonWithdrawals)) for index, jsonWithdrawal := range jsonWithdrawals { @@ -403,7 +403,7 @@ func convertWithdrawalsToProto(jsonWithdrawals []*apimiddleware.WithdrawalJson) return withdrawals, nil } -func convertBlsToExecutionChangesToProto(jsonSignedBlsToExecutionChanges []*apimiddleware.SignedBLSToExecutionChangeJson) ([]*ethpb.SignedBLSToExecutionChange, error) { +func convertBlsToExecutionChangesToProto(jsonSignedBlsToExecutionChanges []*shared.SignedBLSToExecutionChange) ([]*ethpb.SignedBLSToExecutionChange, error) { signedBlsToExecutionChanges := make([]*ethpb.SignedBLSToExecutionChange, len(jsonSignedBlsToExecutionChanges)) for index, jsonBlsToExecutionChange := range jsonSignedBlsToExecutionChanges { diff --git a/validator/client/beacon-api/beacon_block_proto_helpers_test.go b/validator/client/beacon-api/beacon_block_proto_helpers_test.go index a737fbc5c3..1af5b2ce02 100644 --- a/validator/client/beacon-api/beacon_block_proto_helpers_test.go +++ b/validator/client/beacon-api/beacon_block_proto_helpers_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -14,15 +14,15 @@ import ( func TestBeaconBlockProtoHelpers_ConvertProposerSlashingsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.ProposerSlashingJson + generateInput func() []*shared.ProposerSlashing expectedResult []*ethpb.ProposerSlashing expectedErrorMessage string }{ { name: "nil proposer slashing", expectedErrorMessage: "proposer slashing at index `0` is nil", - generateInput: func() []*apimiddleware.ProposerSlashingJson { - return []*apimiddleware.ProposerSlashingJson{ + generateInput: func() []*shared.ProposerSlashing { + return []*shared.ProposerSlashing{ nil, } }, @@ -30,21 +30,18 @@ func TestBeaconBlockProtoHelpers_ConvertProposerSlashingsToProto(t *testing.T) { { name: "bad header 1", expectedErrorMessage: "failed to get proposer header 1", - generateInput: func() []*apimiddleware.ProposerSlashingJson { - return []*apimiddleware.ProposerSlashingJson{ - { - Header_1: nil, - Header_2: nil, - }, - } + generateInput: func() []*shared.ProposerSlashing { + input := generateProposerSlashings() + input[0].SignedHeader1 = nil + return input }, }, { name: "bad header 2", expectedErrorMessage: "failed to get proposer header 2", - generateInput: func() []*apimiddleware.ProposerSlashingJson { + generateInput: func() []*shared.ProposerSlashing { input := generateProposerSlashings() - input[0].Header_2 = nil + input[0].SignedHeader2 = nil return input }, }, @@ -117,73 +114,73 @@ func TestBeaconBlockProtoHelpers_ConvertProposerSlashingsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertProposerSlashingSignedHeaderToProto(t *testing.T) { testCases := []struct { name string - generateInput func() *apimiddleware.SignedBeaconBlockHeaderJson + generateInput func() *shared.SignedBeaconBlockHeader expectedResult *ethpb.SignedBeaconBlockHeader expectedErrorMessage string }{ { name: "nil signed header", expectedErrorMessage: "signed header is nil", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { return nil }, + generateInput: func() *shared.SignedBeaconBlockHeader { return nil }, }, { name: "nil header", expectedErrorMessage: "header is nil", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header = nil + input.Message = nil return input }, }, { name: "bad slot", expectedErrorMessage: "failed to parse header slot `foo`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header.Slot = "foo" + input.Message.Slot = "foo" return input }, }, { name: "bad proposer index", expectedErrorMessage: "failed to parse header proposer index `bar`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header.ProposerIndex = "bar" + input.Message.ProposerIndex = "bar" return input }, }, { name: "bad parent root", expectedErrorMessage: "failed to decode header parent root `foo`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header.ParentRoot = "foo" + input.Message.ParentRoot = "foo" return input }, }, { name: "bad state root", expectedErrorMessage: "failed to decode header state root `bar`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header.StateRoot = "bar" + input.Message.StateRoot = "bar" return input }, }, { name: "bad body root", expectedErrorMessage: "failed to decode header body root `foo`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() - input.Header.BodyRoot = "foo" + input.Message.BodyRoot = "foo" return input }, }, { name: "bad parent root", expectedErrorMessage: "failed to decode signature `bar`", - generateInput: func() *apimiddleware.SignedBeaconBlockHeaderJson { + generateInput: func() *shared.SignedBeaconBlockHeader { input := generateSignedBeaconBlockHeader() input.Signature = "bar" return input @@ -222,15 +219,15 @@ func TestBeaconBlockProtoHelpers_ConvertProposerSlashingSignedHeaderToProto(t *t func TestBeaconBlockProtoHelpers_ConvertAttesterSlashingsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.AttesterSlashingJson + generateInput func() []*shared.AttesterSlashing expectedResult []*ethpb.AttesterSlashing expectedErrorMessage string }{ { name: "nil attester slashing", expectedErrorMessage: "attester slashing at index `0` is nil", - generateInput: func() []*apimiddleware.AttesterSlashingJson { - return []*apimiddleware.AttesterSlashingJson{ + generateInput: func() []*shared.AttesterSlashing { + return []*shared.AttesterSlashing{ nil, } }, @@ -238,11 +235,11 @@ func TestBeaconBlockProtoHelpers_ConvertAttesterSlashingsToProto(t *testing.T) { { name: "bad attestation 1", expectedErrorMessage: "failed to get attestation 1", - generateInput: func() []*apimiddleware.AttesterSlashingJson { - return []*apimiddleware.AttesterSlashingJson{ + generateInput: func() []*shared.AttesterSlashing { + return []*shared.AttesterSlashing{ { - Attestation_1: nil, - Attestation_2: nil, + Attestation1: nil, + Attestation2: nil, }, } }, @@ -250,9 +247,9 @@ func TestBeaconBlockProtoHelpers_ConvertAttesterSlashingsToProto(t *testing.T) { { name: "bad attestation 2", expectedErrorMessage: "failed to get attestation 2", - generateInput: func() []*apimiddleware.AttesterSlashingJson { + generateInput: func() []*shared.AttesterSlashing { input := generateAttesterSlashings() - input[0].Attestation_2 = nil + input[0].Attestation2 = nil return input }, }, @@ -353,19 +350,19 @@ func TestBeaconBlockProtoHelpers_ConvertAttesterSlashingsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertAttestationToProto(t *testing.T) { testCases := []struct { name string - generateInput func() *apimiddleware.IndexedAttestationJson + generateInput func() *shared.IndexedAttestation expectedResult *ethpb.IndexedAttestation expectedErrorMessage string }{ { name: "nil indexed attestation", expectedErrorMessage: "indexed attestation is nil", - generateInput: func() *apimiddleware.IndexedAttestationJson { return nil }, + generateInput: func() *shared.IndexedAttestation { return nil }, }, { name: "bad attesting index", expectedErrorMessage: "failed to parse attesting index `foo`", - generateInput: func() *apimiddleware.IndexedAttestationJson { + generateInput: func() *shared.IndexedAttestation { input := generateIndexedAttestation() input.AttestingIndices[0] = "foo" return input @@ -374,7 +371,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationToProto(t *testing.T) { { name: "bad signature", expectedErrorMessage: "failed to decode attestation signature `bar`", - generateInput: func() *apimiddleware.IndexedAttestationJson { + generateInput: func() *shared.IndexedAttestation { input := generateIndexedAttestation() input.Signature = "bar" return input @@ -383,7 +380,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationToProto(t *testing.T) { { name: "bad data", expectedErrorMessage: "failed to get attestation data", - generateInput: func() *apimiddleware.IndexedAttestationJson { + generateInput: func() *shared.IndexedAttestation { input := generateIndexedAttestation() input.Data = nil return input @@ -429,19 +426,19 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertCheckpointToProto(t *testing.T) { testCases := []struct { name string - generateInput func() *apimiddleware.CheckpointJson + generateInput func() *shared.Checkpoint expectedResult *ethpb.Checkpoint expectedErrorMessage string }{ { name: "nil checkpoint", expectedErrorMessage: "checkpoint is nil", - generateInput: func() *apimiddleware.CheckpointJson { return nil }, + generateInput: func() *shared.Checkpoint { return nil }, }, { name: "bad epoch", expectedErrorMessage: "failed to parse checkpoint epoch `foo`", - generateInput: func() *apimiddleware.CheckpointJson { + generateInput: func() *shared.Checkpoint { input := generateCheckpoint() input.Epoch = "foo" return input @@ -450,7 +447,7 @@ func TestBeaconBlockProtoHelpers_ConvertCheckpointToProto(t *testing.T) { { name: "bad root", expectedErrorMessage: "failed to decode checkpoint root `bar`", - generateInput: func() *apimiddleware.CheckpointJson { + generateInput: func() *shared.Checkpoint { input := generateCheckpoint() input.Root = "bar" return input @@ -483,15 +480,15 @@ func TestBeaconBlockProtoHelpers_ConvertCheckpointToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertAttestationsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.AttestationJson + generateInput func() []*shared.Attestation expectedResult []*ethpb.Attestation expectedErrorMessage string }{ { name: "nil attestation", expectedErrorMessage: "attestation at index `0` is nil", - generateInput: func() []*apimiddleware.AttestationJson { - return []*apimiddleware.AttestationJson{ + generateInput: func() []*shared.Attestation { + return []*shared.Attestation{ nil, } }, @@ -499,7 +496,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationsToProto(t *testing.T) { { name: "bad aggregation bits", expectedErrorMessage: "failed to decode aggregation bits `foo`", - generateInput: func() []*apimiddleware.AttestationJson { + generateInput: func() []*shared.Attestation { input := generateAttestations() input[0].AggregationBits = "foo" return input @@ -508,7 +505,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationsToProto(t *testing.T) { { name: "bad data", expectedErrorMessage: "failed to get attestation data", - generateInput: func() []*apimiddleware.AttestationJson { + generateInput: func() []*shared.Attestation { input := generateAttestations() input[0].Data = nil return input @@ -517,7 +514,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationsToProto(t *testing.T) { { name: "bad signature", expectedErrorMessage: "failed to decode attestation signature `bar`", - generateInput: func() []*apimiddleware.AttestationJson { + generateInput: func() []*shared.Attestation { input := generateAttestations() input[0].Signature = "bar" return input @@ -582,19 +579,19 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { testCases := []struct { name string - generateInput func() *apimiddleware.AttestationDataJson + generateInput func() *shared.AttestationData expectedResult *ethpb.AttestationData expectedErrorMessage string }{ { name: "nil attestation data", expectedErrorMessage: "attestation data is nil", - generateInput: func() *apimiddleware.AttestationDataJson { return nil }, + generateInput: func() *shared.AttestationData { return nil }, }, { name: "bad slot", expectedErrorMessage: "failed to parse attestation slot `foo`", - generateInput: func() *apimiddleware.AttestationDataJson { + generateInput: func() *shared.AttestationData { input := generateAttestationData() input.Slot = "foo" return input @@ -603,7 +600,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { { name: "bad committee index", expectedErrorMessage: "failed to parse attestation committee index `bar`", - generateInput: func() *apimiddleware.AttestationDataJson { + generateInput: func() *shared.AttestationData { input := generateAttestationData() input.CommitteeIndex = "bar" return input @@ -612,7 +609,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { { name: "bad beacon block root", expectedErrorMessage: "failed to decode attestation beacon block root `foo`", - generateInput: func() *apimiddleware.AttestationDataJson { + generateInput: func() *shared.AttestationData { input := generateAttestationData() input.BeaconBlockRoot = "foo" return input @@ -621,7 +618,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { { name: "bad source checkpoint", expectedErrorMessage: "failed to get attestation source checkpoint", - generateInput: func() *apimiddleware.AttestationDataJson { + generateInput: func() *shared.AttestationData { input := generateAttestationData() input.Source = nil return input @@ -630,7 +627,7 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { { name: "bad target checkpoint", expectedErrorMessage: "failed to get attestation target checkpoint", - generateInput: func() *apimiddleware.AttestationDataJson { + generateInput: func() *shared.AttestationData { input := generateAttestationData() input.Target = nil return input @@ -672,15 +669,15 @@ func TestBeaconBlockProtoHelpers_ConvertAttestationDataToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.DepositJson + generateInput func() []*shared.Deposit expectedResult []*ethpb.Deposit expectedErrorMessage string }{ { name: "nil deposit", expectedErrorMessage: "deposit at index `0` is nil", - generateInput: func() []*apimiddleware.DepositJson { - return []*apimiddleware.DepositJson{ + generateInput: func() []*shared.Deposit { + return []*shared.Deposit{ nil, } }, @@ -688,7 +685,7 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { { name: "bad proof", expectedErrorMessage: "failed to decode deposit proof `foo`", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() input[0].Proof[0] = "foo" return input @@ -697,7 +694,7 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { { name: "nil data", expectedErrorMessage: "deposit data at index `0` is nil", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() input[0].Data = nil return input @@ -706,16 +703,16 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { { name: "bad public key", expectedErrorMessage: "failed to decode deposit public key `bar`", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() - input[0].Data.PublicKey = "bar" + input[0].Data.Pubkey = "bar" return input }, }, { name: "bad withdrawal credentials", expectedErrorMessage: "failed to decode deposit withdrawal credentials `foo`", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() input[0].Data.WithdrawalCredentials = "foo" return input @@ -724,7 +721,7 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { { name: "bad amount", expectedErrorMessage: "failed to parse deposit amount `bar`", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() input[0].Data.Amount = "bar" return input @@ -733,7 +730,7 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { { name: "bad signature", expectedErrorMessage: "failed to decode signature `foo`", - generateInput: func() []*apimiddleware.DepositJson { + generateInput: func() []*shared.Deposit { input := generateDeposits() input[0].Data.Signature = "foo" return input @@ -788,15 +785,15 @@ func TestBeaconBlockProtoHelpers_ConvertDepositsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertVoluntaryExitsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.SignedVoluntaryExitJson + generateInput func() []*shared.SignedVoluntaryExit expectedResult []*ethpb.SignedVoluntaryExit expectedErrorMessage string }{ { name: "nil voluntary exit", expectedErrorMessage: "signed voluntary exit at index `0` is nil", - generateInput: func() []*apimiddleware.SignedVoluntaryExitJson { - return []*apimiddleware.SignedVoluntaryExitJson{ + generateInput: func() []*shared.SignedVoluntaryExit { + return []*shared.SignedVoluntaryExit{ nil, } }, @@ -804,34 +801,34 @@ func TestBeaconBlockProtoHelpers_ConvertVoluntaryExitsToProto(t *testing.T) { { name: "nil data", expectedErrorMessage: "voluntary exit at index `0` is nil", - generateInput: func() []*apimiddleware.SignedVoluntaryExitJson { + generateInput: func() []*shared.SignedVoluntaryExit { input := generateSignedVoluntaryExits() - input[0].Exit = nil + input[0].Message = nil return input }, }, { name: "bad epoch", expectedErrorMessage: "failed to parse voluntary exit epoch `foo`", - generateInput: func() []*apimiddleware.SignedVoluntaryExitJson { + generateInput: func() []*shared.SignedVoluntaryExit { input := generateSignedVoluntaryExits() - input[0].Exit.Epoch = "foo" + input[0].Message.Epoch = "foo" return input }, }, { name: "bad validator index", expectedErrorMessage: "failed to parse voluntary exit validator index `bar`", - generateInput: func() []*apimiddleware.SignedVoluntaryExitJson { + generateInput: func() []*shared.SignedVoluntaryExit { input := generateSignedVoluntaryExits() - input[0].Exit.ValidatorIndex = "bar" + input[0].Message.ValidatorIndex = "bar" return input }, }, { name: "bad signature", expectedErrorMessage: "failed to decode signature `foo`", - generateInput: func() []*apimiddleware.SignedVoluntaryExitJson { + generateInput: func() []*shared.SignedVoluntaryExit { input := generateSignedVoluntaryExits() input[0].Signature = "foo" return input @@ -921,14 +918,14 @@ func TestBeaconBlockProtoHelpers_ConvertTransactionsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.WithdrawalJson + generateInput func() []*shared.Withdrawal expectedResult []*enginev1.Withdrawal expectedErrorMessage string }{ { name: "nil withdrawal", expectedErrorMessage: "withdrawal at index `0` is nil", - generateInput: func() []*apimiddleware.WithdrawalJson { + generateInput: func() []*shared.Withdrawal { input := generateWithdrawals() input[0] = nil return input @@ -937,7 +934,7 @@ func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { { name: "bad withdrawal index", expectedErrorMessage: "failed to parse withdrawal index `foo`", - generateInput: func() []*apimiddleware.WithdrawalJson { + generateInput: func() []*shared.Withdrawal { input := generateWithdrawals() input[0].WithdrawalIndex = "foo" return input @@ -946,7 +943,7 @@ func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { { name: "bad validator index", expectedErrorMessage: "failed to parse validator index `bar`", - generateInput: func() []*apimiddleware.WithdrawalJson { + generateInput: func() []*shared.Withdrawal { input := generateWithdrawals() input[0].ValidatorIndex = "bar" return input @@ -955,7 +952,7 @@ func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { { name: "bad execution address", expectedErrorMessage: "failed to decode execution address `foo`", - generateInput: func() []*apimiddleware.WithdrawalJson { + generateInput: func() []*shared.Withdrawal { input := generateWithdrawals() input[0].ExecutionAddress = "foo" return input @@ -964,7 +961,7 @@ func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { { name: "bad amount", expectedErrorMessage: "failed to parse withdrawal amount `bar`", - generateInput: func() []*apimiddleware.WithdrawalJson { + generateInput: func() []*shared.Withdrawal { input := generateWithdrawals() input[0].Amount = "bar" return input @@ -1007,14 +1004,14 @@ func TestBeaconBlockProtoHelpers_ConvertWithdrawalsToProto(t *testing.T) { func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing.T) { testCases := []struct { name string - generateInput func() []*apimiddleware.SignedBLSToExecutionChangeJson + generateInput func() []*shared.SignedBLSToExecutionChange expectedResult []*ethpb.SignedBLSToExecutionChange expectedErrorMessage string }{ { name: "nil bls to execution change", expectedErrorMessage: "bls to execution change at index `0` is nil", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0] = nil return input @@ -1023,7 +1020,7 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. { name: "nil bls to execution change message", expectedErrorMessage: "bls to execution change message at index `0` is nil", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0].Message = nil return input @@ -1032,7 +1029,7 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. { name: "bad validator index", expectedErrorMessage: "failed to decode validator index `foo`", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0].Message.ValidatorIndex = "foo" return input @@ -1041,7 +1038,7 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. { name: "bad from bls pubkey", expectedErrorMessage: "failed to decode bls pubkey `bar`", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0].Message.FromBLSPubkey = "bar" return input @@ -1050,7 +1047,7 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. { name: "bad to execution address", expectedErrorMessage: "failed to decode execution address `foo`", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0].Message.ToExecutionAddress = "foo" return input @@ -1059,7 +1056,7 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. { name: "bad signature", expectedErrorMessage: "failed to decode signature `bar`", - generateInput: func() []*apimiddleware.SignedBLSToExecutionChangeJson { + generateInput: func() []*shared.SignedBLSToExecutionChange { input := generateBlsToExecutionChanges() input[0].Signature = "bar" return input @@ -1081,11 +1078,11 @@ func TestBeaconBlockProtoHelpers_ConvertBlsToExecutionChangesToProto(t *testing. } } -func generateProposerSlashings() []*apimiddleware.ProposerSlashingJson { - return []*apimiddleware.ProposerSlashingJson{ +func generateProposerSlashings() []*shared.ProposerSlashing { + return []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "1", ProposerIndex: "2", ParentRoot: hexutil.Encode([]byte{3}), @@ -1094,8 +1091,8 @@ func generateProposerSlashings() []*apimiddleware.ProposerSlashingJson { }, Signature: hexutil.Encode([]byte{6}), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "7", ProposerIndex: "8", ParentRoot: hexutil.Encode([]byte{9}), @@ -1106,8 +1103,8 @@ func generateProposerSlashings() []*apimiddleware.ProposerSlashingJson { }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "13", ProposerIndex: "14", ParentRoot: hexutil.Encode([]byte{15}), @@ -1116,8 +1113,8 @@ func generateProposerSlashings() []*apimiddleware.ProposerSlashingJson { }, Signature: hexutil.Encode([]byte{18}), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "19", ProposerIndex: "20", ParentRoot: hexutil.Encode([]byte{21}), @@ -1130,9 +1127,9 @@ func generateProposerSlashings() []*apimiddleware.ProposerSlashingJson { } } -func generateSignedBeaconBlockHeader() *apimiddleware.SignedBeaconBlockHeaderJson { - return &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ +func generateSignedBeaconBlockHeader() *shared.SignedBeaconBlockHeader { + return &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "1", ProposerIndex: "2", ParentRoot: hexutil.Encode([]byte{3}), @@ -1143,37 +1140,37 @@ func generateSignedBeaconBlockHeader() *apimiddleware.SignedBeaconBlockHeaderJso } } -func generateAttesterSlashings() []*apimiddleware.AttesterSlashingJson { - return []*apimiddleware.AttesterSlashingJson{ +func generateAttesterSlashings() []*shared.AttesterSlashing { + return []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"1", "2"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "3", CommitteeIndex: "4", BeaconBlockRoot: hexutil.Encode([]byte{5}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "8", Root: hexutil.Encode([]byte{9}), }, }, Signature: hexutil.Encode([]byte{10}), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"11", "12"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "13", CommitteeIndex: "14", BeaconBlockRoot: hexutil.Encode([]byte{15}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "16", Root: hexutil.Encode([]byte{17}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "18", Root: hexutil.Encode([]byte{19}), }, @@ -1182,34 +1179,34 @@ func generateAttesterSlashings() []*apimiddleware.AttesterSlashingJson { }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"21", "22"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "23", CommitteeIndex: "24", BeaconBlockRoot: hexutil.Encode([]byte{25}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "26", Root: hexutil.Encode([]byte{27}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "28", Root: hexutil.Encode([]byte{29}), }, }, Signature: hexutil.Encode([]byte{30}), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"31", "32"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "33", CommitteeIndex: "34", BeaconBlockRoot: hexutil.Encode([]byte{35}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "36", Root: hexutil.Encode([]byte{37}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "38", Root: hexutil.Encode([]byte{39}), }, @@ -1220,18 +1217,18 @@ func generateAttesterSlashings() []*apimiddleware.AttesterSlashingJson { } } -func generateIndexedAttestation() *apimiddleware.IndexedAttestationJson { - return &apimiddleware.IndexedAttestationJson{ +func generateIndexedAttestation() *shared.IndexedAttestation { + return &shared.IndexedAttestation{ AttestingIndices: []string{"1", "2"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "3", CommitteeIndex: "4", BeaconBlockRoot: hexutil.Encode([]byte{5}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "8", Root: hexutil.Encode([]byte{9}), }, @@ -1240,26 +1237,26 @@ func generateIndexedAttestation() *apimiddleware.IndexedAttestationJson { } } -func generateCheckpoint() *apimiddleware.CheckpointJson { - return &apimiddleware.CheckpointJson{ +func generateCheckpoint() *shared.Checkpoint { + return &shared.Checkpoint{ Epoch: "1", Root: hexutil.Encode([]byte{2}), } } -func generateAttestations() []*apimiddleware.AttestationJson { - return []*apimiddleware.AttestationJson{ +func generateAttestations() []*shared.Attestation { + return []*shared.Attestation{ { AggregationBits: hexutil.Encode([]byte{1}), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "2", CommitteeIndex: "3", BeaconBlockRoot: hexutil.Encode([]byte{4}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "5", Root: hexutil.Encode([]byte{6}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "7", Root: hexutil.Encode([]byte{8}), }, @@ -1268,15 +1265,15 @@ func generateAttestations() []*apimiddleware.AttestationJson { }, { AggregationBits: hexutil.Encode([]byte{10}), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "11", CommitteeIndex: "12", BeaconBlockRoot: hexutil.Encode([]byte{13}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "14", Root: hexutil.Encode([]byte{15}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "16", Root: hexutil.Encode([]byte{17}), }, @@ -1286,31 +1283,31 @@ func generateAttestations() []*apimiddleware.AttestationJson { } } -func generateAttestationData() *apimiddleware.AttestationDataJson { - return &apimiddleware.AttestationDataJson{ +func generateAttestationData() *shared.AttestationData { + return &shared.AttestationData{ Slot: "1", CommitteeIndex: "2", BeaconBlockRoot: hexutil.Encode([]byte{3}), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "4", Root: hexutil.Encode([]byte{5}), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "6", Root: hexutil.Encode([]byte{7}), }, } } -func generateDeposits() []*apimiddleware.DepositJson { - return []*apimiddleware.DepositJson{ +func generateDeposits() []*shared.Deposit { + return []*shared.Deposit{ { Proof: []string{ hexutil.Encode([]byte{1}), hexutil.Encode([]byte{2}), }, - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: hexutil.Encode([]byte{3}), + Data: &shared.DepositData{ + Pubkey: hexutil.Encode([]byte{3}), WithdrawalCredentials: hexutil.Encode([]byte{4}), Amount: "5", Signature: hexutil.Encode([]byte{6}), @@ -1321,8 +1318,8 @@ func generateDeposits() []*apimiddleware.DepositJson { hexutil.Encode([]byte{7}), hexutil.Encode([]byte{8}), }, - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: hexutil.Encode([]byte{9}), + Data: &shared.DepositData{ + Pubkey: hexutil.Encode([]byte{9}), WithdrawalCredentials: hexutil.Encode([]byte{10}), Amount: "11", Signature: hexutil.Encode([]byte{12}), @@ -1331,17 +1328,17 @@ func generateDeposits() []*apimiddleware.DepositJson { } } -func generateSignedVoluntaryExits() []*apimiddleware.SignedVoluntaryExitJson { - return []*apimiddleware.SignedVoluntaryExitJson{ +func generateSignedVoluntaryExits() []*shared.SignedVoluntaryExit { + return []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "1", ValidatorIndex: "2", }, Signature: hexutil.Encode([]byte{3}), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "4", ValidatorIndex: "5", }, @@ -1350,8 +1347,8 @@ func generateSignedVoluntaryExits() []*apimiddleware.SignedVoluntaryExitJson { } } -func generateWithdrawals() []*apimiddleware.WithdrawalJson { - return []*apimiddleware.WithdrawalJson{ +func generateWithdrawals() []*shared.Withdrawal { + return []*shared.Withdrawal{ { WithdrawalIndex: "1", ValidatorIndex: "2", @@ -1367,10 +1364,10 @@ func generateWithdrawals() []*apimiddleware.WithdrawalJson { } } -func generateBlsToExecutionChanges() []*apimiddleware.SignedBLSToExecutionChangeJson { - return []*apimiddleware.SignedBLSToExecutionChangeJson{ +func generateBlsToExecutionChanges() []*shared.SignedBLSToExecutionChange { + return []*shared.SignedBLSToExecutionChange{ { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "1", FromBLSPubkey: hexutil.Encode([]byte{2}), ToExecutionAddress: hexutil.Encode([]byte{3}), @@ -1378,7 +1375,7 @@ func generateBlsToExecutionChanges() []*apimiddleware.SignedBLSToExecutionChange Signature: hexutil.Encode([]byte{4}), }, { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "5", FromBLSPubkey: hexutil.Encode([]byte{6}), ToExecutionAddress: hexutil.Encode([]byte{7}), diff --git a/validator/client/beacon-api/mock/BUILD.bazel b/validator/client/beacon-api/mock/BUILD.bazel index 46609eb19b..e1586e4cfc 100644 --- a/validator/client/beacon-api/mock/BUILD.bazel +++ b/validator/client/beacon-api/mock/BUILD.bazel @@ -12,7 +12,6 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/mock", visibility = ["//visibility:public"], deps = [ - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/beacon:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//beacon-chain/rpc/eth/validator:go_default_library", diff --git a/validator/client/beacon-api/mock/beacon_block_converter_mock.go b/validator/client/beacon-api/mock/beacon_block_converter_mock.go index 4a978038e6..926aef70de 100644 --- a/validator/client/beacon-api/mock/beacon_block_converter_mock.go +++ b/validator/client/beacon-api/mock/beacon_block_converter_mock.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: validator/client/beacon-api/beacon_block_converter.go +// Source: github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api (interfaces: BeaconBlockConverter) // Package mock is a generated GoMock package. package mock @@ -8,89 +8,89 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" - apimiddleware "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + shared "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) -// MockbeaconBlockConverter is a mock of beaconBlockConverter interface. -type MockbeaconBlockConverter struct { +// MockBeaconBlockConverter is a mock of BeaconBlockConverter interface. +type MockBeaconBlockConverter struct { ctrl *gomock.Controller - recorder *MockbeaconBlockConverterMockRecorder + recorder *MockBeaconBlockConverterMockRecorder } -// MockbeaconBlockConverterMockRecorder is the mock recorder for MockbeaconBlockConverter. -type MockbeaconBlockConverterMockRecorder struct { - mock *MockbeaconBlockConverter +// MockBeaconBlockConverterMockRecorder is the mock recorder for MockBeaconBlockConverter. +type MockBeaconBlockConverterMockRecorder struct { + mock *MockBeaconBlockConverter } -// NewMockbeaconBlockConverter creates a new mock instance. -func NewMockbeaconBlockConverter(ctrl *gomock.Controller) *MockbeaconBlockConverter { - mock := &MockbeaconBlockConverter{ctrl: ctrl} - mock.recorder = &MockbeaconBlockConverterMockRecorder{mock} +// NewMockBeaconBlockConverter creates a new mock instance. +func NewMockBeaconBlockConverter(ctrl *gomock.Controller) *MockBeaconBlockConverter { + mock := &MockBeaconBlockConverter{ctrl: ctrl} + mock.recorder = &MockBeaconBlockConverterMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockbeaconBlockConverter) EXPECT() *MockbeaconBlockConverterMockRecorder { +func (m *MockBeaconBlockConverter) EXPECT() *MockBeaconBlockConverterMockRecorder { return m.recorder } // ConvertRESTAltairBlockToProto mocks base method. -func (m *MockbeaconBlockConverter) ConvertRESTAltairBlockToProto(block *apimiddleware.BeaconBlockAltairJson) (*eth.BeaconBlockAltair, error) { +func (m *MockBeaconBlockConverter) ConvertRESTAltairBlockToProto(arg0 *shared.BeaconBlockAltair) (*eth.BeaconBlockAltair, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConvertRESTAltairBlockToProto", block) + ret := m.ctrl.Call(m, "ConvertRESTAltairBlockToProto", arg0) ret0, _ := ret[0].(*eth.BeaconBlockAltair) ret1, _ := ret[1].(error) return ret0, ret1 } // ConvertRESTAltairBlockToProto indicates an expected call of ConvertRESTAltairBlockToProto. -func (mr *MockbeaconBlockConverterMockRecorder) ConvertRESTAltairBlockToProto(block interface{}) *gomock.Call { +func (mr *MockBeaconBlockConverterMockRecorder) ConvertRESTAltairBlockToProto(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTAltairBlockToProto", reflect.TypeOf((*MockbeaconBlockConverter)(nil).ConvertRESTAltairBlockToProto), block) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTAltairBlockToProto", reflect.TypeOf((*MockBeaconBlockConverter)(nil).ConvertRESTAltairBlockToProto), arg0) } // ConvertRESTBellatrixBlockToProto mocks base method. -func (m *MockbeaconBlockConverter) ConvertRESTBellatrixBlockToProto(block *apimiddleware.BeaconBlockBellatrixJson) (*eth.BeaconBlockBellatrix, error) { +func (m *MockBeaconBlockConverter) ConvertRESTBellatrixBlockToProto(arg0 *shared.BeaconBlockBellatrix) (*eth.BeaconBlockBellatrix, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConvertRESTBellatrixBlockToProto", block) + ret := m.ctrl.Call(m, "ConvertRESTBellatrixBlockToProto", arg0) ret0, _ := ret[0].(*eth.BeaconBlockBellatrix) ret1, _ := ret[1].(error) return ret0, ret1 } // ConvertRESTBellatrixBlockToProto indicates an expected call of ConvertRESTBellatrixBlockToProto. -func (mr *MockbeaconBlockConverterMockRecorder) ConvertRESTBellatrixBlockToProto(block interface{}) *gomock.Call { +func (mr *MockBeaconBlockConverterMockRecorder) ConvertRESTBellatrixBlockToProto(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTBellatrixBlockToProto", reflect.TypeOf((*MockbeaconBlockConverter)(nil).ConvertRESTBellatrixBlockToProto), block) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTBellatrixBlockToProto", reflect.TypeOf((*MockBeaconBlockConverter)(nil).ConvertRESTBellatrixBlockToProto), arg0) } // ConvertRESTCapellaBlockToProto mocks base method. -func (m *MockbeaconBlockConverter) ConvertRESTCapellaBlockToProto(block *apimiddleware.BeaconBlockCapellaJson) (*eth.BeaconBlockCapella, error) { +func (m *MockBeaconBlockConverter) ConvertRESTCapellaBlockToProto(arg0 *shared.BeaconBlockCapella) (*eth.BeaconBlockCapella, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConvertRESTCapellaBlockToProto", block) + ret := m.ctrl.Call(m, "ConvertRESTCapellaBlockToProto", arg0) ret0, _ := ret[0].(*eth.BeaconBlockCapella) ret1, _ := ret[1].(error) return ret0, ret1 } // ConvertRESTCapellaBlockToProto indicates an expected call of ConvertRESTCapellaBlockToProto. -func (mr *MockbeaconBlockConverterMockRecorder) ConvertRESTCapellaBlockToProto(block interface{}) *gomock.Call { +func (mr *MockBeaconBlockConverterMockRecorder) ConvertRESTCapellaBlockToProto(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTCapellaBlockToProto", reflect.TypeOf((*MockbeaconBlockConverter)(nil).ConvertRESTCapellaBlockToProto), block) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTCapellaBlockToProto", reflect.TypeOf((*MockBeaconBlockConverter)(nil).ConvertRESTCapellaBlockToProto), arg0) } // ConvertRESTPhase0BlockToProto mocks base method. -func (m *MockbeaconBlockConverter) ConvertRESTPhase0BlockToProto(block *apimiddleware.BeaconBlockJson) (*eth.BeaconBlock, error) { +func (m *MockBeaconBlockConverter) ConvertRESTPhase0BlockToProto(arg0 *shared.BeaconBlock) (*eth.BeaconBlock, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConvertRESTPhase0BlockToProto", block) + ret := m.ctrl.Call(m, "ConvertRESTPhase0BlockToProto", arg0) ret0, _ := ret[0].(*eth.BeaconBlock) ret1, _ := ret[1].(error) return ret0, ret1 } // ConvertRESTPhase0BlockToProto indicates an expected call of ConvertRESTPhase0BlockToProto. -func (mr *MockbeaconBlockConverterMockRecorder) ConvertRESTPhase0BlockToProto(block interface{}) *gomock.Call { +func (mr *MockBeaconBlockConverterMockRecorder) ConvertRESTPhase0BlockToProto(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTPhase0BlockToProto", reflect.TypeOf((*MockbeaconBlockConverter)(nil).ConvertRESTPhase0BlockToProto), block) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConvertRESTPhase0BlockToProto", reflect.TypeOf((*MockBeaconBlockConverter)(nil).ConvertRESTPhase0BlockToProto), arg0) } diff --git a/validator/client/beacon-api/propose_beacon_block.go b/validator/client/beacon-api/propose_beacon_block.go index e6b3b083e2..66d6622a04 100644 --- a/validator/client/beacon-api/propose_beacon_block.go +++ b/validator/client/beacon-api/propose_beacon_block.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -150,10 +149,10 @@ func (c beaconApiValidatorClient) proposeBeaconBlock(ctx context.Context, in *et } func marshallBeaconBlockPhase0(block *ethpb.SignedBeaconBlock) ([]byte, error) { - signedBeaconBlockJson := &apimiddleware.SignedBeaconBlockJson{ + signedBeaconBlockJson := &shared.SignedBeaconBlock{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BeaconBlockJson{ - Body: &apimiddleware.BeaconBlockBodyJson{ + Message: &shared.BeaconBlock{ + Body: &shared.BeaconBlockBody{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -174,14 +173,14 @@ func marshallBeaconBlockPhase0(block *ethpb.SignedBeaconBlock) ([]byte, error) { } func marshallBeaconBlockAltair(block *ethpb.SignedBeaconBlockAltair) ([]byte, error) { - signedBeaconBlockAltairJson := &apimiddleware.SignedBeaconBlockAltairJson{ + signedBeaconBlockAltairJson := &shared.SignedBeaconBlockAltair{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BeaconBlockAltairJson{ + Message: &shared.BeaconBlockAltair{ ParentRoot: hexutil.Encode(block.Block.ParentRoot), ProposerIndex: uint64ToString(block.Block.ProposerIndex), Slot: uint64ToString(block.Block.Slot), StateRoot: hexutil.Encode(block.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyAltairJson{ + Body: &shared.BeaconBlockBodyAltair{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -190,7 +189,7 @@ func marshallBeaconBlockAltair(block *ethpb.SignedBeaconBlockAltair) ([]byte, er ProposerSlashings: jsonifyProposerSlashings(block.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(block.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(block.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeSignature), }, @@ -202,14 +201,14 @@ func marshallBeaconBlockAltair(block *ethpb.SignedBeaconBlockAltair) ([]byte, er } func marshallBeaconBlockBellatrix(block *ethpb.SignedBeaconBlockBellatrix) ([]byte, error) { - signedBeaconBlockBellatrixJson := &apimiddleware.SignedBeaconBlockBellatrixJson{ + signedBeaconBlockBellatrixJson := &shared.SignedBeaconBlockBellatrix{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BeaconBlockBellatrixJson{ + Message: &shared.BeaconBlockBellatrix{ ParentRoot: hexutil.Encode(block.Block.ParentRoot), ProposerIndex: uint64ToString(block.Block.ProposerIndex), Slot: uint64ToString(block.Block.Slot), StateRoot: hexutil.Encode(block.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyBellatrixJson{ + Body: &shared.BeaconBlockBodyBellatrix{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -218,11 +217,11 @@ func marshallBeaconBlockBellatrix(block *ethpb.SignedBeaconBlockBellatrix) ([]by ProposerSlashings: jsonifyProposerSlashings(block.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(block.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(block.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadJson{ + ExecutionPayload: &shared.ExecutionPayload{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(block.Block.Body.ExecutionPayload.BaseFeePerGas).String(), BlockHash: hexutil.Encode(block.Block.Body.ExecutionPayload.BlockHash), BlockNumber: uint64ToString(block.Block.Body.ExecutionPayload.BlockNumber), @@ -235,7 +234,7 @@ func marshallBeaconBlockBellatrix(block *ethpb.SignedBeaconBlockBellatrix) ([]by PrevRandao: hexutil.Encode(block.Block.Body.ExecutionPayload.PrevRandao), ReceiptsRoot: hexutil.Encode(block.Block.Body.ExecutionPayload.ReceiptsRoot), StateRoot: hexutil.Encode(block.Block.Body.ExecutionPayload.StateRoot), - TimeStamp: uint64ToString(block.Block.Body.ExecutionPayload.Timestamp), + Timestamp: uint64ToString(block.Block.Body.ExecutionPayload.Timestamp), Transactions: jsonifyTransactions(block.Block.Body.ExecutionPayload.Transactions), }, }, @@ -246,14 +245,14 @@ func marshallBeaconBlockBellatrix(block *ethpb.SignedBeaconBlockBellatrix) ([]by } func marshallBeaconBlockBlindedBellatrix(block *ethpb.SignedBlindedBeaconBlockBellatrix) ([]byte, error) { - signedBeaconBlockBellatrixJson := &apimiddleware.SignedBlindedBeaconBlockBellatrixJson{ + signedBeaconBlockBellatrixJson := &shared.SignedBlindedBeaconBlockBellatrix{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BlindedBeaconBlockBellatrixJson{ + Message: &shared.BlindedBeaconBlockBellatrix{ ParentRoot: hexutil.Encode(block.Block.ParentRoot), ProposerIndex: uint64ToString(block.Block.ProposerIndex), Slot: uint64ToString(block.Block.Slot), StateRoot: hexutil.Encode(block.Block.StateRoot), - Body: &apimiddleware.BlindedBeaconBlockBodyBellatrixJson{ + Body: &shared.BlindedBeaconBlockBodyBellatrix{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -262,11 +261,11 @@ func marshallBeaconBlockBlindedBellatrix(block *ethpb.SignedBlindedBeaconBlockBe ProposerSlashings: jsonifyProposerSlashings(block.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(block.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(block.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayloadHeader: &apimiddleware.ExecutionPayloadHeaderJson{ + ExecutionPayloadHeader: &shared.ExecutionPayloadHeader{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(block.Block.Body.ExecutionPayloadHeader.BaseFeePerGas).String(), BlockHash: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.BlockHash), BlockNumber: uint64ToString(block.Block.Body.ExecutionPayloadHeader.BlockNumber), @@ -279,7 +278,7 @@ func marshallBeaconBlockBlindedBellatrix(block *ethpb.SignedBlindedBeaconBlockBe PrevRandao: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.PrevRandao), ReceiptsRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.ReceiptsRoot), StateRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.StateRoot), - TimeStamp: uint64ToString(block.Block.Body.ExecutionPayloadHeader.Timestamp), + Timestamp: uint64ToString(block.Block.Body.ExecutionPayloadHeader.Timestamp), TransactionsRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.TransactionsRoot), }, }, @@ -290,14 +289,14 @@ func marshallBeaconBlockBlindedBellatrix(block *ethpb.SignedBlindedBeaconBlockBe } func marshallBeaconBlockCapella(block *ethpb.SignedBeaconBlockCapella) ([]byte, error) { - signedBeaconBlockCapellaJson := &apimiddleware.SignedBeaconBlockCapellaJson{ + signedBeaconBlockCapellaJson := &shared.SignedBeaconBlockCapella{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BeaconBlockCapellaJson{ + Message: &shared.BeaconBlockCapella{ ParentRoot: hexutil.Encode(block.Block.ParentRoot), ProposerIndex: uint64ToString(block.Block.ProposerIndex), Slot: uint64ToString(block.Block.Slot), StateRoot: hexutil.Encode(block.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyCapellaJson{ + Body: &shared.BeaconBlockBodyCapella{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -306,11 +305,11 @@ func marshallBeaconBlockCapella(block *ethpb.SignedBeaconBlockCapella) ([]byte, ProposerSlashings: jsonifyProposerSlashings(block.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(block.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(block.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadCapellaJson{ + ExecutionPayload: &shared.ExecutionPayloadCapella{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(block.Block.Body.ExecutionPayload.BaseFeePerGas).String(), BlockHash: hexutil.Encode(block.Block.Body.ExecutionPayload.BlockHash), BlockNumber: uint64ToString(block.Block.Body.ExecutionPayload.BlockNumber), @@ -323,11 +322,11 @@ func marshallBeaconBlockCapella(block *ethpb.SignedBeaconBlockCapella) ([]byte, PrevRandao: hexutil.Encode(block.Block.Body.ExecutionPayload.PrevRandao), ReceiptsRoot: hexutil.Encode(block.Block.Body.ExecutionPayload.ReceiptsRoot), StateRoot: hexutil.Encode(block.Block.Body.ExecutionPayload.StateRoot), - TimeStamp: uint64ToString(block.Block.Body.ExecutionPayload.Timestamp), + Timestamp: uint64ToString(block.Block.Body.ExecutionPayload.Timestamp), Transactions: jsonifyTransactions(block.Block.Body.ExecutionPayload.Transactions), Withdrawals: jsonifyWithdrawals(block.Block.Body.ExecutionPayload.Withdrawals), }, - BLSToExecutionChanges: jsonifyBlsToExecutionChanges(block.Block.Body.BlsToExecutionChanges), + BlsToExecutionChanges: jsonifyBlsToExecutionChanges(block.Block.Body.BlsToExecutionChanges), }, }, } @@ -336,14 +335,14 @@ func marshallBeaconBlockCapella(block *ethpb.SignedBeaconBlockCapella) ([]byte, } func marshallBeaconBlockBlindedCapella(block *ethpb.SignedBlindedBeaconBlockCapella) ([]byte, error) { - signedBeaconBlockCapellaJson := &apimiddleware.SignedBlindedBeaconBlockCapellaJson{ + signedBeaconBlockCapellaJson := &shared.SignedBlindedBeaconBlockCapella{ Signature: hexutil.Encode(block.Signature), - Message: &apimiddleware.BlindedBeaconBlockCapellaJson{ + Message: &shared.BlindedBeaconBlockCapella{ ParentRoot: hexutil.Encode(block.Block.ParentRoot), ProposerIndex: uint64ToString(block.Block.ProposerIndex), Slot: uint64ToString(block.Block.Slot), StateRoot: hexutil.Encode(block.Block.StateRoot), - Body: &apimiddleware.BlindedBeaconBlockBodyCapellaJson{ + Body: &shared.BlindedBeaconBlockBodyCapella{ Attestations: jsonifyAttestations(block.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(block.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(block.Block.Body.Deposits), @@ -352,11 +351,11 @@ func marshallBeaconBlockBlindedCapella(block *ethpb.SignedBlindedBeaconBlockCape ProposerSlashings: jsonifyProposerSlashings(block.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(block.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(block.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(block.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayloadHeader: &apimiddleware.ExecutionPayloadHeaderCapellaJson{ + ExecutionPayloadHeader: &shared.ExecutionPayloadHeaderCapella{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(block.Block.Body.ExecutionPayloadHeader.BaseFeePerGas).String(), BlockHash: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.BlockHash), BlockNumber: uint64ToString(block.Block.Body.ExecutionPayloadHeader.BlockNumber), @@ -369,11 +368,11 @@ func marshallBeaconBlockBlindedCapella(block *ethpb.SignedBlindedBeaconBlockCape PrevRandao: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.PrevRandao), ReceiptsRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.ReceiptsRoot), StateRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.StateRoot), - TimeStamp: uint64ToString(block.Block.Body.ExecutionPayloadHeader.Timestamp), + Timestamp: uint64ToString(block.Block.Body.ExecutionPayloadHeader.Timestamp), TransactionsRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.TransactionsRoot), WithdrawalsRoot: hexutil.Encode(block.Block.Body.ExecutionPayloadHeader.WithdrawalsRoot), }, - BLSToExecutionChanges: jsonifyBlsToExecutionChanges(block.Block.Body.BlsToExecutionChanges), + BlsToExecutionChanges: jsonifyBlsToExecutionChanges(block.Block.Body.BlsToExecutionChanges), }, }, } diff --git a/validator/client/beacon-api/propose_beacon_block_altair_test.go b/validator/client/beacon-api/propose_beacon_block_altair_test.go index 6cab55dfc1..a939da7178 100644 --- a/validator/client/beacon-api/propose_beacon_block_altair_test.go +++ b/validator/client/beacon-api/propose_beacon_block_altair_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -26,14 +26,14 @@ func TestProposeBeaconBlock_Altair(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = altairBlock - jsonAltairBlock := &apimiddleware.SignedBeaconBlockAltairJson{ + jsonAltairBlock := &shared.SignedBeaconBlockAltair{ Signature: hexutil.Encode(altairBlock.Altair.Signature), - Message: &apimiddleware.BeaconBlockAltairJson{ + Message: &shared.BeaconBlockAltair{ ParentRoot: hexutil.Encode(altairBlock.Altair.Block.ParentRoot), ProposerIndex: uint64ToString(altairBlock.Altair.Block.ProposerIndex), Slot: uint64ToString(altairBlock.Altair.Block.Slot), StateRoot: hexutil.Encode(altairBlock.Altair.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyAltairJson{ + Body: &shared.BeaconBlockBodyAltair{ Attestations: jsonifyAttestations(altairBlock.Altair.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(altairBlock.Altair.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(altairBlock.Altair.Block.Body.Deposits), @@ -42,7 +42,7 @@ func TestProposeBeaconBlock_Altair(t *testing.T) { ProposerSlashings: jsonifyProposerSlashings(altairBlock.Altair.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(altairBlock.Altair.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(altairBlock.Altair.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(altairBlock.Altair.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(altairBlock.Altair.Block.Body.SyncAggregate.SyncCommitteeSignature), }, diff --git a/validator/client/beacon-api/propose_beacon_block_bellatrix_test.go b/validator/client/beacon-api/propose_beacon_block_bellatrix_test.go index c112b00c6f..8163d22c7d 100644 --- a/validator/client/beacon-api/propose_beacon_block_bellatrix_test.go +++ b/validator/client/beacon-api/propose_beacon_block_bellatrix_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -27,14 +27,14 @@ func TestProposeBeaconBlock_Bellatrix(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = bellatrixBlock - jsonBellatrixBlock := &apimiddleware.SignedBeaconBlockBellatrixJson{ + jsonBellatrixBlock := &shared.SignedBeaconBlockBellatrix{ Signature: hexutil.Encode(bellatrixBlock.Bellatrix.Signature), - Message: &apimiddleware.BeaconBlockBellatrixJson{ + Message: &shared.BeaconBlockBellatrix{ ParentRoot: hexutil.Encode(bellatrixBlock.Bellatrix.Block.ParentRoot), ProposerIndex: uint64ToString(bellatrixBlock.Bellatrix.Block.ProposerIndex), Slot: uint64ToString(bellatrixBlock.Bellatrix.Block.Slot), StateRoot: hexutil.Encode(bellatrixBlock.Bellatrix.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyBellatrixJson{ + Body: &shared.BeaconBlockBodyBellatrix{ Attestations: jsonifyAttestations(bellatrixBlock.Bellatrix.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(bellatrixBlock.Bellatrix.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(bellatrixBlock.Bellatrix.Block.Body.Deposits), @@ -43,11 +43,11 @@ func TestProposeBeaconBlock_Bellatrix(t *testing.T) { ProposerSlashings: jsonifyProposerSlashings(bellatrixBlock.Bellatrix.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(bellatrixBlock.Bellatrix.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadJson{ + ExecutionPayload: &shared.ExecutionPayload{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.BaseFeePerGas).String(), BlockHash: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.BlockHash), BlockNumber: uint64ToString(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.BlockNumber), @@ -60,7 +60,7 @@ func TestProposeBeaconBlock_Bellatrix(t *testing.T) { PrevRandao: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.PrevRandao), ReceiptsRoot: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.ReceiptsRoot), StateRoot: hexutil.Encode(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.StateRoot), - TimeStamp: uint64ToString(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.Timestamp), + Timestamp: uint64ToString(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.Timestamp), Transactions: jsonifyTransactions(bellatrixBlock.Bellatrix.Block.Body.ExecutionPayload.Transactions), }, }, diff --git a/validator/client/beacon-api/propose_beacon_block_blinded_bellatrix_test.go b/validator/client/beacon-api/propose_beacon_block_blinded_bellatrix_test.go index 69186a6190..1c0b9d4a44 100644 --- a/validator/client/beacon-api/propose_beacon_block_blinded_bellatrix_test.go +++ b/validator/client/beacon-api/propose_beacon_block_blinded_bellatrix_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -28,14 +28,14 @@ func TestProposeBeaconBlock_BlindedBellatrix(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = blindedBellatrixBlock - jsonBlindedBellatrixBlock := &apimiddleware.SignedBlindedBeaconBlockBellatrixJson{ + jsonBlindedBellatrixBlock := &shared.SignedBlindedBeaconBlockBellatrix{ Signature: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Signature), - Message: &apimiddleware.BlindedBeaconBlockBellatrixJson{ + Message: &shared.BlindedBeaconBlockBellatrix{ ParentRoot: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.ParentRoot), ProposerIndex: uint64ToString(blindedBellatrixBlock.BlindedBellatrix.Block.ProposerIndex), Slot: uint64ToString(blindedBellatrixBlock.BlindedBellatrix.Block.Slot), StateRoot: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.StateRoot), - Body: &apimiddleware.BlindedBeaconBlockBodyBellatrixJson{ + Body: &shared.BlindedBeaconBlockBodyBellatrix{ Attestations: jsonifyAttestations(blindedBellatrixBlock.BlindedBellatrix.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(blindedBellatrixBlock.BlindedBellatrix.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(blindedBellatrixBlock.BlindedBellatrix.Block.Body.Deposits), @@ -44,11 +44,11 @@ func TestProposeBeaconBlock_BlindedBellatrix(t *testing.T) { ProposerSlashings: jsonifyProposerSlashings(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(blindedBellatrixBlock.BlindedBellatrix.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayloadHeader: &apimiddleware.ExecutionPayloadHeaderJson{ + ExecutionPayloadHeader: &shared.ExecutionPayloadHeader{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.BaseFeePerGas).String(), BlockHash: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.BlockHash), BlockNumber: uint64ToString(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.BlockNumber), @@ -61,7 +61,7 @@ func TestProposeBeaconBlock_BlindedBellatrix(t *testing.T) { PrevRandao: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.PrevRandao), ReceiptsRoot: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.ReceiptsRoot), StateRoot: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.StateRoot), - TimeStamp: uint64ToString(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.Timestamp), + Timestamp: uint64ToString(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.Timestamp), TransactionsRoot: hexutil.Encode(blindedBellatrixBlock.BlindedBellatrix.Block.Body.ExecutionPayloadHeader.TransactionsRoot), }, }, diff --git a/validator/client/beacon-api/propose_beacon_block_blinded_capella_test.go b/validator/client/beacon-api/propose_beacon_block_blinded_capella_test.go index c51a832b8b..0c65cd0471 100644 --- a/validator/client/beacon-api/propose_beacon_block_blinded_capella_test.go +++ b/validator/client/beacon-api/propose_beacon_block_blinded_capella_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -28,14 +28,14 @@ func TestProposeBeaconBlock_BlindedCapella(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = blindedCapellaBlock - jsonBlindedCapellaBlock := &apimiddleware.SignedBlindedBeaconBlockCapellaJson{ + jsonBlindedCapellaBlock := &shared.SignedBlindedBeaconBlockCapella{ Signature: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Signature), - Message: &apimiddleware.BlindedBeaconBlockCapellaJson{ + Message: &shared.BlindedBeaconBlockCapella{ ParentRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.ParentRoot), ProposerIndex: uint64ToString(blindedCapellaBlock.BlindedCapella.Block.ProposerIndex), Slot: uint64ToString(blindedCapellaBlock.BlindedCapella.Block.Slot), StateRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.StateRoot), - Body: &apimiddleware.BlindedBeaconBlockBodyCapellaJson{ + Body: &shared.BlindedBeaconBlockBodyCapella{ Attestations: jsonifyAttestations(blindedCapellaBlock.BlindedCapella.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(blindedCapellaBlock.BlindedCapella.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(blindedCapellaBlock.BlindedCapella.Block.Body.Deposits), @@ -44,11 +44,11 @@ func TestProposeBeaconBlock_BlindedCapella(t *testing.T) { ProposerSlashings: jsonifyProposerSlashings(blindedCapellaBlock.BlindedCapella.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(blindedCapellaBlock.BlindedCapella.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayloadHeader: &apimiddleware.ExecutionPayloadHeaderCapellaJson{ + ExecutionPayloadHeader: &shared.ExecutionPayloadHeaderCapella{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.BaseFeePerGas).String(), BlockHash: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.BlockHash), BlockNumber: uint64ToString(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.BlockNumber), @@ -61,11 +61,11 @@ func TestProposeBeaconBlock_BlindedCapella(t *testing.T) { PrevRandao: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.PrevRandao), ReceiptsRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.ReceiptsRoot), StateRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.StateRoot), - TimeStamp: uint64ToString(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.Timestamp), + Timestamp: uint64ToString(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.Timestamp), TransactionsRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.TransactionsRoot), WithdrawalsRoot: hexutil.Encode(blindedCapellaBlock.BlindedCapella.Block.Body.ExecutionPayloadHeader.WithdrawalsRoot), }, - BLSToExecutionChanges: jsonifyBlsToExecutionChanges(blindedCapellaBlock.BlindedCapella.Block.Body.BlsToExecutionChanges), + BlsToExecutionChanges: jsonifyBlsToExecutionChanges(blindedCapellaBlock.BlindedCapella.Block.Body.BlsToExecutionChanges), }, }, } diff --git a/validator/client/beacon-api/propose_beacon_block_capella_test.go b/validator/client/beacon-api/propose_beacon_block_capella_test.go index 59b0e17a18..7e9ce52ee0 100644 --- a/validator/client/beacon-api/propose_beacon_block_capella_test.go +++ b/validator/client/beacon-api/propose_beacon_block_capella_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" @@ -27,14 +27,14 @@ func TestProposeBeaconBlock_Capella(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = capellaBlock - jsonCapellaBlock := &apimiddleware.SignedBeaconBlockCapellaJson{ + jsonCapellaBlock := &shared.SignedBeaconBlockCapella{ Signature: hexutil.Encode(capellaBlock.Capella.Signature), - Message: &apimiddleware.BeaconBlockCapellaJson{ + Message: &shared.BeaconBlockCapella{ ParentRoot: hexutil.Encode(capellaBlock.Capella.Block.ParentRoot), ProposerIndex: uint64ToString(capellaBlock.Capella.Block.ProposerIndex), Slot: uint64ToString(capellaBlock.Capella.Block.Slot), StateRoot: hexutil.Encode(capellaBlock.Capella.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyCapellaJson{ + Body: &shared.BeaconBlockBodyCapella{ Attestations: jsonifyAttestations(capellaBlock.Capella.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(capellaBlock.Capella.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(capellaBlock.Capella.Block.Body.Deposits), @@ -43,11 +43,11 @@ func TestProposeBeaconBlock_Capella(t *testing.T) { ProposerSlashings: jsonifyProposerSlashings(capellaBlock.Capella.Block.Body.ProposerSlashings), RandaoReveal: hexutil.Encode(capellaBlock.Capella.Block.Body.RandaoReveal), VoluntaryExits: JsonifySignedVoluntaryExits(capellaBlock.Capella.Block.Body.VoluntaryExits), - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: hexutil.Encode(capellaBlock.Capella.Block.Body.SyncAggregate.SyncCommitteeBits), SyncCommitteeSignature: hexutil.Encode(capellaBlock.Capella.Block.Body.SyncAggregate.SyncCommitteeSignature), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadCapellaJson{ + ExecutionPayload: &shared.ExecutionPayloadCapella{ BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(capellaBlock.Capella.Block.Body.ExecutionPayload.BaseFeePerGas).String(), BlockHash: hexutil.Encode(capellaBlock.Capella.Block.Body.ExecutionPayload.BlockHash), BlockNumber: uint64ToString(capellaBlock.Capella.Block.Body.ExecutionPayload.BlockNumber), @@ -60,11 +60,11 @@ func TestProposeBeaconBlock_Capella(t *testing.T) { PrevRandao: hexutil.Encode(capellaBlock.Capella.Block.Body.ExecutionPayload.PrevRandao), ReceiptsRoot: hexutil.Encode(capellaBlock.Capella.Block.Body.ExecutionPayload.ReceiptsRoot), StateRoot: hexutil.Encode(capellaBlock.Capella.Block.Body.ExecutionPayload.StateRoot), - TimeStamp: uint64ToString(capellaBlock.Capella.Block.Body.ExecutionPayload.Timestamp), + Timestamp: uint64ToString(capellaBlock.Capella.Block.Body.ExecutionPayload.Timestamp), Transactions: jsonifyTransactions(capellaBlock.Capella.Block.Body.ExecutionPayload.Transactions), Withdrawals: jsonifyWithdrawals(capellaBlock.Capella.Block.Body.ExecutionPayload.Withdrawals), }, - BLSToExecutionChanges: jsonifyBlsToExecutionChanges(capellaBlock.Capella.Block.Body.BlsToExecutionChanges), + BlsToExecutionChanges: jsonifyBlsToExecutionChanges(capellaBlock.Capella.Block.Body.BlsToExecutionChanges), }, }, } diff --git a/validator/client/beacon-api/propose_beacon_block_phase0_test.go b/validator/client/beacon-api/propose_beacon_block_phase0_test.go index 29bb708aaa..b5f492bff4 100644 --- a/validator/client/beacon-api/propose_beacon_block_phase0_test.go +++ b/validator/client/beacon-api/propose_beacon_block_phase0_test.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -26,14 +26,14 @@ func TestProposeBeaconBlock_Phase0(t *testing.T) { genericSignedBlock := ðpb.GenericSignedBeaconBlock{} genericSignedBlock.Block = phase0Block - jsonPhase0Block := &apimiddleware.SignedBeaconBlockJson{ + jsonPhase0Block := &shared.SignedBeaconBlock{ Signature: hexutil.Encode(phase0Block.Phase0.Signature), - Message: &apimiddleware.BeaconBlockJson{ + Message: &shared.BeaconBlock{ ParentRoot: hexutil.Encode(phase0Block.Phase0.Block.ParentRoot), ProposerIndex: uint64ToString(phase0Block.Phase0.Block.ProposerIndex), Slot: uint64ToString(phase0Block.Phase0.Block.Slot), StateRoot: hexutil.Encode(phase0Block.Phase0.Block.StateRoot), - Body: &apimiddleware.BeaconBlockBodyJson{ + Body: &shared.BeaconBlockBody{ Attestations: jsonifyAttestations(phase0Block.Phase0.Block.Body.Attestations), AttesterSlashings: jsonifyAttesterSlashings(phase0Block.Phase0.Block.Body.AttesterSlashings), Deposits: jsonifyDeposits(phase0Block.Phase0.Block.Body.Deposits), diff --git a/validator/client/beacon-api/propose_exit.go b/validator/client/beacon-api/propose_exit.go index 8ec9035c49..20ef4d6fb2 100644 --- a/validator/client/beacon-api/propose_exit.go +++ b/validator/client/beacon-api/propose_exit.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -21,8 +21,8 @@ func (c beaconApiValidatorClient) proposeExit(ctx context.Context, signedVolunta return nil, errors.New("exit is nil") } - jsonSignedVoluntaryExit := apimiddleware.SignedVoluntaryExitJson{ - Exit: &apimiddleware.VoluntaryExitJson{ + jsonSignedVoluntaryExit := shared.SignedVoluntaryExit{ + Message: &shared.VoluntaryExit{ Epoch: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.Epoch), 10), ValidatorIndex: strconv.FormatUint(uint64(signedVoluntaryExit.Exit.ValidatorIndex), 10), }, diff --git a/validator/client/beacon-api/propose_exit_test.go b/validator/client/beacon-api/propose_exit_test.go index 916289d8a5..501afb7efd 100644 --- a/validator/client/beacon-api/propose_exit_test.go +++ b/validator/client/beacon-api/propose_exit_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -24,8 +24,8 @@ func TestProposeExit_Valid(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - jsonSignedVoluntaryExit := apimiddleware.SignedVoluntaryExitJson{ - Exit: &apimiddleware.VoluntaryExitJson{ + jsonSignedVoluntaryExit := shared.SignedVoluntaryExit{ + Message: &shared.VoluntaryExit{ Epoch: "1", ValidatorIndex: "2", }, diff --git a/validator/client/beacon-api/stream_blocks.go b/validator/client/beacon-api/stream_blocks.go index 9cf9fa3d21..c47a26eda3 100644 --- a/validator/client/beacon-api/stream_blocks.go +++ b/validator/client/beacon-api/stream_blocks.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -89,7 +88,7 @@ func (c beaconApiValidatorClient) getHeadSignedBeaconBlock(ctx context.Context) switch signedBlockResponseJson.Version { case "phase0": - jsonPhase0Block := apimiddleware.SignedBeaconBlockJson{} + jsonPhase0Block := shared.SignedBeaconBlock{} if err := decoder.Decode(&jsonPhase0Block); err != nil { return nil, errors.Wrap(err, "failed to decode signed phase0 block response json") } @@ -114,7 +113,7 @@ func (c beaconApiValidatorClient) getHeadSignedBeaconBlock(ctx context.Context) slot = phase0Block.Slot case "altair": - jsonAltairBlock := apimiddleware.SignedBeaconBlockAltairJson{} + jsonAltairBlock := shared.SignedBeaconBlockAltair{} if err := decoder.Decode(&jsonAltairBlock); err != nil { return nil, errors.Wrap(err, "failed to decode signed altair block response json") } @@ -139,7 +138,7 @@ func (c beaconApiValidatorClient) getHeadSignedBeaconBlock(ctx context.Context) slot = altairBlock.Slot case "bellatrix": - jsonBellatrixBlock := apimiddleware.SignedBeaconBlockBellatrixJson{} + jsonBellatrixBlock := shared.SignedBeaconBlockBellatrix{} if err := decoder.Decode(&jsonBellatrixBlock); err != nil { return nil, errors.Wrap(err, "failed to decode signed bellatrix block response json") } @@ -164,7 +163,7 @@ func (c beaconApiValidatorClient) getHeadSignedBeaconBlock(ctx context.Context) slot = bellatrixBlock.Slot case "capella": - jsonCapellaBlock := apimiddleware.SignedBeaconBlockCapellaJson{} + jsonCapellaBlock := shared.SignedBeaconBlockCapella{} if err := decoder.Decode(&jsonCapellaBlock); err != nil { return nil, errors.Wrap(err, "failed to decode signed capella block response json") } diff --git a/validator/client/beacon-api/stream_blocks_test.go b/validator/client/beacon-api/stream_blocks_test.go index 3c56bde23e..3afcf787a8 100644 --- a/validator/client/beacon-api/stream_blocks_test.go +++ b/validator/client/beacon-api/stream_blocks_test.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" rpctesting "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared/testing" eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -48,12 +47,12 @@ func TestStreamBlocks_UnsupportedConsensusVersion(t *testing.T) { func TestStreamBlocks_Error(t *testing.T) { testSuites := []struct { consensusVersion string - generateBeaconBlockConverter func(ctrl *gomock.Controller, conversionError error) *mock.MockbeaconBlockConverter + generateBeaconBlockConverter func(ctrl *gomock.Controller, conversionError error) *mock.MockBeaconBlockConverter }{ { consensusVersion: "phase0", - generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockbeaconBlockConverter { - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockBeaconBlockConverter { + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) beaconBlockConverter.EXPECT().ConvertRESTPhase0BlockToProto( gomock.Any(), ).Return( @@ -66,8 +65,8 @@ func TestStreamBlocks_Error(t *testing.T) { }, { consensusVersion: "altair", - generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockbeaconBlockConverter { - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockBeaconBlockConverter { + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) beaconBlockConverter.EXPECT().ConvertRESTAltairBlockToProto( gomock.Any(), ).Return( @@ -80,8 +79,8 @@ func TestStreamBlocks_Error(t *testing.T) { }, { consensusVersion: "bellatrix", - generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockbeaconBlockConverter { - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockBeaconBlockConverter { + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) beaconBlockConverter.EXPECT().ConvertRESTBellatrixBlockToProto( gomock.Any(), ).Return( @@ -94,8 +93,8 @@ func TestStreamBlocks_Error(t *testing.T) { }, { consensusVersion: "capella", - generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockbeaconBlockConverter { - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + generateBeaconBlockConverter: func(ctrl *gomock.Controller, conversionError error) *mock.MockBeaconBlockConverter { + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) beaconBlockConverter.EXPECT().ConvertRESTCapellaBlockToProto( gomock.Any(), ).Return( @@ -124,7 +123,7 @@ func TestStreamBlocks_Error(t *testing.T) { expectedErrorMessage: "failed to get signed %s block", conversionError: errors.New("foo"), generateData: func(consensusVersion string) []byte { - blockBytes, err := json.Marshal(apimiddleware.SignedBeaconBlockJson{Signature: "0x01"}) + blockBytes, err := json.Marshal(shared.SignedBeaconBlock{Signature: "0x01"}) require.NoError(t, err) return blockBytes }, @@ -133,7 +132,7 @@ func TestStreamBlocks_Error(t *testing.T) { name: "signature decoding failed", expectedErrorMessage: "failed to decode %s block signature `foo`", generateData: func(consensusVersion string) []byte { - blockBytes, err := json.Marshal(apimiddleware.SignedBeaconBlockJson{Signature: "foo"}) + blockBytes, err := json.Marshal(shared.SignedBeaconBlock{Signature: "foo"}) require.NoError(t, err) return blockBytes }, @@ -202,13 +201,13 @@ func TestStreamBlocks_Phase0Valid(t *testing.T) { signedBlockResponseJson := abstractSignedBlockResponseJson{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) // For the first call, return a block that satisfies the verifiedOnly condition. This block should be returned by the first Recv(). // For the second call, return the same block as the previous one. This block shouldn't be returned by the second Recv(). phase0BeaconBlock1 := test_helpers.GenerateJsonPhase0BeaconBlock() phase0BeaconBlock1.Slot = "1" - signedBeaconBlockContainer1 := apimiddleware.SignedBeaconBlockJson{ + signedBeaconBlockContainer1 := shared.SignedBeaconBlock{ Message: phase0BeaconBlock1, Signature: "0x01", } @@ -246,7 +245,7 @@ func TestStreamBlocks_Phase0Valid(t *testing.T) { // If verifiedOnly == false, this block will be returned by the second Recv(); otherwise, another block will be requested. phase0BeaconBlock2 := test_helpers.GenerateJsonPhase0BeaconBlock() phase0BeaconBlock2.Slot = "2" - signedBeaconBlockContainer2 := apimiddleware.SignedBeaconBlockJson{ + signedBeaconBlockContainer2 := shared.SignedBeaconBlock{ Message: phase0BeaconBlock2, Signature: "0x02", } @@ -366,13 +365,13 @@ func TestStreamBlocks_AltairValid(t *testing.T) { signedBlockResponseJson := abstractSignedBlockResponseJson{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) // For the first call, return a block that satisfies the verifiedOnly condition. This block should be returned by the first Recv(). // For the second call, return the same block as the previous one. This block shouldn't be returned by the second Recv(). altairBeaconBlock1 := test_helpers.GenerateJsonAltairBeaconBlock() altairBeaconBlock1.Slot = "1" - signedBeaconBlockContainer1 := apimiddleware.SignedBeaconBlockAltairJson{ + signedBeaconBlockContainer1 := shared.SignedBeaconBlockAltair{ Message: altairBeaconBlock1, Signature: "0x01", } @@ -410,7 +409,7 @@ func TestStreamBlocks_AltairValid(t *testing.T) { // If verifiedOnly == false, this block will be returned by the second Recv(); otherwise, another block will be requested. altairBeaconBlock2 := test_helpers.GenerateJsonAltairBeaconBlock() altairBeaconBlock2.Slot = "2" - signedBeaconBlockContainer2 := apimiddleware.SignedBeaconBlockAltairJson{ + signedBeaconBlockContainer2 := shared.SignedBeaconBlockAltair{ Message: altairBeaconBlock2, Signature: "0x02", } @@ -530,13 +529,13 @@ func TestStreamBlocks_BellatrixValid(t *testing.T) { signedBlockResponseJson := abstractSignedBlockResponseJson{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) // For the first call, return a block that satisfies the verifiedOnly condition. This block should be returned by the first Recv(). // For the second call, return the same block as the previous one. This block shouldn't be returned by the second Recv(). bellatrixBeaconBlock1 := test_helpers.GenerateJsonBellatrixBeaconBlock() bellatrixBeaconBlock1.Slot = "1" - signedBeaconBlockContainer1 := apimiddleware.SignedBeaconBlockBellatrixJson{ + signedBeaconBlockContainer1 := shared.SignedBeaconBlockBellatrix{ Message: bellatrixBeaconBlock1, Signature: "0x01", } @@ -574,7 +573,7 @@ func TestStreamBlocks_BellatrixValid(t *testing.T) { // If verifiedOnly == false, this block will be returned by the second Recv(); otherwise, another block will be requested. bellatrixBeaconBlock2 := test_helpers.GenerateJsonBellatrixBeaconBlock() bellatrixBeaconBlock2.Slot = "2" - signedBeaconBlockContainer2 := apimiddleware.SignedBeaconBlockBellatrixJson{ + signedBeaconBlockContainer2 := shared.SignedBeaconBlockBellatrix{ Message: bellatrixBeaconBlock2, Signature: "0x02", } @@ -694,13 +693,13 @@ func TestStreamBlocks_CapellaValid(t *testing.T) { signedBlockResponseJson := abstractSignedBlockResponseJson{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) // For the first call, return a block that satisfies the verifiedOnly condition. This block should be returned by the first Recv(). // For the second call, return the same block as the previous one. This block shouldn't be returned by the second Recv(). capellaBeaconBlock1 := test_helpers.GenerateJsonCapellaBeaconBlock() capellaBeaconBlock1.Slot = "1" - signedBeaconBlockContainer1 := apimiddleware.SignedBeaconBlockCapellaJson{ + signedBeaconBlockContainer1 := shared.SignedBeaconBlockCapella{ Message: capellaBeaconBlock1, Signature: "0x01", } @@ -738,7 +737,7 @@ func TestStreamBlocks_CapellaValid(t *testing.T) { // If verifiedOnly == false, this block will be returned by the second Recv(); otherwise, another block will be requested. capellaBeaconBlock2 := test_helpers.GenerateJsonCapellaBeaconBlock() capellaBeaconBlock2.Slot = "2" - signedBeaconBlockContainer2 := apimiddleware.SignedBeaconBlockCapellaJson{ + signedBeaconBlockContainer2 := shared.SignedBeaconBlockCapella{ Message: capellaBeaconBlock2, Signature: "0x02", } @@ -858,7 +857,7 @@ func TestStreamBlocks_DenebValid(t *testing.T) { signedBlockResponseJson := abstractSignedBlockResponseJson{} jsonRestHandler := mock.NewMockJsonRestHandler(ctrl) - beaconBlockConverter := mock.NewMockbeaconBlockConverter(ctrl) + beaconBlockConverter := mock.NewMockBeaconBlockConverter(ctrl) // For the first call, return a block that satisfies the verifiedOnly condition. This block should be returned by the first Recv(). // For the second call, return the same block as the previous one. This block shouldn't be returned by the second Recv(). diff --git a/validator/client/beacon-api/submit_aggregate_selection_proof.go b/validator/client/beacon-api/submit_aggregate_selection_proof.go index 23bf41b76f..731823814d 100644 --- a/validator/client/beacon-api/submit_aggregate_selection_proof.go +++ b/validator/client/beacon-api/submit_aggregate_selection_proof.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/validator" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/time/slots" @@ -84,13 +84,17 @@ func (c *beaconApiValidatorClient) submitAggregateSelectionProof(ctx context.Con }, nil } -func (c *beaconApiValidatorClient) getAggregateAttestation(ctx context.Context, slot primitives.Slot, attestationDataRoot []byte) (*apimiddleware.AggregateAttestationResponseJson, error) { +func (c *beaconApiValidatorClient) getAggregateAttestation( + ctx context.Context, + slot primitives.Slot, + attestationDataRoot []byte, +) (*validator.AggregateAttestationResponse, error) { params := url.Values{} params.Add("slot", strconv.FormatUint(uint64(slot), 10)) params.Add("attestation_data_root", hexutil.Encode(attestationDataRoot)) endpoint := buildURL("/eth/v1/validator/aggregate_attestation", params) - var aggregateAttestationResponse apimiddleware.AggregateAttestationResponseJson + var aggregateAttestationResponse validator.AggregateAttestationResponse errJson, err := c.jsonRestHandler.Get(ctx, endpoint, &aggregateAttestationResponse) if err != nil { return nil, errors.Wrapf(err, msgUnexpectedError) diff --git a/validator/client/beacon-api/submit_aggregate_selection_proof_test.go b/validator/client/beacon-api/submit_aggregate_selection_proof_test.go index 6ee2e22a76..493f234752 100644 --- a/validator/client/beacon-api/submit_aggregate_selection_proof_test.go +++ b/validator/client/beacon-api/submit_aggregate_selection_proof_test.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/node" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/validator" @@ -242,10 +241,10 @@ func TestSubmitAggregateSelectionProof(t *testing.T) { jsonRestHandler.EXPECT().Get( ctx, fmt.Sprintf("%s?attestation_data_root=%s&slot=%d", aggregateAttestationEndpoint, hexutil.Encode(attestationDataRootBytes[:]), slot), - &apimiddleware.AggregateAttestationResponseJson{}, + &validator.AggregateAttestationResponse{}, ).SetArg( 2, - apimiddleware.AggregateAttestationResponseJson{ + validator.AggregateAttestationResponse{ Data: jsonifyAttestation(aggregateAttestation), }, ).Return( diff --git a/validator/client/beacon-api/submit_signed_aggregate_proof.go b/validator/client/beacon-api/submit_signed_aggregate_proof.go index e0dc6948d2..81a435309f 100644 --- a/validator/client/beacon-api/submit_signed_aggregate_proof.go +++ b/validator/client/beacon-api/submit_signed_aggregate_proof.go @@ -6,12 +6,12 @@ import ( "encoding/json" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) func (c *beaconApiValidatorClient) submitSignedAggregateSelectionProof(ctx context.Context, in *ethpb.SignedAggregateSubmitRequest) (*ethpb.SignedAggregateSubmitResponse, error) { - body, err := json.Marshal([]*apimiddleware.SignedAggregateAttestationAndProofJson{jsonifySignedAggregateAndProof(in.SignedAggregateAndProof)}) + body, err := json.Marshal([]*shared.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(in.SignedAggregateAndProof)}) if err != nil { return nil, errors.Wrap(err, "failed to marshal SignedAggregateAttestationAndProof") } diff --git a/validator/client/beacon-api/submit_signed_aggregate_proof_test.go b/validator/client/beacon-api/submit_signed_aggregate_proof_test.go index 9f09a477ba..4c6a60c29c 100644 --- a/validator/client/beacon-api/submit_signed_aggregate_proof_test.go +++ b/validator/client/beacon-api/submit_signed_aggregate_proof_test.go @@ -8,7 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -21,7 +21,7 @@ func TestSubmitSignedAggregateSelectionProof_Valid(t *testing.T) { defer ctrl.Finish() signedAggregateAndProof := generateSignedAggregateAndProofJson() - marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*apimiddleware.SignedAggregateAttestationAndProofJson{jsonifySignedAggregateAndProof(signedAggregateAndProof)}) + marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*shared.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(signedAggregateAndProof)}) require.NoError(t, err) ctx := context.Background() @@ -54,7 +54,7 @@ func TestSubmitSignedAggregateSelectionProof_BadRequest(t *testing.T) { defer ctrl.Finish() signedAggregateAndProof := generateSignedAggregateAndProofJson() - marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*apimiddleware.SignedAggregateAttestationAndProofJson{jsonifySignedAggregateAndProof(signedAggregateAndProof)}) + marshalledSignedAggregateSignedAndProof, err := json.Marshal([]*shared.SignedAggregateAttestationAndProof{jsonifySignedAggregateAndProof(signedAggregateAndProof)}) require.NoError(t, err) ctx := context.Background() diff --git a/validator/client/beacon-api/submit_signed_contribution_and_proof.go b/validator/client/beacon-api/submit_signed_contribution_and_proof.go index 603877c8af..e718e1a1f9 100644 --- a/validator/client/beacon-api/submit_signed_contribution_and_proof.go +++ b/validator/client/beacon-api/submit_signed_contribution_and_proof.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -25,11 +25,11 @@ func (c beaconApiValidatorClient) submitSignedContributionAndProof(ctx context.C return errors.New("signed contribution and proof contribution is nil") } - jsonContributionAndProofs := []apimiddleware.SignedContributionAndProofJson{ + jsonContributionAndProofs := []shared.SignedContributionAndProof{ { - Message: &apimiddleware.ContributionAndProofJson{ + Message: &shared.ContributionAndProof{ AggregatorIndex: strconv.FormatUint(uint64(in.Message.AggregatorIndex), 10), - Contribution: &apimiddleware.SyncCommitteeContributionJson{ + Contribution: &shared.SyncCommitteeContribution{ Slot: strconv.FormatUint(uint64(in.Message.Contribution.Slot), 10), BeaconBlockRoot: hexutil.Encode(in.Message.Contribution.BlockRoot), SubcommitteeIndex: strconv.FormatUint(in.Message.Contribution.SubcommitteeIndex, 10), diff --git a/validator/client/beacon-api/submit_signed_contribution_and_proof_test.go b/validator/client/beacon-api/submit_signed_contribution_and_proof_test.go index b690487163..3c56ed3812 100644 --- a/validator/client/beacon-api/submit_signed_contribution_and_proof_test.go +++ b/validator/client/beacon-api/submit_signed_contribution_and_proof_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/testing/assert" "github.com/prysmaticlabs/prysm/v4/testing/require" @@ -22,11 +22,11 @@ func TestSubmitSignedContributionAndProof_Valid(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - jsonContributionAndProofs := []apimiddleware.SignedContributionAndProofJson{ + jsonContributionAndProofs := []shared.SignedContributionAndProof{ { - Message: &apimiddleware.ContributionAndProofJson{ + Message: &shared.ContributionAndProof{ AggregatorIndex: "1", - Contribution: &apimiddleware.SyncCommitteeContributionJson{ + Contribution: &shared.SyncCommitteeContribution{ Slot: "2", BeaconBlockRoot: hexutil.Encode([]byte{3}), SubcommitteeIndex: "4", diff --git a/validator/client/beacon-api/subscribe_committee_subnets.go b/validator/client/beacon-api/subscribe_committee_subnets.go index 8796745554..99be9f7e3f 100644 --- a/validator/client/beacon-api/subscribe_committee_subnets.go +++ b/validator/client/beacon-api/subscribe_committee_subnets.go @@ -7,7 +7,7 @@ import ( "strconv" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/time/slots" @@ -23,7 +23,7 @@ func (c beaconApiValidatorClient) subscribeCommitteeSubnets(ctx context.Context, } slotToCommitteesAtSlotMap := make(map[primitives.Slot]uint64) - jsonCommitteeSubscriptions := make([]*apimiddleware.BeaconCommitteeSubscribeJson, len(in.CommitteeIds)) + jsonCommitteeSubscriptions := make([]*shared.BeaconCommitteeSubscription, len(in.CommitteeIds)) for index := range in.CommitteeIds { subscribeSlot := in.Slots[index] subscribeCommitteeId := in.CommitteeIds[index] @@ -59,7 +59,7 @@ func (c beaconApiValidatorClient) subscribeCommitteeSubnets(ctx context.Context, } } - jsonCommitteeSubscriptions[index] = &apimiddleware.BeaconCommitteeSubscribeJson{ + jsonCommitteeSubscriptions[index] = &shared.BeaconCommitteeSubscription{ CommitteeIndex: strconv.FormatUint(uint64(subscribeCommitteeId), 10), CommitteesAtSlot: strconv.FormatUint(committeesAtSlot, 10), Slot: strconv.FormatUint(uint64(subscribeSlot), 10), diff --git a/validator/client/beacon-api/subscribe_committee_subnets_test.go b/validator/client/beacon-api/subscribe_committee_subnets_test.go index 9b3762f7a6..503c224199 100644 --- a/validator/client/beacon-api/subscribe_committee_subnets_test.go +++ b/validator/client/beacon-api/subscribe_committee_subnets_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/validator" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -31,9 +31,9 @@ func TestSubscribeCommitteeSubnets_Valid(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - jsonCommitteeSubscriptions := make([]*apimiddleware.BeaconCommitteeSubscribeJson, len(subscribeSlots)) + jsonCommitteeSubscriptions := make([]*shared.BeaconCommitteeSubscription, len(subscribeSlots)) for index := range jsonCommitteeSubscriptions { - jsonCommitteeSubscriptions[index] = &apimiddleware.BeaconCommitteeSubscribeJson{ + jsonCommitteeSubscriptions[index] = &shared.BeaconCommitteeSubscription{ ValidatorIndex: strconv.FormatUint(uint64(validatorIndices[index]), 10), CommitteeIndex: strconv.FormatUint(uint64(committeeIndices[index]), 10), CommitteesAtSlot: strconv.FormatUint(committeesAtSlot[index], 10), diff --git a/validator/client/beacon-api/sync_committee.go b/validator/client/beacon-api/sync_committee.go index 9311d1d85c..5cb65dcfed 100644 --- a/validator/client/beacon-api/sync_committee.go +++ b/validator/client/beacon-api/sync_committee.go @@ -9,8 +9,9 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/validator" "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v4/time/slots" @@ -44,7 +45,7 @@ func (c *beaconApiValidatorClient) submitSyncMessage(ctx context.Context, syncMe func (c *beaconApiValidatorClient) getSyncMessageBlockRoot(ctx context.Context) (*ethpb.SyncMessageBlockRootResponse, error) { // Get head beacon block root. - var resp apimiddleware.BlockRootResponseJson + var resp beacon.BlockRootResponse errJson, err := c.jsonRestHandler.Get(ctx, "/eth/v1/beacon/blocks/head/root", &resp) if err != nil { return nil, errors.Wrapf(err, msgUnexpectedError) @@ -95,7 +96,7 @@ func (c *beaconApiValidatorClient) getSyncCommitteeContribution( url := buildURL("/eth/v1/validator/sync_committee_contribution", params) - var resp apimiddleware.ProduceSyncCommitteeContributionResponseJson + var resp validator.ProduceSyncCommitteeContributionResponse errJson, err := c.jsonRestHandler.Get(ctx, url, &resp) if err != nil { return nil, errors.Wrapf(err, msgUnexpectedError) @@ -138,7 +139,7 @@ func (c *beaconApiValidatorClient) getSyncSubcommitteeIndex(ctx context.Context, return ðpb.SyncSubcommitteeIndexResponse{Indices: indices}, nil } -func convertSyncContributionJsonToProto(contribution *apimiddleware.SyncCommitteeContributionJson) (*ethpb.SyncCommitteeContribution, error) { +func convertSyncContributionJsonToProto(contribution *shared.SyncCommitteeContribution) (*ethpb.SyncCommitteeContribution, error) { if contribution == nil { return nil, errors.New("sync committee contribution is nil") } diff --git a/validator/client/beacon-api/sync_committee_test.go b/validator/client/beacon-api/sync_committee_test.go index d7b51b5be7..760759e2a1 100644 --- a/validator/client/beacon-api/sync_committee_test.go +++ b/validator/client/beacon-api/sync_committee_test.go @@ -11,7 +11,6 @@ import ( "github.com/golang/mock/gomock" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/validator" @@ -102,12 +101,12 @@ func TestGetSyncMessageBlockRoot(t *testing.T) { name string endpointError error expectedErrorMessage string - expectedResponse apimiddleware.BlockRootResponseJson + expectedResponse beacon.BlockRootResponse }{ { name: "valid request", - expectedResponse: apimiddleware.BlockRootResponseJson{ - Data: &apimiddleware.BlockRootContainerJson{ + expectedResponse: beacon.BlockRootResponse{ + Data: &beacon.BlockRoot{ Root: blockRoot, }, }, @@ -119,20 +118,20 @@ func TestGetSyncMessageBlockRoot(t *testing.T) { }, { name: "execution optimistic", - expectedResponse: apimiddleware.BlockRootResponseJson{ + expectedResponse: beacon.BlockRootResponse{ ExecutionOptimistic: true, }, expectedErrorMessage: "the node is currently optimistic and cannot serve validators", }, { name: "no data", - expectedResponse: apimiddleware.BlockRootResponseJson{}, + expectedResponse: beacon.BlockRootResponse{}, expectedErrorMessage: "no data returned", }, { name: "no root", - expectedResponse: apimiddleware.BlockRootResponseJson{ - Data: new(apimiddleware.BlockRootContainerJson), + expectedResponse: beacon.BlockRootResponse{ + Data: new(beacon.BlockRoot), }, expectedErrorMessage: "no root returned", }, @@ -145,7 +144,7 @@ func TestGetSyncMessageBlockRoot(t *testing.T) { jsonRestHandler.EXPECT().Get( ctx, "/eth/v1/beacon/blocks/head/root", - &apimiddleware.BlockRootResponseJson{}, + &beacon.BlockRootResponse{}, ).SetArg( 2, test.expectedResponse, @@ -184,7 +183,7 @@ func TestGetSyncCommitteeContribution(t *testing.T) { SubnetId: 1, } - contributionJson := &apimiddleware.SyncCommitteeContributionJson{ + contributionJson := &shared.SyncCommitteeContribution{ Slot: "1", BeaconBlockRoot: blockRoot, SubcommitteeIndex: "1", @@ -194,13 +193,13 @@ func TestGetSyncCommitteeContribution(t *testing.T) { tests := []struct { name string - contribution apimiddleware.ProduceSyncCommitteeContributionResponseJson + contribution validator.ProduceSyncCommitteeContributionResponse endpointErr error expectedErrMsg string }{ { name: "valid request", - contribution: apimiddleware.ProduceSyncCommitteeContributionResponseJson{Data: contributionJson}, + contribution: validator.ProduceSyncCommitteeContributionResponse{Data: contributionJson}, }, { name: "bad request", @@ -216,11 +215,11 @@ func TestGetSyncCommitteeContribution(t *testing.T) { jsonRestHandler.EXPECT().Get( ctx, "/eth/v1/beacon/blocks/head/root", - &apimiddleware.BlockRootResponseJson{}, + &beacon.BlockRootResponse{}, ).SetArg( 2, - apimiddleware.BlockRootResponseJson{ - Data: &apimiddleware.BlockRootContainerJson{ + beacon.BlockRootResponse{ + Data: &beacon.BlockRoot{ Root: blockRoot, }, }, @@ -233,7 +232,7 @@ func TestGetSyncCommitteeContribution(t *testing.T) { ctx, fmt.Sprintf("/eth/v1/validator/sync_committee_contribution?beacon_block_root=%s&slot=%d&subcommittee_index=%d", blockRoot, uint64(request.Slot), request.SubnetId), - &apimiddleware.ProduceSyncCommitteeContributionResponseJson{}, + &validator.ProduceSyncCommitteeContributionResponse{}, ).SetArg( 2, test.contribution, diff --git a/validator/client/beacon-api/test-helpers/BUILD.bazel b/validator/client/beacon-api/test-helpers/BUILD.bazel index dee0ff5921..142fbd19c5 100644 --- a/validator/client/beacon-api/test-helpers/BUILD.bazel +++ b/validator/client/beacon-api/test-helpers/BUILD.bazel @@ -14,7 +14,6 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/test-helpers", visibility = ["//validator:__subpackages__"], deps = [ - "//beacon-chain/rpc/apimiddleware:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/engine/v1:go_default_library", diff --git a/validator/client/beacon-api/test-helpers/altair_beacon_block_test_helpers.go b/validator/client/beacon-api/test-helpers/altair_beacon_block_test_helpers.go index 084fa1c3af..c19183c32b 100644 --- a/validator/client/beacon-api/test-helpers/altair_beacon_block_test_helpers.go +++ b/validator/client/beacon-api/test-helpers/altair_beacon_block_test_helpers.go @@ -1,7 +1,7 @@ package test_helpers import ( - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -219,24 +219,24 @@ func GenerateProtoAltairBeaconBlock() *ethpb.BeaconBlockAltair { } } -func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { - return &apimiddleware.BeaconBlockAltairJson{ +func GenerateJsonAltairBeaconBlock() *shared.BeaconBlockAltair { + return &shared.BeaconBlockAltair{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BeaconBlockBodyAltairJson{ + Body: &shared.BeaconBlockBodyAltair{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -245,8 +245,8 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -257,8 +257,8 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -267,8 +267,8 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -279,36 +279,36 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -317,34 +317,34 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -353,18 +353,18 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(4, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -373,15 +373,15 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -389,11 +389,11 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -401,31 +401,31 @@ func GenerateJsonAltairBeaconBlock() *apimiddleware.BeaconBlockAltairJson { }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, Signature: FillEncodedByteSlice(96, 109), }, }, - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: FillEncodedByteSlice(64, 110), SyncCommitteeSignature: FillEncodedByteSlice(96, 111), }, diff --git a/validator/client/beacon-api/test-helpers/bellatrix_beacon_block_test_helpers.go b/validator/client/beacon-api/test-helpers/bellatrix_beacon_block_test_helpers.go index 65653cc2cc..bd73e27589 100644 --- a/validator/client/beacon-api/test-helpers/bellatrix_beacon_block_test_helpers.go +++ b/validator/client/beacon-api/test-helpers/bellatrix_beacon_block_test_helpers.go @@ -1,7 +1,6 @@ package test_helpers import ( - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" @@ -471,24 +470,24 @@ func GenerateProtoBlindedBellatrixBeaconBlock() *ethpb.BlindedBeaconBlockBellatr } } -func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson { - return &apimiddleware.BeaconBlockBellatrixJson{ +func GenerateJsonBellatrixBeaconBlock() *shared.BeaconBlockBellatrix { + return &shared.BeaconBlockBellatrix{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BeaconBlockBodyBellatrixJson{ + Body: &shared.BeaconBlockBodyBellatrix{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -497,8 +496,8 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -509,8 +508,8 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -519,8 +518,8 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -531,36 +530,36 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -569,34 +568,34 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -605,18 +604,18 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(4, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -625,15 +624,15 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -641,11 +640,11 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -653,35 +652,35 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, Signature: FillEncodedByteSlice(96, 109), }, }, - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: FillEncodedByteSlice(64, 110), SyncCommitteeSignature: FillEncodedByteSlice(96, 111), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadJson{ + ExecutionPayload: &shared.ExecutionPayload{ ParentHash: FillEncodedByteSlice(32, 112), FeeRecipient: FillEncodedByteSlice(20, 113), StateRoot: FillEncodedByteSlice(32, 114), @@ -691,7 +690,7 @@ func GenerateJsonBellatrixBeaconBlock() *apimiddleware.BeaconBlockBellatrixJson BlockNumber: "118", GasLimit: "119", GasUsed: "120", - TimeStamp: "121", + Timestamp: "121", ExtraData: FillEncodedByteSlice(32, 122), BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(FillByteSlice(32, 123)).String(), BlockHash: FillEncodedByteSlice(32, 124), diff --git a/validator/client/beacon-api/test-helpers/capella_beacon_block_test_helpers.go b/validator/client/beacon-api/test-helpers/capella_beacon_block_test_helpers.go index 972bfac3a3..826e88f881 100644 --- a/validator/client/beacon-api/test-helpers/capella_beacon_block_test_helpers.go +++ b/validator/client/beacon-api/test-helpers/capella_beacon_block_test_helpers.go @@ -1,7 +1,6 @@ package test_helpers import ( - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" @@ -522,24 +521,24 @@ func GenerateProtoBlindedCapellaBeaconBlock() *ethpb.BlindedBeaconBlockCapella { } } -func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { - return &apimiddleware.BeaconBlockCapellaJson{ +func GenerateJsonCapellaBeaconBlock() *shared.BeaconBlockCapella { + return &shared.BeaconBlockCapella{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BeaconBlockBodyCapellaJson{ + Body: &shared.BeaconBlockBodyCapella{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -548,8 +547,8 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -560,8 +559,8 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -570,8 +569,8 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -582,36 +581,36 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -620,34 +619,34 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -656,18 +655,18 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(4, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -676,15 +675,15 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -692,11 +691,11 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -704,35 +703,35 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, Signature: FillEncodedByteSlice(96, 109), }, }, - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: FillEncodedByteSlice(64, 110), SyncCommitteeSignature: FillEncodedByteSlice(96, 111), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadCapellaJson{ + ExecutionPayload: &shared.ExecutionPayloadCapella{ ParentHash: FillEncodedByteSlice(32, 112), FeeRecipient: FillEncodedByteSlice(20, 113), StateRoot: FillEncodedByteSlice(32, 114), @@ -742,7 +741,7 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { BlockNumber: "118", GasLimit: "119", GasUsed: "120", - TimeStamp: "121", + Timestamp: "121", ExtraData: FillEncodedByteSlice(32, 122), BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(FillByteSlice(32, 123)).String(), BlockHash: FillEncodedByteSlice(32, 124), @@ -750,7 +749,7 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { FillEncodedByteSlice(32, 125), FillEncodedByteSlice(32, 126), }, - Withdrawals: []*apimiddleware.WithdrawalJson{ + Withdrawals: []*shared.Withdrawal{ { WithdrawalIndex: "127", ValidatorIndex: "128", @@ -765,9 +764,9 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { }, }, }, - BLSToExecutionChanges: []*apimiddleware.SignedBLSToExecutionChangeJson{ + BlsToExecutionChanges: []*shared.SignedBLSToExecutionChange{ { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "135", FromBLSPubkey: FillEncodedByteSlice(48, 136), ToExecutionAddress: FillEncodedByteSlice(20, 137), @@ -775,7 +774,7 @@ func GenerateJsonCapellaBeaconBlock() *apimiddleware.BeaconBlockCapellaJson { Signature: FillEncodedByteSlice(96, 138), }, { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "139", FromBLSPubkey: FillEncodedByteSlice(48, 140), ToExecutionAddress: FillEncodedByteSlice(20, 141), @@ -1014,19 +1013,19 @@ func GenerateJsonBlindedCapellaBeaconBlock() *shared.BlindedBeaconBlockCapella { TransactionsRoot: FillEncodedByteSlice(32, 125), WithdrawalsRoot: FillEncodedByteSlice(32, 126), }, - BlsToExecutionChanges: []*shared.SignedBlsToExecutionChange{ + BlsToExecutionChanges: []*shared.SignedBLSToExecutionChange{ { - Message: &shared.BlsToExecutionChange{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "135", - FromBlsPubkey: FillEncodedByteSlice(48, 136), + FromBLSPubkey: FillEncodedByteSlice(48, 136), ToExecutionAddress: FillEncodedByteSlice(20, 137), }, Signature: FillEncodedByteSlice(96, 138), }, { - Message: &shared.BlsToExecutionChange{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "139", - FromBlsPubkey: FillEncodedByteSlice(48, 140), + FromBLSPubkey: FillEncodedByteSlice(48, 140), ToExecutionAddress: FillEncodedByteSlice(20, 141), }, Signature: FillEncodedByteSlice(96, 142), diff --git a/validator/client/beacon-api/test-helpers/deneb_beacon_block_test_helpers.go b/validator/client/beacon-api/test-helpers/deneb_beacon_block_test_helpers.go index d2e4609e66..c27fb0e8b3 100644 --- a/validator/client/beacon-api/test-helpers/deneb_beacon_block_test_helpers.go +++ b/validator/client/beacon-api/test-helpers/deneb_beacon_block_test_helpers.go @@ -1,7 +1,7 @@ package test_helpers import ( - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" @@ -575,25 +575,25 @@ func GenerateProtoBlindedDenebBeaconBlock() *ethpb.BlindedBeaconBlockAndBlobsDen } } -func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson { - return &apimiddleware.BeaconBlockContentsDenebJson{ - Block: &apimiddleware.BeaconBlockDenebJson{ +func GenerateJsonDenebBeaconBlock() *shared.BeaconBlockContentsDeneb { + return &shared.BeaconBlockContentsDeneb{ + Block: &shared.BeaconBlockDeneb{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BeaconBlockBodyDenebJson{ + Body: &shared.BeaconBlockBodyDeneb{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -602,8 +602,8 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -614,8 +614,8 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -624,8 +624,8 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -636,36 +636,36 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -674,34 +674,34 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -710,18 +710,18 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(4, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -730,15 +730,15 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -746,11 +746,11 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -758,35 +758,35 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, Signature: FillEncodedByteSlice(96, 109), }, }, - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: FillEncodedByteSlice(64, 110), SyncCommitteeSignature: FillEncodedByteSlice(96, 111), }, - ExecutionPayload: &apimiddleware.ExecutionPayloadDenebJson{ + ExecutionPayload: &shared.ExecutionPayloadDeneb{ ParentHash: FillEncodedByteSlice(32, 112), FeeRecipient: FillEncodedByteSlice(20, 113), StateRoot: FillEncodedByteSlice(32, 114), @@ -796,7 +796,7 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson BlockNumber: "118", GasLimit: "119", GasUsed: "120", - TimeStamp: "121", + Timestamp: "121", ExtraData: FillEncodedByteSlice(32, 122), BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(FillByteSlice(32, 123)).String(), BlockHash: FillEncodedByteSlice(32, 124), @@ -804,7 +804,7 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson FillEncodedByteSlice(32, 125), FillEncodedByteSlice(32, 126), }, - Withdrawals: []*apimiddleware.WithdrawalJson{ + Withdrawals: []*shared.Withdrawal{ { WithdrawalIndex: "127", ValidatorIndex: "128", @@ -821,9 +821,9 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson BlobGasUsed: "135", ExcessBlobGas: "136", }, - BLSToExecutionChanges: []*apimiddleware.SignedBLSToExecutionChangeJson{ + BlsToExecutionChanges: []*shared.SignedBLSToExecutionChange{ { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "137", FromBLSPubkey: FillEncodedByteSlice(48, 138), ToExecutionAddress: FillEncodedByteSlice(20, 139), @@ -831,7 +831,7 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson Signature: FillEncodedByteSlice(96, 140), }, { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "141", FromBLSPubkey: FillEncodedByteSlice(48, 142), ToExecutionAddress: FillEncodedByteSlice(20, 143), @@ -842,7 +842,7 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson BlobKzgCommitments: []string{FillEncodedByteSlice(48, 145), FillEncodedByteSlice(48, 146)}, }, }, - BlobSidecars: []*apimiddleware.BlobSidecarJson{ + BlobSidecars: []*shared.BlobSidecar{ { BlockRoot: FillEncodedByteSlice(32, 147), Index: "148", @@ -867,25 +867,25 @@ func GenerateJsonDenebBeaconBlock() *apimiddleware.BeaconBlockContentsDenebJson } } -func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockContentsDenebJson { - return &apimiddleware.BlindedBeaconBlockContentsDenebJson{ - BlindedBlock: &apimiddleware.BlindedBeaconBlockDenebJson{ +func GenerateJsonBlindedDenebBeaconBlock() *shared.BlindedBeaconBlockContentsDeneb { + return &shared.BlindedBeaconBlockContentsDeneb{ + BlindedBlock: &shared.BlindedBeaconBlockDeneb{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BlindedBeaconBlockBodyDenebJson{ + Body: &shared.BlindedBeaconBlockBodyDeneb{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -894,8 +894,8 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -906,8 +906,8 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -916,8 +916,8 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -928,36 +928,36 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -966,34 +966,34 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -1002,18 +1002,18 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(4, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -1022,15 +1022,15 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -1038,11 +1038,11 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -1050,35 +1050,35 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, Signature: FillEncodedByteSlice(96, 109), }, }, - SyncAggregate: &apimiddleware.SyncAggregateJson{ + SyncAggregate: &shared.SyncAggregate{ SyncCommitteeBits: FillEncodedByteSlice(64, 110), SyncCommitteeSignature: FillEncodedByteSlice(96, 111), }, - ExecutionPayloadHeader: &apimiddleware.ExecutionPayloadHeaderDenebJson{ + ExecutionPayloadHeader: &shared.ExecutionPayloadHeaderDeneb{ ParentHash: FillEncodedByteSlice(32, 112), FeeRecipient: FillEncodedByteSlice(20, 113), StateRoot: FillEncodedByteSlice(32, 114), @@ -1088,7 +1088,7 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont BlockNumber: "118", GasLimit: "119", GasUsed: "120", - TimeStamp: "121", + Timestamp: "121", ExtraData: FillEncodedByteSlice(32, 122), BaseFeePerGas: bytesutil.LittleEndianBytesToBigInt(FillByteSlice(32, 123)).String(), BlockHash: FillEncodedByteSlice(32, 124), @@ -1097,9 +1097,9 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont BlobGasUsed: "127", ExcessBlobGas: "128", }, - BLSToExecutionChanges: []*apimiddleware.SignedBLSToExecutionChangeJson{ + BlsToExecutionChanges: []*shared.SignedBLSToExecutionChange{ { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "129", FromBLSPubkey: FillEncodedByteSlice(48, 130), ToExecutionAddress: FillEncodedByteSlice(20, 131), @@ -1107,7 +1107,7 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont Signature: FillEncodedByteSlice(96, 132), }, { - Message: &apimiddleware.BLSToExecutionChangeJson{ + Message: &shared.BLSToExecutionChange{ ValidatorIndex: "133", FromBLSPubkey: FillEncodedByteSlice(48, 134), ToExecutionAddress: FillEncodedByteSlice(20, 135), @@ -1118,7 +1118,7 @@ func GenerateJsonBlindedDenebBeaconBlock() *apimiddleware.BlindedBeaconBlockCont BlobKzgCommitments: []string{FillEncodedByteSlice(48, 137), FillEncodedByteSlice(48, 138)}, }, }, - BlindedBlobSidecars: []*apimiddleware.BlindedBlobSidecarJson{ + BlindedBlobSidecars: []*shared.BlindedBlobSidecar{ { BlockRoot: FillEncodedByteSlice(32, 139), Index: "140", diff --git a/validator/client/beacon-api/test-helpers/phase0_beacon_block_test_helpers.go b/validator/client/beacon-api/test-helpers/phase0_beacon_block_test_helpers.go index a250780b2b..2bfb597183 100644 --- a/validator/client/beacon-api/test-helpers/phase0_beacon_block_test_helpers.go +++ b/validator/client/beacon-api/test-helpers/phase0_beacon_block_test_helpers.go @@ -1,7 +1,7 @@ package test_helpers import ( - "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/apimiddleware" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/shared" ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" ) @@ -215,24 +215,24 @@ func GenerateProtoPhase0BeaconBlock() *ethpb.BeaconBlock { } } -func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { - return &apimiddleware.BeaconBlockJson{ +func GenerateJsonPhase0BeaconBlock() *shared.BeaconBlock { + return &shared.BeaconBlock{ Slot: "1", ProposerIndex: "2", ParentRoot: FillEncodedByteSlice(32, 3), StateRoot: FillEncodedByteSlice(32, 4), - Body: &apimiddleware.BeaconBlockBodyJson{ + Body: &shared.BeaconBlockBody{ RandaoReveal: FillEncodedByteSlice(96, 5), - Eth1Data: &apimiddleware.Eth1DataJson{ + Eth1Data: &shared.Eth1Data{ DepositRoot: FillEncodedByteSlice(32, 6), DepositCount: "7", BlockHash: FillEncodedByteSlice(32, 8), }, Graffiti: FillEncodedByteSlice(32, 9), - ProposerSlashings: []*apimiddleware.ProposerSlashingJson{ + ProposerSlashings: []*shared.ProposerSlashing{ { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "10", ProposerIndex: "11", ParentRoot: FillEncodedByteSlice(32, 12), @@ -241,8 +241,8 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, Signature: FillEncodedByteSlice(96, 15), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "16", ProposerIndex: "17", ParentRoot: FillEncodedByteSlice(32, 18), @@ -253,8 +253,8 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, }, { - Header_1: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader1: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "22", ProposerIndex: "23", ParentRoot: FillEncodedByteSlice(32, 24), @@ -263,8 +263,8 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, Signature: FillEncodedByteSlice(96, 27), }, - Header_2: &apimiddleware.SignedBeaconBlockHeaderJson{ - Header: &apimiddleware.BeaconBlockHeaderJson{ + SignedHeader2: &shared.SignedBeaconBlockHeader{ + Message: &shared.BeaconBlockHeader{ Slot: "28", ProposerIndex: "29", ParentRoot: FillEncodedByteSlice(32, 30), @@ -275,36 +275,36 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, }, }, - AttesterSlashings: []*apimiddleware.AttesterSlashingJson{ + AttesterSlashings: []*shared.AttesterSlashing{ { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"34", "35"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "36", CommitteeIndex: "37", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "39", Root: FillEncodedByteSlice(32, 40), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "41", Root: FillEncodedByteSlice(32, 42), }, }, Signature: FillEncodedByteSlice(96, 43), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"44", "45"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "46", CommitteeIndex: "47", BeaconBlockRoot: FillEncodedByteSlice(32, 48), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "49", Root: FillEncodedByteSlice(32, 50), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "51", Root: FillEncodedByteSlice(32, 52), }, @@ -313,34 +313,34 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, }, { - Attestation_1: &apimiddleware.IndexedAttestationJson{ + Attestation1: &shared.IndexedAttestation{ AttestingIndices: []string{"54", "55"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "56", CommitteeIndex: "57", BeaconBlockRoot: FillEncodedByteSlice(32, 58), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "59", Root: FillEncodedByteSlice(32, 60), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "61", Root: FillEncodedByteSlice(32, 62), }, }, Signature: FillEncodedByteSlice(96, 63), }, - Attestation_2: &apimiddleware.IndexedAttestationJson{ + Attestation2: &shared.IndexedAttestation{ AttestingIndices: []string{"64", "65"}, - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "66", CommitteeIndex: "67", BeaconBlockRoot: FillEncodedByteSlice(32, 68), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "69", Root: FillEncodedByteSlice(32, 70), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "71", Root: FillEncodedByteSlice(32, 72), }, @@ -349,18 +349,18 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, }, }, - Attestations: []*apimiddleware.AttestationJson{ + Attestations: []*shared.Attestation{ { AggregationBits: FillEncodedByteSlice(32, 74), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "75", CommitteeIndex: "76", BeaconBlockRoot: FillEncodedByteSlice(32, 77), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "78", Root: FillEncodedByteSlice(32, 79), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "80", Root: FillEncodedByteSlice(32, 81), }, @@ -369,15 +369,15 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, { AggregationBits: FillEncodedByteSlice(4, 83), - Data: &apimiddleware.AttestationDataJson{ + Data: &shared.AttestationData{ Slot: "84", CommitteeIndex: "85", BeaconBlockRoot: FillEncodedByteSlice(32, 38), - Source: &apimiddleware.CheckpointJson{ + Source: &shared.Checkpoint{ Epoch: "87", Root: FillEncodedByteSlice(32, 88), }, - Target: &apimiddleware.CheckpointJson{ + Target: &shared.Checkpoint{ Epoch: "89", Root: FillEncodedByteSlice(32, 90), }, @@ -385,11 +385,11 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { Signature: FillEncodedByteSlice(96, 91), }, }, - Deposits: []*apimiddleware.DepositJson{ + Deposits: []*shared.Deposit{ { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 92)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 94), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 94), WithdrawalCredentials: FillEncodedByteSlice(32, 95), Amount: "96", Signature: FillEncodedByteSlice(96, 97), @@ -397,24 +397,24 @@ func GenerateJsonPhase0BeaconBlock() *apimiddleware.BeaconBlockJson { }, { Proof: FillEncodedByteArraySlice(33, FillEncodedByteSlice(32, 98)), - Data: &apimiddleware.Deposit_DataJson{ - PublicKey: FillEncodedByteSlice(48, 100), + Data: &shared.DepositData{ + Pubkey: FillEncodedByteSlice(48, 100), WithdrawalCredentials: FillEncodedByteSlice(32, 101), Amount: "102", Signature: FillEncodedByteSlice(96, 103), }, }, }, - VoluntaryExits: []*apimiddleware.SignedVoluntaryExitJson{ + VoluntaryExits: []*shared.SignedVoluntaryExit{ { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "104", ValidatorIndex: "105", }, Signature: FillEncodedByteSlice(96, 106), }, { - Exit: &apimiddleware.VoluntaryExitJson{ + Message: &shared.VoluntaryExit{ Epoch: "107", ValidatorIndex: "108", }, diff --git a/validator/node/BUILD.bazel b/validator/node/BUILD.bazel index e6cd4c432c..9774123d4b 100644 --- a/validator/node/BUILD.bazel +++ b/validator/node/BUILD.bazel @@ -40,7 +40,6 @@ go_library( ], deps = [ "//api/gateway:go_default_library", - "//api/gateway/apimiddleware:go_default_library", "//api/server:go_default_library", "//async/event:go_default_library", "//cmd:go_default_library", diff --git a/validator/node/node.go b/validator/node/node.go index a41b3c1851..6f5b43638d 100644 --- a/validator/node/node.go +++ b/validator/node/node.go @@ -27,7 +27,6 @@ import ( "github.com/pkg/errors" fastssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v4/api/gateway" - "github.com/prysmaticlabs/prysm/v4/api/gateway/apimiddleware" "github.com/prysmaticlabs/prysm/v4/api/server" "github.com/prysmaticlabs/prysm/v4/async/event" "github.com/prysmaticlabs/prysm/v4/cmd" @@ -814,7 +813,7 @@ func (c *ValidatorClient) registerRPCGatewayService(router *mux.Router) error { gwruntime.WithForwardResponseOption(gateway.HttpResponseModifier), ) - muxHandler := func(_ *apimiddleware.ApiProxyMiddleware, h http.HandlerFunc, w http.ResponseWriter, req *http.Request) { + muxHandler := func(h http.HandlerFunc, w http.ResponseWriter, req *http.Request) { // The validator gateway handler requires this special logic as it serves the web APIs and the web UI. if strings.HasPrefix(req.URL.Path, "/api") { req.URL.Path = strings.Replace(req.URL.Path, "/api", "", 1)