Compare commits

...

2 Commits

Author SHA1 Message Date
james-prysm
b6e43638a3 changelog 2025-04-03 16:46:04 -05:00
james-prysm
7ccb2ba291 moved http-util to api package, and merged with api util. renamed grpc to grpcutil" 2025-04-03 16:34:27 -05:00
161 changed files with 1814 additions and 1862 deletions

View File

@@ -2,11 +2,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"constants.go",
"headers.go",
"jwt.go",
],
srcs = ["jwt.go"],
importpath = "github.com/prysmaticlabs/prysm/v5/api",
visibility = ["//visibility:public"],
deps = [

View File

@@ -1,19 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["common.go"],
importpath = "github.com/prysmaticlabs/prysm/v5/api/apiutil",
visibility = ["//visibility:public"],
deps = ["//consensus-types/primitives:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["common_test.go"],
embed = [":go_default_library"],
deps = [
"//consensus-types/primitives:go_default_library",
"//testing/assert:go_default_library",
],
)

View File

@@ -4,17 +4,22 @@ go_library(
name = "go_default_library",
srcs = [
"client.go",
"errors.go",
"options.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/api/client",
visibility = ["//visibility:public"],
deps = ["@com_github_pkg_errors//:go_default_library"],
deps = [
"//api/httputil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["client_test.go"],
embed = [":go_default_library"],
deps = ["//testing/require:go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//testing/require:go_default_library",
],
)

View File

@@ -14,6 +14,7 @@ go_library(
deps = [
"//api/client:go_default_library",
"//api/client/beacon/iface:go_default_library",
"//api/httputil:go_default_library",
"//api/server:go_default_library",
"//api/server/structs:go_default_library",
"//consensus-types/primitives:go_default_library",
@@ -34,8 +35,8 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api/client:go_default_library",
"//api/client/beacon/testing:go_default_library",
"//api/httputil:go_default_library",
"//testing/require:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
],

View File

@@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
@@ -184,7 +185,7 @@ var versionRE = regexp.MustCompile(`^(\w+)/(v\d+\.\d+\.\d+[-a-zA-Z0-9]*)\s*/?(.*
func parseNodeVersion(v string) (*NodeVersion, error) {
groups := versionRE.FindStringSubmatch(v)
if len(groups) != 4 {
return nil, errors.Wrapf(client.ErrInvalidNodeVersion, "could not be parsed: %s", v)
return nil, errors.Wrapf(httputil.ErrInvalidNodeVersion, "could not be parsed: %s", v)
}
return &NodeVersion{
implementation: groups[1],

View File

@@ -4,7 +4,7 @@ import (
"net/url"
"testing"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)
@@ -18,17 +18,17 @@ func TestParseNodeVersion(t *testing.T) {
{
name: "empty string",
v: "",
err: client.ErrInvalidNodeVersion,
err: httputil.ErrInvalidNodeVersion,
},
{
name: "Prysm as the version string",
v: "Prysm",
err: client.ErrInvalidNodeVersion,
err: httputil.ErrInvalidNodeVersion,
},
{
name: "semver only",
v: "v2.0.6",
err: client.ErrInvalidNodeVersion,
err: httputil.ErrInvalidNodeVersion,
},
{
name: "complete version",
@@ -92,7 +92,7 @@ func TestValidHostname(t *testing.T) {
{
name: "hostname without port",
hostArg: "mydomain.org",
err: client.ErrMalformedHostname,
err: httputil.ErrMalformedHostname,
},
{
name: "hostname with port",

View File

@@ -11,8 +11,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/api/client/builder",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/client:go_default_library",
"//api/httputil:go_default_library",
"//api/server:go_default_library",
"//api/server/structs:go_default_library",
"//config/fieldparams:go_default_library",
@@ -47,7 +46,7 @@ go_test(
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",

View File

@@ -13,8 +13,7 @@ import (
"text/template"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
@@ -191,7 +190,7 @@ func (c *Client) do(ctx context.Context, method string, path string, body io.Rea
err = non200Err(r)
return
}
res, err = io.ReadAll(io.LimitReader(r.Body, client.MaxBodySize))
res, err = io.ReadAll(io.LimitReader(r.Body, httputil.MaxBodySize))
if err != nil {
err = errors.Wrap(err, "error reading http response body from builder server")
return
@@ -229,11 +228,11 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
var getOpts reqOption
if c.sszEnabled {
getOpts = func(r *http.Request) {
r.Header.Set("Accept", api.OctetStreamMediaType)
r.Header.Set("Accept", httputil.OctetStreamMediaType)
}
} else {
getOpts = func(r *http.Request) {
r.Header.Set("Accept", api.JsonMediaType)
r.Header.Set("Accept", httputil.JsonMediaType)
}
}
data, header, err := c.do(ctx, http.MethodGet, path, nil, getOpts)
@@ -256,8 +255,8 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
func (c *Client) parseHeaderResponse(data []byte, header http.Header) (SignedBid, error) {
var versionHeader string
if c.sszEnabled || header.Get(api.VersionHeader) != "" {
versionHeader = header.Get(api.VersionHeader)
if c.sszEnabled || header.Get(httputil.VersionHeader) != "" {
versionHeader = header.Get(httputil.VersionHeader)
} else {
// If we don't have a version header, attempt to parse JSON for version
v := &VersionResponse{}
@@ -387,8 +386,8 @@ func (c *Client) RegisterValidator(ctx context.Context, svr []*ethpb.SignedValid
)
if c.sszEnabled {
postOpts = func(r *http.Request) {
r.Header.Set("Content-Type", api.OctetStreamMediaType)
r.Header.Set("Accept", api.OctetStreamMediaType)
r.Header.Set("Content-Type", httputil.OctetStreamMediaType)
r.Header.Set("Accept", httputil.OctetStreamMediaType)
}
body, err = sszValidatorRegisterRequest(svr)
if err != nil {
@@ -398,8 +397,8 @@ func (c *Client) RegisterValidator(ctx context.Context, svr []*ethpb.SignedValid
}
} else {
postOpts = func(r *http.Request) {
r.Header.Set("Content-Type", api.JsonMediaType)
r.Header.Set("Accept", api.JsonMediaType)
r.Header.Set("Content-Type", httputil.JsonMediaType)
r.Header.Set("Accept", httputil.JsonMediaType)
}
body, err = jsonValidatorRegisterRequest(svr)
if err != nil {
@@ -443,7 +442,7 @@ func sszValidatorRegisterRequest(svr []*ethpb.SignedValidatorRegistrationV1) ([]
return ssz, nil
}
var errResponseVersionMismatch = errors.New("builder API response uses a different version than requested in " + api.VersionHeader + " header")
var errResponseVersionMismatch = errors.New("builder API response uses a different version than requested in " + httputil.VersionHeader + " header")
func getVersionsBlockToPayload(blockVersion int) (int, error) {
if blockVersion >= version.Deneb {
@@ -501,7 +500,7 @@ func (c *Client) SubmitBlindedBlock(ctx context.Context, sb interfaces.ReadOnlyS
func (c *Client) checkBlockVersion(respBytes []byte, header http.Header) (int, error) {
var versionHeader string
if c.sszEnabled {
versionHeader = strings.ToLower(header.Get(api.VersionHeader))
versionHeader = strings.ToLower(header.Get(httputil.VersionHeader))
} else {
// fallback to JSON-based version extraction
v := &VersionResponse{}
@@ -531,9 +530,9 @@ func (c *Client) buildBlindedBlockRequest(sb interfaces.ReadOnlySignedBeaconBloc
return nil, nil, errors.Wrap(err, "could not marshal SSZ for blinded block")
}
opt := func(r *http.Request) {
r.Header.Set(api.VersionHeader, version.String(sb.Version()))
r.Header.Set("Content-Type", api.OctetStreamMediaType)
r.Header.Set("Accept", api.OctetStreamMediaType)
r.Header.Set(httputil.VersionHeader, version.String(sb.Version()))
r.Header.Set("Content-Type", httputil.OctetStreamMediaType)
r.Header.Set("Accept", httputil.OctetStreamMediaType)
}
return body, opt, nil
}
@@ -547,9 +546,9 @@ func (c *Client) buildBlindedBlockRequest(sb interfaces.ReadOnlySignedBeaconBloc
return nil, nil, errors.Wrap(err, "error marshaling blinded block to JSON")
}
opt := func(r *http.Request) {
r.Header.Set(api.VersionHeader, version.String(sb.Version()))
r.Header.Set("Content-Type", api.JsonMediaType)
r.Header.Set("Accept", api.JsonMediaType)
r.Header.Set(httputil.VersionHeader, version.String(sb.Version()))
r.Header.Set("Content-Type", httputil.JsonMediaType)
r.Header.Set("Accept", httputil.JsonMediaType)
}
return body, opt, nil
}
@@ -642,14 +641,14 @@ func (c *Client) parseBlindedBlockResponseJSON(
// happy path, and an error with information about the server response body for a non-200 response.
func (c *Client) Status(ctx context.Context) error {
getOpts := func(r *http.Request) {
r.Header.Set("Accept", api.JsonMediaType)
r.Header.Set("Accept", httputil.JsonMediaType)
}
_, _, err := c.do(ctx, http.MethodGet, getStatus, nil, getOpts)
return err
}
func non200Err(response *http.Response) error {
bodyBytes, err := io.ReadAll(io.LimitReader(response.Body, client.MaxErrBodySize))
bodyBytes, err := io.ReadAll(io.LimitReader(response.Body, httputil.MaxErrBodySize))
var errMessage ErrorMessage
var body string
if err != nil {

View File

@@ -11,7 +11,7 @@ import (
"testing"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
@@ -90,8 +90,8 @@ func TestClient_RegisterValidator(t *testing.T) {
t.Run("JSON success", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
body, err := io.ReadAll(r.Body)
defer func() {
require.NoError(t, r.Body.Close())
@@ -125,8 +125,8 @@ func TestClient_RegisterValidator(t *testing.T) {
t.Run("SSZ success", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
body, err := io.ReadAll(r.Body)
defer func() {
require.NoError(t, r.Body.Close())
@@ -220,7 +220,7 @@ func TestClient_GetHeader(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, expectedPath, r.URL.Path)
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(testExampleHeaderResponse)),
@@ -255,7 +255,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("bellatrix ssz", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
epr := &ExecHeaderResponse{}
require.NoError(t, json.Unmarshal([]byte(testExampleHeaderResponse), epr))
@@ -264,7 +264,7 @@ func TestClient_GetHeader(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "bellatrix")
header.Set(httputil.VersionHeader, "bellatrix")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -301,7 +301,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("capella", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
return &http.Response{
StatusCode: http.StatusOK,
@@ -333,7 +333,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("capella ssz", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
epr := &ExecHeaderResponseCapella{}
require.NoError(t, json.Unmarshal([]byte(testExampleHeaderResponseCapella), epr))
@@ -342,7 +342,7 @@ func TestClient_GetHeader(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "capella")
header.Set(httputil.VersionHeader, "capella")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -375,7 +375,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("deneb", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
return &http.Response{
StatusCode: http.StatusOK,
@@ -415,7 +415,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("deneb ssz", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
epr := &ExecHeaderResponseDeneb{}
require.NoError(t, json.Unmarshal([]byte(testExampleHeaderResponseDeneb), epr))
@@ -424,7 +424,7 @@ func TestClient_GetHeader(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "deneb")
header.Set(httputil.VersionHeader, "deneb")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -483,7 +483,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("electra", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
return &http.Response{
StatusCode: http.StatusOK,
@@ -528,7 +528,7 @@ func TestClient_GetHeader(t *testing.T) {
t.Run("electra ssz", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, expectedPath, r.URL.Path)
epr := &ExecHeaderResponseElectra{}
require.NoError(t, json.Unmarshal([]byte(testExampleHeaderResponseElectra), epr))
@@ -537,7 +537,7 @@ func TestClient_GetHeader(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "electra")
header.Set(httputil.VersionHeader, "electra")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -608,8 +608,8 @@ func TestSubmitBlindedBlock(t *testing.T) {
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "bellatrix", r.Header.Get("Eth-Consensus-Version"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(testExampleExecutionPayload)),
@@ -635,9 +635,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "bellatrix", r.Header.Get(api.VersionHeader))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, "bellatrix", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
epr := &ExecutionPayloadResponse{}
require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayload), epr))
ep := &ExecutionPayload{}
@@ -647,7 +647,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "bellatrix")
header.Set(httputil.VersionHeader, "bellatrix")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -675,9 +675,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "capella", r.Header.Get(api.VersionHeader))
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, "capella", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(testExampleExecutionPayloadCapella)),
@@ -705,9 +705,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "capella", r.Header.Get(api.VersionHeader))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, "capella", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
epr := &ExecutionPayloadResponse{}
require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadCapella), epr))
ep := &ExecutionPayloadCapella{}
@@ -717,7 +717,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
ssz, err := pro.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "capella")
header.Set(httputil.VersionHeader, "capella")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -748,9 +748,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "deneb", r.Header.Get(api.VersionHeader))
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, "deneb", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
var req structs.SignedBlindedBeaconBlockDeneb
err := json.NewDecoder(r.Body).Decode(&req)
require.NoError(t, err)
@@ -788,9 +788,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "deneb", r.Header.Get(api.VersionHeader))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, "deneb", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
epr := &ExecPayloadResponseDeneb{}
require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadDeneb), epr))
pro, blob, err := epr.ToProto()
@@ -802,7 +802,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
ssz, err := combined.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "deneb")
header.Set(httputil.VersionHeader, "deneb")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,
@@ -835,9 +835,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "electra", r.Header.Get(api.VersionHeader))
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
require.Equal(t, "electra", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.JsonMediaType, r.Header.Get("Accept"))
var req structs.SignedBlindedBeaconBlockElectra
err := json.NewDecoder(r.Body).Decode(&req)
require.NoError(t, err)
@@ -875,9 +875,9 @@ func TestSubmitBlindedBlock(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
require.Equal(t, "electra", r.Header.Get(api.VersionHeader))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
require.Equal(t, "electra", r.Header.Get(httputil.VersionHeader))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Content-Type"))
require.Equal(t, httputil.OctetStreamMediaType, r.Header.Get("Accept"))
epr := &ExecPayloadResponseDeneb{}
require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadDeneb), epr))
pro, blob, err := epr.ToProto()
@@ -889,7 +889,7 @@ func TestSubmitBlindedBlock(t *testing.T) {
ssz, err := combined.MarshalSSZ()
require.NoError(t, err)
header := http.Header{}
header.Set(api.VersionHeader, "electra")
header.Set(httputil.VersionHeader, "electra")
return &http.Response{
StatusCode: http.StatusOK,
Header: header,

View File

@@ -8,12 +8,7 @@ import (
"net/url"
"github.com/pkg/errors"
)
const (
MaxBodySize int64 = 1 << 23 // 8MB default, WithMaxBodySize can override
MaxBodySizeState int64 = 1 << 29 // 512MB
MaxErrBodySize int64 = 1 << 17 // 128KB
"github.com/prysmaticlabs/prysm/v5/api/httputil"
)
// Client is a wrapper object around the HTTP client.
@@ -35,7 +30,7 @@ func NewClient(host string, opts ...ClientOpt) (*Client, error) {
c := &Client{
hc: &http.Client{},
baseURL: u,
maxBodySize: MaxBodySize,
maxBodySize: httputil.MaxBodySize,
}
for _, o := range opts {
o(c)
@@ -67,7 +62,7 @@ func urlForHost(h string) (*url.URL, error) {
// try to parse as host:port
host, port, err := net.SplitHostPort(h)
if err != nil {
return nil, ErrMalformedHostname
return nil, httputil.ErrMalformedHostname
}
return &url.URL{Host: net.JoinHostPort(host, port), Scheme: "http"}, nil
}
@@ -95,7 +90,7 @@ func (c *Client) Get(ctx context.Context, path string, opts ...ReqOption) ([]byt
err = r.Body.Close()
}()
if r.StatusCode != http.StatusOK {
return nil, Non200Err(r)
return nil, httputil.Non200Err(r)
}
b, err := io.ReadAll(io.LimitReader(r.Body, c.maxBodySize))
if err != nil {

View File

@@ -4,6 +4,7 @@ import (
"net/url"
"testing"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)
@@ -18,7 +19,7 @@ func TestValidHostname(t *testing.T) {
{
name: "hostname without port",
hostArg: "mydomain.org",
err: ErrMalformedHostname,
err: httputil.ErrMalformedHostname,
},
}
for _, c := range cases {

View File

@@ -9,8 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/api/client/event",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/client:go_default_library",
"//api/httputil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@@ -8,8 +8,7 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
log "github.com/sirupsen/logrus"
)
@@ -85,13 +84,13 @@ func (h *EventStream) Subscribe(eventsChannel chan<- *Event) {
Data: []byte(errors.Wrap(err, "failed to create HTTP request").Error()),
}
}
req.Header.Set("Accept", api.EventStreamMediaType)
req.Header.Set("Connection", api.KeepAlive)
req.Header.Set("Accept", httputil.EventStreamMediaType)
req.Header.Set("Connection", httputil.KeepAlive)
resp, err := h.httpClient.Do(req)
if err != nil {
eventsChannel <- &Event{
EventType: EventConnectionError,
Data: []byte(errors.Wrap(err, client.ErrConnectionIssue.Error()).Error()),
Data: []byte(errors.Wrap(err, httputil.ErrConnectionIssue.Error()).Error()),
}
return
}
@@ -145,7 +144,7 @@ func (h *EventStream) Subscribe(eventsChannel chan<- *Event) {
if err := scanner.Err(); err != nil {
eventsChannel <- &Event{
EventType: EventConnectionError,
Data: []byte(errors.Wrap(err, errors.Wrap(client.ErrConnectionIssue, "scanner failed").Error()).Error()),
Data: []byte(errors.Wrap(err, errors.Wrap(httputil.ErrConnectionIssue, "scanner failed").Error()).Error()),
}
}
}

View File

@@ -3,10 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"grpcutils.go",
"common.go",
"parameters.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/api/grpc",
importpath = "github.com/prysmaticlabs/prysm/v5/api/grpcutil",
visibility = ["//visibility:public"],
deps = [
"@com_github_sirupsen_logrus//:go_default_library",
@@ -17,7 +17,7 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["grpcutils_test.go"],
srcs = ["common_test.go"],
embed = [":go_default_library"],
deps = [
"//testing/assert:go_default_library",

View File

@@ -1,4 +1,4 @@
package grpc
package grpcutil
import (
"context"

View File

@@ -1,4 +1,4 @@
package grpc
package grpcutil
import (
"context"

View File

@@ -1,4 +1,4 @@
package grpc
package grpcutil
// CustomErrorMetadataKey is the name of the metadata key storing additional error information.
// Metadata value is expected to be a byte-encoded JSON object.

View File

@@ -3,24 +3,31 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"common.go",
"constants.go",
"errors.go",
"headers.go",
"reader.go",
"writer.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/network/httputil",
importpath = "github.com/prysmaticlabs/prysm/v5/api/httputil",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//consensus-types/primitives:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["reader_test.go"],
srcs = [
"common_test.go",
"reader_test.go",
],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//consensus-types/primitives:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],

View File

@@ -1,4 +1,4 @@
package apiutil
package httputil
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package apiutil
package httputil
import (
"net/url"

View File

@@ -1,4 +1,4 @@
package api
package httputil
const (
WebUrlPrefix = "/v2/validator/"
@@ -7,3 +7,9 @@ const (
SystemLogsPrefix = "health/logs"
AuthTokenFileName = "auth-token"
)
const (
MaxBodySize int64 = 1 << 23 // 8MB default, WithMaxBodySize can override
MaxBodySizeState int64 = 1 << 29 // 512MB
MaxErrBodySize int64 = 1 << 17 // 128KB
)

View File

@@ -1,4 +1,4 @@
package client
package httputil
import (
"fmt"
@@ -8,6 +8,14 @@ import (
"github.com/pkg/errors"
)
func HandleError(w http.ResponseWriter, message string, code int) {
errJson := &DefaultJsonError{
Message: message,
Code: code,
}
WriteError(w, errJson)
}
// ErrMalformedHostname is used to indicate if a host name's format is incorrect.
var ErrMalformedHostname = errors.New("hostname must include port, separated by one colon, like example.com:3500")

View File

@@ -1,4 +1,4 @@
package api
package httputil
import "net/http"

View File

@@ -5,8 +5,6 @@ import (
"regexp"
"strconv"
"strings"
"github.com/prysmaticlabs/prysm/v5/api"
)
// match a number with optional decimals
@@ -23,7 +21,7 @@ func RespondWithSsz(req *http.Request) bool {
for _, t := range types {
values := strings.Split(t, ";")
name := values[0]
if name != api.JsonMediaType && name != api.OctetStreamMediaType {
if name != JsonMediaType && name != OctetStreamMediaType {
continue
}
// no params specified
@@ -49,10 +47,10 @@ func RespondWithSsz(req *http.Request) bool {
}
}
return currentType == api.OctetStreamMediaType
return currentType == OctetStreamMediaType
}
// IsRequestSsz checks if the request object should be interpreted as ssz
func IsRequestSsz(req *http.Request) bool {
return req.Header.Get("Content-Type") == api.OctetStreamMediaType
return req.Header.Get("Content-Type") == OctetStreamMediaType
}

View File

@@ -7,7 +7,6 @@ import (
"net/http/httptest"
"testing"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)
@@ -15,42 +14,42 @@ import (
func TestRespondWithSsz(t *testing.T) {
t.Run("ssz_requested", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example", nil)
request.Header["Accept"] = []string{api.OctetStreamMediaType}
request.Header["Accept"] = []string{OctetStreamMediaType}
result := RespondWithSsz(request)
assert.Equal(t, true, result)
})
t.Run("ssz_content_type_first", func(t *testing.T) {
request := httptest.NewRequest("GET", "http://foo.example", nil)
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s", api.OctetStreamMediaType, api.JsonMediaType)}
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s", OctetStreamMediaType, JsonMediaType)}
result := RespondWithSsz(request)
assert.Equal(t, true, result)
})
t.Run("ssz_content_type_preferred_1", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example", nil)
request.Header["Accept"] = []string{fmt.Sprintf("%s;q=0.9,%s", api.JsonMediaType, api.OctetStreamMediaType)}
request.Header["Accept"] = []string{fmt.Sprintf("%s;q=0.9,%s", JsonMediaType, OctetStreamMediaType)}
result := RespondWithSsz(request)
assert.Equal(t, true, result)
})
t.Run("ssz_content_type_preferred_2", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example", nil)
request.Header["Accept"] = []string{fmt.Sprintf("%s;q=0.95,%s;q=0.9", api.OctetStreamMediaType, api.JsonMediaType)}
request.Header["Accept"] = []string{fmt.Sprintf("%s;q=0.95,%s;q=0.9", OctetStreamMediaType, JsonMediaType)}
result := RespondWithSsz(request)
assert.Equal(t, true, result)
})
t.Run("other_content_type_preferred", func(t *testing.T) {
request := httptest.NewRequest("GET", "http://foo.example", nil)
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s;q=0.9", api.JsonMediaType, api.OctetStreamMediaType)}
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s;q=0.9", JsonMediaType, OctetStreamMediaType)}
result := RespondWithSsz(request)
assert.Equal(t, false, result)
})
t.Run("other_params", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example", nil)
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s;q=0.9,otherparam=xyz", api.JsonMediaType, api.OctetStreamMediaType)}
request.Header["Accept"] = []string{fmt.Sprintf("%s,%s;q=0.9,otherparam=xyz", JsonMediaType, OctetStreamMediaType)}
result := RespondWithSsz(request)
assert.Equal(t, false, result)
})
@@ -96,7 +95,7 @@ func TestIsRequestSsz(t *testing.T) {
_, err := body.WriteString("something")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", &body)
request.Header["Content-Type"] = []string{api.OctetStreamMediaType}
request.Header["Content-Type"] = []string{OctetStreamMediaType}
result := IsRequestSsz(request)
assert.Equal(t, true, result)
})
@@ -116,7 +115,7 @@ func TestIsRequestSsz(t *testing.T) {
t.Run("ssz Post json content type", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://foo.example", nil)
request.Header["Content-Type"] = []string{api.JsonMediaType}
request.Header["Content-Type"] = []string{JsonMediaType}
result := IsRequestSsz(request)
assert.Equal(t, false, result)
})

View File

@@ -8,7 +8,6 @@ import (
"net/http"
"strconv"
"github.com/prysmaticlabs/prysm/v5/api"
log "github.com/sirupsen/logrus"
)
@@ -32,7 +31,7 @@ func (e *DefaultJsonError) Error() string {
// WriteJson writes the response message in JSON format.
func WriteJson(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", api.JsonMediaType)
w.Header().Set("Content-Type", JsonMediaType)
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(v); err != nil {
log.WithError(err).Error("Could not write response message")
@@ -42,7 +41,7 @@ func WriteJson(w http.ResponseWriter, v any) {
// WriteSsz writes the response message in ssz format
func WriteSsz(w http.ResponseWriter, respSsz []byte) {
w.Header().Set("Content-Length", strconv.Itoa(len(respSsz)))
w.Header().Set("Content-Type", api.OctetStreamMediaType)
w.Header().Set("Content-Type", OctetStreamMediaType)
if _, err := io.Copy(w, io.NopCloser(bytes.NewReader(respSsz))); err != nil {
log.WithError(err).Error("could not write response message")
}
@@ -56,7 +55,7 @@ func WriteError(w http.ResponseWriter, errJson HasStatusCode) {
return
}
w.Header().Set("Content-Length", strconv.Itoa(len(j)))
w.Header().Set("Content-Type", api.JsonMediaType)
w.Header().Set("Content-Type", JsonMediaType)
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")

View File

@@ -19,7 +19,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],

View File

@@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)
@@ -55,7 +55,7 @@ func TestNormalizeQueryValuesHandler(t *testing.T) {
}
func TestContentTypeHandler(t *testing.T) {
acceptedMediaTypes := []string{api.JsonMediaType, api.OctetStreamMediaType}
acceptedMediaTypes := []string{httputil.JsonMediaType, httputil.OctetStreamMediaType}
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("next handler"))
@@ -72,12 +72,12 @@ func TestContentTypeHandler(t *testing.T) {
}{
{
name: "Accepted Content-Type - application/json",
contentType: api.JsonMediaType,
contentType: httputil.JsonMediaType,
expectedStatusCode: http.StatusOK,
},
{
name: "Accepted Content-Type - ssz format",
contentType: api.OctetStreamMediaType,
contentType: httputil.OctetStreamMediaType,
expectedStatusCode: http.StatusOK,
},
{

View File

@@ -11,7 +11,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/middleware:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/builder:go_default_library",

View File

@@ -5,7 +5,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/middleware"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/beacon"
@@ -123,7 +123,7 @@ func (s *Service) rewardsEndpoints(blocker lookup.Blocker, stater lookup.Stater,
template: "/eth/v1/beacon/rewards/blocks/{block_id}",
name: namespace + ".BlockRewards",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.BlockRewards,
methods: []string{http.MethodGet},
@@ -132,8 +132,8 @@ func (s *Service) rewardsEndpoints(blocker lookup.Blocker, stater lookup.Stater,
template: "/eth/v1/beacon/rewards/attestations/{epoch}",
name: namespace + ".AttestationRewards",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.AttestationRewards,
methods: []string{http.MethodPost},
@@ -142,8 +142,8 @@ func (s *Service) rewardsEndpoints(blocker lookup.Blocker, stater lookup.Stater,
template: "/eth/v1/beacon/rewards/sync_committee/{block_id}",
name: namespace + ".SyncCommitteeRewards",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SyncCommitteeRewards,
methods: []string{http.MethodPost},
@@ -165,7 +165,7 @@ func (s *Service) builderEndpoints(stater lookup.Stater) []endpoint {
template: "/eth/v1/builder/states/{state_id}/expected_withdrawals",
name: namespace + ".ExpectedWithdrawals",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.ExpectedWithdrawals,
methods: []string{http.MethodGet},
@@ -187,7 +187,7 @@ func (s *Service) blobEndpoints(blocker lookup.Blocker) []endpoint {
template: "/eth/v1/beacon/blob_sidecars/{block_id}",
name: namespace + ".Blobs",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.Blobs,
methods: []string{http.MethodGet},
@@ -230,7 +230,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/aggregate_attestation",
name: namespace + ".GetAggregateAttestation",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAggregateAttestation,
methods: []string{http.MethodGet},
@@ -239,7 +239,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v2/validator/aggregate_attestation",
name: namespace + ".GetAggregateAttestationV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAggregateAttestationV2,
methods: []string{http.MethodGet},
@@ -248,8 +248,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/contribution_and_proofs",
name: namespace + ".SubmitContributionAndProofs",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitContributionAndProofs,
methods: []string{http.MethodPost},
@@ -259,8 +259,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/aggregate_and_proofs",
name: namespace + ".SubmitAggregateAndProofs",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAggregateAndProofs,
methods: []string{http.MethodPost},
@@ -269,8 +269,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v2/validator/aggregate_and_proofs",
name: namespace + ".SubmitAggregateAndProofsV2",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAggregateAndProofsV2,
methods: []string{http.MethodPost},
@@ -279,7 +279,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/sync_committee_contribution",
name: namespace + ".ProduceSyncCommitteeContribution",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ProduceSyncCommitteeContribution,
methods: []string{http.MethodGet},
@@ -288,8 +288,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/sync_committee_subscriptions",
name: namespace + ".SubmitSyncCommitteeSubscription",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitSyncCommitteeSubscription,
methods: []string{http.MethodPost},
@@ -298,8 +298,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/beacon_committee_subscriptions",
name: namespace + ".SubmitBeaconCommitteeSubscription",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitBeaconCommitteeSubscription,
methods: []string{http.MethodPost},
@@ -308,7 +308,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/attestation_data",
name: namespace + ".GetAttestationData",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAttestationData,
methods: []string{http.MethodGet},
@@ -317,8 +317,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/register_validator",
name: namespace + ".RegisterValidator",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.RegisterValidator,
methods: []string{http.MethodPost},
@@ -327,8 +327,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/duties/attester/{epoch}",
name: namespace + ".GetAttesterDuties",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAttesterDuties,
methods: []string{http.MethodPost},
@@ -337,7 +337,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/duties/proposer/{epoch}",
name: namespace + ".GetProposerDuties",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetProposerDuties,
methods: []string{http.MethodGet},
@@ -346,8 +346,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/duties/sync/{epoch}",
name: namespace + ".GetSyncCommitteeDuties",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetSyncCommitteeDuties,
methods: []string{http.MethodPost},
@@ -356,8 +356,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/prepare_beacon_proposer",
name: namespace + ".PrepareBeaconProposer",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PrepareBeaconProposer,
methods: []string{http.MethodPost},
@@ -366,8 +366,8 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/liveness/{epoch}",
name: namespace + ".GetLiveness",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetLiveness,
methods: []string{http.MethodPost},
@@ -376,7 +376,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v2/validator/blocks/{slot}",
name: namespace + ".ProduceBlockV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.ProduceBlockV2,
methods: []string{http.MethodGet},
@@ -385,7 +385,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/blinded_blocks/{slot}",
name: namespace + ".ProduceBlindedBlock",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.ProduceBlindedBlock,
methods: []string{http.MethodGet},
@@ -394,7 +394,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v3/validator/blocks/{slot}",
name: namespace + ".ProduceBlockV3",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.ProduceBlockV3,
methods: []string{http.MethodGet},
@@ -403,7 +403,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/beacon_committee_selections",
name: namespace + ".BeaconCommitteeSelections",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
},
handler: server.BeaconCommitteeSelections,
methods: []string{http.MethodPost},
@@ -412,7 +412,7 @@ func (s *Service) validatorEndpoints(
template: "/eth/v1/validator/sync_committee_selections",
name: namespace + ".SyncCommittee Selections",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
},
handler: server.SyncCommitteeSelections,
methods: []string{http.MethodPost},
@@ -440,7 +440,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/syncing",
name: namespace + ".GetSyncStatus",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetSyncStatus,
methods: []string{http.MethodGet},
@@ -449,7 +449,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/identity",
name: namespace + ".GetIdentity",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetIdentity,
methods: []string{http.MethodGet},
@@ -458,7 +458,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/peers/{peer_id}",
name: namespace + ".GetPeer",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPeer,
methods: []string{http.MethodGet},
@@ -467,7 +467,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/peers",
name: namespace + ".GetPeers",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPeers,
methods: []string{http.MethodGet},
@@ -476,7 +476,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/peer_count",
name: namespace + ".GetPeerCount",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPeerCount,
methods: []string{http.MethodGet},
@@ -485,7 +485,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/version",
name: namespace + ".GetVersion",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetVersion,
methods: []string{http.MethodGet},
@@ -494,7 +494,7 @@ func (s *Service) nodeEndpoints() []endpoint {
template: "/eth/v1/node/health",
name: namespace + ".GetHealth",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetHealth,
methods: []string{http.MethodGet},
@@ -544,7 +544,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/committees",
name: namespace + ".GetCommittees",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetCommittees,
methods: []string{http.MethodGet},
@@ -553,7 +553,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/fork",
name: namespace + ".GetStateFork",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetStateFork,
methods: []string{http.MethodGet},
@@ -562,7 +562,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/root",
name: namespace + ".GetStateRoot",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetStateRoot,
methods: []string{http.MethodGet},
@@ -571,7 +571,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/sync_committees",
name: namespace + ".GetSyncCommittees",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetSyncCommittees,
methods: []string{http.MethodGet},
@@ -580,7 +580,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/randao",
name: namespace + ".GetRandao",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetRandao,
methods: []string{http.MethodGet},
@@ -590,8 +590,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/blocks",
name: namespace + ".PublishBlock",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PublishBlock,
methods: []string{http.MethodPost},
@@ -601,8 +601,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/blinded_blocks",
name: namespace + ".PublishBlindedBlock",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PublishBlindedBlock,
methods: []string{http.MethodPost},
@@ -611,8 +611,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/blocks",
name: namespace + ".PublishBlockV2",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PublishBlockV2,
methods: []string{http.MethodPost},
@@ -621,8 +621,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/blinded_blocks",
name: namespace + ".PublishBlindedBlockV2",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PublishBlindedBlockV2,
methods: []string{http.MethodPost},
@@ -631,7 +631,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/blocks/{block_id}",
name: namespace + ".GetBlockV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetBlockV2,
methods: []string{http.MethodGet},
@@ -641,7 +641,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/blocks/{block_id}/attestations",
name: namespace + ".GetBlockAttestations",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetBlockAttestations,
methods: []string{http.MethodGet},
@@ -650,7 +650,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/blocks/{block_id}/attestations",
name: namespace + ".GetBlockAttestationsV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetBlockAttestationsV2,
methods: []string{http.MethodGet},
@@ -659,7 +659,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/blinded_blocks/{block_id}",
name: namespace + ".GetBlindedBlock",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetBlindedBlock,
methods: []string{http.MethodGet},
@@ -668,7 +668,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/blocks/{block_id}/root",
name: namespace + ".GetBlockRoot",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetBlockRoot,
methods: []string{http.MethodGet},
@@ -678,7 +678,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/attestations",
name: namespace + ".ListAttestations",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListAttestations,
methods: []string{http.MethodGet},
@@ -687,7 +687,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/pool/attestations",
name: namespace + ".ListAttestationsV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListAttestationsV2,
methods: []string{http.MethodGet},
@@ -696,8 +696,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/attestations",
name: namespace + ".SubmitAttestations",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAttestations,
methods: []string{http.MethodPost},
@@ -706,8 +706,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/pool/attestations",
name: namespace + ".SubmitAttestationsV2",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAttestationsV2,
methods: []string{http.MethodPost},
@@ -716,7 +716,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/voluntary_exits",
name: namespace + ".ListVoluntaryExits",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListVoluntaryExits,
methods: []string{http.MethodGet},
@@ -725,8 +725,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/voluntary_exits",
name: namespace + ".SubmitVoluntaryExit",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitVoluntaryExit,
methods: []string{http.MethodPost},
@@ -735,8 +735,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/sync_committees",
name: namespace + ".SubmitSyncCommitteeSignatures",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitSyncCommitteeSignatures,
methods: []string{http.MethodPost},
@@ -745,7 +745,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/bls_to_execution_changes",
name: namespace + ".ListBLSToExecutionChanges",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListBLSToExecutionChanges,
methods: []string{http.MethodGet},
@@ -754,8 +754,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/bls_to_execution_changes",
name: namespace + ".SubmitBLSToExecutionChanges",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitBLSToExecutionChanges,
methods: []string{http.MethodPost},
@@ -765,7 +765,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/attester_slashings",
name: namespace + ".GetAttesterSlashings",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAttesterSlashings,
methods: []string{http.MethodGet},
@@ -774,7 +774,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/pool/attester_slashings",
name: namespace + ".GetAttesterSlashingsV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetAttesterSlashingsV2,
methods: []string{http.MethodGet},
@@ -783,8 +783,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/attester_slashings",
name: namespace + ".SubmitAttesterSlashings",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAttesterSlashings,
methods: []string{http.MethodPost},
@@ -793,8 +793,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v2/beacon/pool/attester_slashings",
name: namespace + ".SubmitAttesterSlashingsV2",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitAttesterSlashingsV2,
methods: []string{http.MethodPost},
@@ -803,7 +803,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/proposer_slashings",
name: namespace + ".GetProposerSlashings",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetProposerSlashings,
methods: []string{http.MethodGet},
@@ -812,8 +812,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/pool/proposer_slashings",
name: namespace + ".SubmitProposerSlashing",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.SubmitProposerSlashing,
methods: []string{http.MethodPost},
@@ -822,7 +822,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/headers",
name: namespace + ".GetBlockHeaders",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetBlockHeaders,
methods: []string{http.MethodGet},
@@ -831,7 +831,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/headers/{block_id}",
name: namespace + ".GetBlockHeader",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetBlockHeader,
methods: []string{http.MethodGet},
@@ -840,7 +840,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/genesis",
name: namespace + ".GetGenesis",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetGenesis,
methods: []string{http.MethodGet},
@@ -849,7 +849,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/finality_checkpoints",
name: namespace + ".GetFinalityCheckpoints",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetFinalityCheckpoints,
methods: []string{http.MethodGet},
@@ -858,8 +858,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/validators",
name: namespace + ".GetValidators",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetValidators,
methods: []string{http.MethodGet, http.MethodPost},
@@ -868,7 +868,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/validators/{validator_id}",
name: namespace + ".GetValidator",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetValidator,
methods: []string{http.MethodGet},
@@ -877,8 +877,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/validator_balances",
name: namespace + ".GetValidatorBalances",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetValidatorBalances,
methods: []string{http.MethodGet, http.MethodPost},
@@ -887,8 +887,8 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/validator_identities",
name: namespace + ".GetValidatorIdentities",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetValidatorIdentities,
methods: []string{http.MethodPost},
@@ -898,7 +898,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/deposit_snapshot",
name: namespace + ".GetDepositSnapshot",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetDepositSnapshot,
methods: []string{http.MethodGet},
@@ -907,7 +907,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/pending_deposits",
name: namespace + ".GetPendingDeposits",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPendingDeposits,
methods: []string{http.MethodGet},
@@ -916,7 +916,7 @@ func (s *Service) beaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/pending_partial_withdrawals",
name: namespace + ".GetPendingPartialWithdrawals",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPendingPartialWithdrawals,
methods: []string{http.MethodGet},
@@ -931,7 +931,7 @@ func (*Service) configEndpoints() []endpoint {
template: "/eth/v1/config/deposit_contract",
name: namespace + ".GetDepositContract",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: config.GetDepositContract,
methods: []string{http.MethodGet},
@@ -940,7 +940,7 @@ func (*Service) configEndpoints() []endpoint {
template: "/eth/v1/config/fork_schedule",
name: namespace + ".GetForkSchedule",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: config.GetForkSchedule,
methods: []string{http.MethodGet},
@@ -949,7 +949,7 @@ func (*Service) configEndpoints() []endpoint {
template: "/eth/v1/config/spec",
name: namespace + ".GetSpec",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: config.GetSpec,
methods: []string{http.MethodGet},
@@ -972,7 +972,7 @@ func (s *Service) lightClientEndpoints(blocker lookup.Blocker, stater lookup.Sta
template: "/eth/v1/beacon/light_client/bootstrap/{block_root}",
name: namespace + ".GetLightClientBootstrap",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetLightClientBootstrap,
methods: []string{http.MethodGet},
@@ -981,7 +981,7 @@ func (s *Service) lightClientEndpoints(blocker lookup.Blocker, stater lookup.Sta
template: "/eth/v1/beacon/light_client/updates",
name: namespace + ".GetLightClientUpdatesByRange",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetLightClientUpdatesByRange,
methods: []string{http.MethodGet},
@@ -990,7 +990,7 @@ func (s *Service) lightClientEndpoints(blocker lookup.Blocker, stater lookup.Sta
template: "/eth/v1/beacon/light_client/finality_update",
name: namespace + ".GetLightClientFinalityUpdate",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetLightClientFinalityUpdate,
methods: []string{http.MethodGet},
@@ -999,7 +999,7 @@ func (s *Service) lightClientEndpoints(blocker lookup.Blocker, stater lookup.Sta
template: "/eth/v1/beacon/light_client/optimistic_update",
name: namespace + ".GetLightClientOptimisticUpdate",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetLightClientOptimisticUpdate,
methods: []string{http.MethodGet},
@@ -1025,7 +1025,7 @@ func (s *Service) debugEndpoints(stater lookup.Stater) []endpoint {
template: "/eth/v2/debug/beacon/states/{state_id}",
name: namespace + ".GetBeaconStateV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType, httputil.OctetStreamMediaType}),
},
handler: server.GetBeaconStateV2,
methods: []string{http.MethodGet},
@@ -1034,7 +1034,7 @@ func (s *Service) debugEndpoints(stater lookup.Stater) []endpoint {
template: "/eth/v2/debug/beacon/heads",
name: namespace + ".GetForkChoiceHeadsV2",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetForkChoiceHeadsV2,
methods: []string{http.MethodGet},
@@ -1043,7 +1043,7 @@ func (s *Service) debugEndpoints(stater lookup.Stater) []endpoint {
template: "/eth/v1/debug/fork_choice",
name: namespace + ".GetForkChoice",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetForkChoice,
methods: []string{http.MethodGet},
@@ -1066,7 +1066,7 @@ func (s *Service) eventsEndpoints() []endpoint {
template: "/eth/v1/events",
name: namespace + ".StreamEvents",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.EventStreamMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.EventStreamMediaType}),
},
handler: server.StreamEvents,
methods: []string{http.MethodGet},
@@ -1101,7 +1101,7 @@ func (s *Service) prysmBeaconEndpoints(
template: "/prysm/v1/beacon/weak_subjectivity",
name: namespace + ".GetWeakSubjectivity",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetWeakSubjectivity,
methods: []string{http.MethodGet},
@@ -1110,7 +1110,7 @@ func (s *Service) prysmBeaconEndpoints(
template: "/eth/v1/beacon/states/{state_id}/validator_count",
name: namespace + ".GetValidatorCount",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetValidatorCount,
methods: []string{http.MethodGet},
@@ -1119,7 +1119,7 @@ func (s *Service) prysmBeaconEndpoints(
template: "/prysm/v1/beacon/states/{state_id}/validator_count",
name: namespace + ".GetValidatorCount",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetValidatorCount,
methods: []string{http.MethodGet},
@@ -1128,8 +1128,8 @@ func (s *Service) prysmBeaconEndpoints(
template: "/prysm/v1/beacon/individual_votes",
name: namespace + ".GetIndividualVotes",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetIndividualVotes,
methods: []string{http.MethodPost},
@@ -1138,7 +1138,7 @@ func (s *Service) prysmBeaconEndpoints(
template: "/prysm/v1/beacon/chain_head",
name: namespace + ".GetChainHead",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetChainHead,
methods: []string{http.MethodGet},
@@ -1147,8 +1147,8 @@ func (s *Service) prysmBeaconEndpoints(
template: "/prysm/v1/beacon/blobs",
name: namespace + ".PublishBlobs",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.PublishBlobs,
methods: []string{http.MethodPost},
@@ -1175,7 +1175,7 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/node/trusted_peers",
name: namespace + ".ListTrustedPeer",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListTrustedPeer,
methods: []string{http.MethodGet},
@@ -1184,7 +1184,7 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/v1/node/trusted_peers",
name: namespace + ".ListTrustedPeer",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.ListTrustedPeer,
methods: []string{http.MethodGet},
@@ -1193,8 +1193,8 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/node/trusted_peers",
name: namespace + ".AddTrustedPeer",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.AddTrustedPeer,
methods: []string{http.MethodPost},
@@ -1203,8 +1203,8 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/v1/node/trusted_peers",
name: namespace + ".AddTrustedPeer",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.AddTrustedPeer,
methods: []string{http.MethodPost},
@@ -1213,7 +1213,7 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/node/trusted_peers/{peer_id}",
name: namespace + ".RemoveTrustedPeer",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.RemoveTrustedPeer,
methods: []string{http.MethodDelete},
@@ -1222,7 +1222,7 @@ func (s *Service) prysmNodeEndpoints() []endpoint {
template: "/prysm/v1/node/trusted_peers/{peer_id}",
name: namespace + ".RemoveTrustedPeer",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.RemoveTrustedPeer,
methods: []string{http.MethodDelete},
@@ -1243,8 +1243,8 @@ func (s *Service) prysmValidatorEndpoints(stater lookup.Stater, coreService *cor
template: "/prysm/validators/performance",
name: namespace + ".GetPerformance",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPerformance,
methods: []string{http.MethodPost},
@@ -1253,8 +1253,8 @@ func (s *Service) prysmValidatorEndpoints(stater lookup.Stater, coreService *cor
template: "/prysm/v1/validators/performance",
name: namespace + ".GetPerformance",
middleware: []middleware.Middleware{
middleware.ContentTypeHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.ContentTypeHandler([]string{httputil.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetPerformance,
methods: []string{http.MethodPost},
@@ -1263,7 +1263,7 @@ func (s *Service) prysmValidatorEndpoints(stater lookup.Stater, coreService *cor
template: "/prysm/v1/validators/participation",
name: namespace + ".GetParticipation",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetParticipation,
methods: []string{http.MethodGet},
@@ -1272,7 +1272,7 @@ func (s *Service) prysmValidatorEndpoints(stater lookup.Stater, coreService *cor
template: "/prysm/v1/validators/active_set_changes",
name: namespace + ".GetActiveSetChanges",
middleware: []middleware.Middleware{
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
middleware.AcceptHeaderHandler([]string{httputil.JsonMediaType}),
},
handler: server.GetActiveSetChanges,
methods: []string{http.MethodGet},

View File

@@ -13,7 +13,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/beacon",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
@@ -54,7 +54,6 @@ go_library(
"//crypto/bls:go_default_library",
"//encoding/bytesutil:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
@@ -77,7 +76,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
@@ -112,7 +111,6 @@ go_test(
"//crypto/hash:go_default_library",
"//encoding/bytesutil:go_default_library",
"//encoding/ssz:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",

View File

@@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositsnapshot"
corehelpers "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
@@ -30,7 +30,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/time/slots"
@@ -100,9 +99,9 @@ func versionHeaderFromRequest(body []byte) (string, error) {
// from the request. If the version header is not provided and not required, it attempts
// to derive it from the request body.
func validateVersionHeader(r *http.Request, body []byte, versionRequired bool) (string, error) {
versionHeader := r.Header.Get(api.VersionHeader)
versionHeader := r.Header.Get(httputil2.VersionHeader)
if versionRequired && versionHeader == "" {
return "", fmt.Errorf("%s header is required", api.VersionHeader)
return "", fmt.Errorf("%s header is required", httputil2.VersionHeader)
}
if !versionRequired && versionHeader == "" {
@@ -152,7 +151,7 @@ func (s *Server) GetBlockV2(w http.ResponseWriter, r *http.Request) {
blockId := r.PathValue("block_id")
if blockId == "" {
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
return
}
blk, err := s.Blocker.Block(ctx, []byte(blockId))
@@ -164,12 +163,12 @@ func (s *Server) GetBlockV2(w http.ResponseWriter, r *http.Request) {
if blk.Version() >= version.Bellatrix && blk.IsBlinded() {
blk, err = s.ExecutionReconstructor.ReconstructFullBlock(ctx, blk)
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "could not reconstruct full execution payload to create signed beacon block").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrapf(err, "could not reconstruct full execution payload to create signed beacon block").Error(), http.StatusBadRequest)
return
}
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
s.getBlockV2Ssz(w, blk)
} else {
s.getBlockV2Json(ctx, w, blk)
@@ -183,7 +182,7 @@ func (s *Server) GetBlindedBlock(w http.ResponseWriter, r *http.Request) {
blockId := r.PathValue("block_id")
if blockId == "" {
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
return
}
blk, err := s.Blocker.Block(ctx, []byte(blockId))
@@ -200,7 +199,7 @@ func (s *Server) GetBlindedBlock(w http.ResponseWriter, r *http.Request) {
}
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
s.getBlockV2Ssz(w, blk)
} else {
s.getBlockV2Json(ctx, w, blk)
@@ -211,15 +210,15 @@ func (s *Server) GetBlindedBlock(w http.ResponseWriter, r *http.Request) {
func (s *Server) getBlockV2Ssz(w http.ResponseWriter, blk interfaces.ReadOnlySignedBeaconBlock) {
result, err := s.getBlockResponseBodySsz(blk)
if err != nil {
httputil.HandleError(w, "Could not get signed beacon block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get signed beacon block: "+err.Error(), http.StatusInternalServerError)
return
}
if result == nil {
httputil.HandleError(w, fmt.Sprintf("Unknown block type %T", blk), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unknown block type %T", blk), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(blk.Version()))
httputil.WriteSsz(w, result)
w.Header().Set(httputil2.VersionHeader, version.String(blk.Version()))
httputil2.WriteSsz(w, result)
}
func (*Server) getBlockResponseBodySsz(blk interfaces.ReadOnlySignedBeaconBlock) ([]byte, error) {
@@ -246,15 +245,15 @@ func (*Server) getBlockResponseBodySsz(blk interfaces.ReadOnlySignedBeaconBlock)
func (s *Server) getBlockV2Json(ctx context.Context, w http.ResponseWriter, blk interfaces.ReadOnlySignedBeaconBlock) {
result, err := s.getBlockResponseBodyJson(ctx, blk)
if err != nil {
httputil.HandleError(w, "Error processing request: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Error processing request: "+err.Error(), http.StatusInternalServerError)
return
}
if result == nil {
httputil.HandleError(w, fmt.Sprintf("Unknown block type %T", blk), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unknown block type %T", blk), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, result.Version)
httputil.WriteJson(w, result)
w.Header().Set(httputil2.VersionHeader, result.Version)
httputil2.WriteJson(w, result)
}
func (s *Server) getBlockResponseBodyJson(ctx context.Context, blk interfaces.ReadOnlySignedBeaconBlock) (*structs.GetBlockV2Response, error) {
@@ -309,7 +308,7 @@ func (s *Server) GetBlockAttestations(w http.ResponseWriter, r *http.Request) {
if ok {
atts[i] = structs.AttFromConsensus(a)
} else {
httputil.HandleError(w, fmt.Sprintf("unable to convert consensus attestations of type %T", att), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("unable to convert consensus attestations of type %T", att), http.StatusInternalServerError)
return
}
}
@@ -318,7 +317,7 @@ func (s *Server) GetBlockAttestations(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: s.FinalizationFetcher.IsFinalized(ctx, root),
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetBlockAttestationsV2 retrieves attestation included in requested block.
@@ -338,7 +337,7 @@ func (s *Server) GetBlockAttestationsV2(w http.ResponseWriter, r *http.Request)
for _, att := range consensusAtts {
a, ok := att.(*eth.AttestationElectra)
if !ok {
httputil.HandleError(w, fmt.Sprintf("unable to convert consensus attestations electra of type %T", att), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("unable to convert consensus attestations electra of type %T", att), http.StatusInternalServerError)
return
}
attStruct := structs.AttElectraFromConsensus(a)
@@ -348,7 +347,7 @@ func (s *Server) GetBlockAttestationsV2(w http.ResponseWriter, r *http.Request)
for _, att := range consensusAtts {
a, ok := att.(*eth.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("unable to convert consensus attestation of type %T", att), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("unable to convert consensus attestation of type %T", att), http.StatusInternalServerError)
return
}
attStruct := structs.AttFromConsensus(a)
@@ -358,7 +357,7 @@ func (s *Server) GetBlockAttestationsV2(w http.ResponseWriter, r *http.Request)
attBytes, err := json.Marshal(attStructs)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("failed to marshal attestations: %v", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("failed to marshal attestations: %v", err), http.StatusInternalServerError)
return
}
resp := &structs.GetBlockAttestationsV2Response{
@@ -367,14 +366,14 @@ func (s *Server) GetBlockAttestationsV2(w http.ResponseWriter, r *http.Request)
Finalized: s.FinalizationFetcher.IsFinalized(ctx, root),
Data: attBytes,
}
w.Header().Set(api.VersionHeader, version.String(v))
httputil.WriteJson(w, resp)
w.Header().Set(httputil2.VersionHeader, version.String(v))
httputil2.WriteJson(w, resp)
}
func (s *Server) blockData(ctx context.Context, w http.ResponseWriter, r *http.Request) (interfaces.ReadOnlySignedBeaconBlock, bool, [32]byte) {
blockId := r.PathValue("block_id")
if blockId == "" {
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
return nil, false, [32]byte{}
}
blk, err := s.Blocker.Block(ctx, []byte(blockId))
@@ -384,12 +383,12 @@ func (s *Server) blockData(ctx context.Context, w http.ResponseWriter, r *http.R
root, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return nil, false, [32]byte{}
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, root)
if err != nil {
httputil.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
return nil, false, [32]byte{}
}
return blk, isOptimistic, root
@@ -410,7 +409,7 @@ func (s *Server) PublishBlindedBlock(w http.ResponseWriter, r *http.Request) {
if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) {
return
}
if httputil.IsRequestSsz(r) {
if httputil2.IsRequestSsz(r) {
s.publishBlindedBlockSSZ(ctx, w, r, false)
} else {
s.publishBlindedBlock(ctx, w, r, false)
@@ -434,7 +433,7 @@ func (s *Server) PublishBlindedBlockV2(w http.ResponseWriter, r *http.Request) {
if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) {
return
}
if httputil.IsRequestSsz(r) {
if httputil2.IsRequestSsz(r) {
s.publishBlindedBlockSSZ(ctx, w, r, true)
} else {
s.publishBlindedBlock(ctx, w, r, true)
@@ -445,24 +444,24 @@ func (s *Server) PublishBlindedBlockV2(w http.ResponseWriter, r *http.Request) {
func (s *Server) publishBlindedBlockSSZ(ctx context.Context, w http.ResponseWriter, r *http.Request, versionRequired bool) {
body, err := readRequestBody(r)
if err != nil {
httputil.HandleError(w, "Could not read request body: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not read request body: "+err.Error(), http.StatusInternalServerError)
return
}
versionHeader, err := validateVersionHeader(r, body, versionRequired)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
genericBlock, err := decodeBlindedBlockSSZ(versionHeader, body)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
if err := s.validateBroadcast(ctx, r, genericBlock); err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
s.proposeBlock(ctx, w, genericBlock)
@@ -550,24 +549,24 @@ func decodeBlindedBellatrixSSZ(body []byte) (*eth.GenericSignedBeaconBlock, erro
func (s *Server) publishBlindedBlock(ctx context.Context, w http.ResponseWriter, r *http.Request, versionRequired bool) {
body, err := readRequestBody(r)
if err != nil {
httputil.HandleError(w, "Could not read request body", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not read request body", http.StatusInternalServerError)
return
}
versionHeader, err := validateVersionHeader(r, body, versionRequired)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
genericBlock, err := decodeBlindedBlockJSON(versionHeader, body)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
if err := s.validateBroadcast(ctx, r, genericBlock); err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
s.proposeBlock(ctx, w, genericBlock)
@@ -641,7 +640,7 @@ func (s *Server) PublishBlock(w http.ResponseWriter, r *http.Request) {
if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) {
return
}
if httputil.IsRequestSsz(r) {
if httputil2.IsRequestSsz(r) {
s.publishBlockSSZ(ctx, w, r, false)
} else {
s.publishBlock(ctx, w, r, false)
@@ -663,7 +662,7 @@ func (s *Server) PublishBlockV2(w http.ResponseWriter, r *http.Request) {
if shared.IsSyncing(r.Context(), w, s.SyncChecker, s.HeadFetcher, s.TimeFetcher, s.OptimisticModeFetcher) {
return
}
if httputil.IsRequestSsz(r) {
if httputil2.IsRequestSsz(r) {
s.publishBlockSSZ(ctx, w, r, true)
} else {
s.publishBlock(ctx, w, r, true)
@@ -674,20 +673,20 @@ func (s *Server) PublishBlockV2(w http.ResponseWriter, r *http.Request) {
func (s *Server) publishBlockSSZ(ctx context.Context, w http.ResponseWriter, r *http.Request, versionRequired bool) {
body, err := readRequestBody(r)
if err != nil {
httputil.HandleError(w, "Could not read request body", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not read request body", http.StatusInternalServerError)
return
}
versionHeader, err := validateVersionHeader(r, body, versionRequired)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
// Decode SSZ into a generic block.
genericBlock, err := decodeSSZToGenericBlock(versionHeader, body)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
@@ -696,14 +695,14 @@ func (s *Server) publishBlockSSZ(ctx context.Context, w http.ResponseWriter, r *
if errors.Is(err, errEquivocatedBlock) {
b, err := blocks.NewSignedBeaconBlock(genericBlock)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
if err = broadcastSidecarsIfSupported(ctx, s, b, genericBlock, versionHeader); err != nil {
log.WithError(err).Error("Failed to broadcast blob sidecars")
}
}
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
@@ -828,20 +827,20 @@ func decodePhase0SSZ(body []byte) (*eth.GenericSignedBeaconBlock, error) {
func (s *Server) publishBlock(ctx context.Context, w http.ResponseWriter, r *http.Request, versionRequired bool) {
body, err := readRequestBody(r)
if err != nil {
httputil.HandleError(w, "Could not read request body", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not read request body", http.StatusInternalServerError)
return
}
versionHeader, err := validateVersionHeader(r, body, versionRequired)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
// Decode JSON into a generic block.
genericBlock, decodeErr := decodeJSONToGenericBlock(versionHeader, body)
if decodeErr != nil {
httputil.HandleError(w, decodeErr.Error(), http.StatusBadRequest)
httputil2.HandleError(w, decodeErr.Error(), http.StatusBadRequest)
return
}
@@ -850,7 +849,7 @@ func (s *Server) publishBlock(ctx context.Context, w http.ResponseWriter, r *htt
if errors.Is(err, errEquivocatedBlock) {
b, err := blocks.NewSignedBeaconBlock(genericBlock)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
@@ -858,7 +857,7 @@ func (s *Server) publishBlock(ctx context.Context, w http.ResponseWriter, r *htt
log.WithError(err).Error("Failed to broadcast blob sidecars")
}
}
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
@@ -950,7 +949,7 @@ func broadcastSidecarsIfSupported(ctx context.Context, s *Server, b interfaces.S
func (s *Server) proposeBlock(ctx context.Context, w http.ResponseWriter, blk *eth.GenericSignedBeaconBlock) {
_, err := s.V1Alpha1ValidatorServer.ProposeBeaconBlock(ctx, blk)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
}
@@ -1069,18 +1068,18 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
var root []byte
blockID := r.PathValue("block_id")
if blockID == "" {
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
return
}
switch blockID {
case "head":
root, err = s.ChainInfoFetcher.HeadRoot(ctx)
if err != nil {
httputil.HandleError(w, "Could not retrieve head root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve head root: "+err.Error(), http.StatusInternalServerError)
return
}
if root == nil {
httputil.HandleError(w, "No head root was found", http.StatusNotFound)
httputil2.HandleError(w, "No head root was found", http.StatusNotFound)
return
}
case "finalized":
@@ -1089,16 +1088,16 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
case "genesis":
blk, err := s.BeaconDB.GenesisBlock(ctx)
if err != nil {
httputil.HandleError(w, "Could not retrieve genesis block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve genesis block: "+err.Error(), http.StatusInternalServerError)
return
}
if err := blocks.BeaconBlockIsNil(blk); err != nil {
httputil.HandleError(w, "Could not find genesis block: "+err.Error(), http.StatusNotFound)
httputil2.HandleError(w, "Could not find genesis block: "+err.Error(), http.StatusNotFound)
return
}
blkRoot, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not hash genesis block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not hash genesis block: "+err.Error(), http.StatusInternalServerError)
return
}
root = blkRoot[:]
@@ -1107,38 +1106,38 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
if isHex {
blockIDBytes, err := hexutil.Decode(blockID)
if err != nil {
httputil.HandleError(w, "Could not decode block ID into bytes: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode block ID into bytes: "+err.Error(), http.StatusBadRequest)
return
}
if len(blockIDBytes) != fieldparams.RootLength {
httputil.HandleError(w, fmt.Sprintf("Block ID has length %d instead of %d", len(blockIDBytes), fieldparams.RootLength), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Block ID has length %d instead of %d", len(blockIDBytes), fieldparams.RootLength), http.StatusBadRequest)
return
}
blockID32 := bytesutil.ToBytes32(blockIDBytes)
blk, err := s.BeaconDB.Block(ctx, blockID32)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not retrieve block for block root %#x: %v", blockID, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not retrieve block for block root %#x: %v", blockID, err), http.StatusInternalServerError)
return
}
if err := blocks.BeaconBlockIsNil(blk); err != nil {
httputil.HandleError(w, "Could not find block: "+err.Error(), http.StatusNotFound)
httputil2.HandleError(w, "Could not find block: "+err.Error(), http.StatusNotFound)
return
}
root = blockIDBytes
} else {
slot, err := strconv.ParseUint(blockID, 10, 64)
if err != nil {
httputil.HandleError(w, "Could not parse block ID: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not parse block ID: "+err.Error(), http.StatusBadRequest)
return
}
hasRoots, roots, err := s.BeaconDB.BlockRootsBySlot(ctx, primitives.Slot(slot))
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not retrieve blocks for slot %d: %v", slot, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not retrieve blocks for slot %d: %v", slot, err), http.StatusInternalServerError)
return
}
if !hasRoots {
httputil.HandleError(w, "Could not find any blocks with given slot", http.StatusNotFound)
httputil2.HandleError(w, "Could not find any blocks with given slot", http.StatusNotFound)
return
}
root = roots[0][:]
@@ -1148,7 +1147,7 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
for _, blockRoot := range roots {
canonical, err := s.ChainInfoFetcher.IsCanonical(ctx, blockRoot)
if err != nil {
httputil.HandleError(w, "Could not determine if block root is canonical: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not determine if block root is canonical: "+err.Error(), http.StatusInternalServerError)
return
}
if canonical {
@@ -1162,7 +1161,7 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
b32Root := bytesutil.ToBytes32(root)
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, b32Root)
if err != nil {
httputil.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
return
}
response := &structs.BlockRootResponse{
@@ -1172,7 +1171,7 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: s.FinalizationFetcher.IsFinalized(ctx, b32Root),
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetStateFork returns Fork object for state with given 'stateId'.
@@ -1182,7 +1181,7 @@ func (s *Server) GetStateFork(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -1193,12 +1192,12 @@ func (s *Server) GetStateFork(w http.ResponseWriter, r *http.Request) {
fork := st.Fork()
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status"+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Could not calculate root of latest block header: ").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrap(err, "Could not calculate root of latest block header: ").Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -1211,7 +1210,7 @@ func (s *Server) GetStateFork(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetCommittees retrieves the committees for the given state at the given epoch.
@@ -1222,7 +1221,7 @@ func (s *Server) GetCommittees(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
@@ -1251,18 +1250,18 @@ func (s *Server) GetCommittees(w http.ResponseWriter, r *http.Request) {
}
activeCount, err := corehelpers.ActiveValidatorCount(ctx, st, epoch)
if err != nil {
httputil.HandleError(w, "Could not get active validator count: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get active validator count: "+err.Error(), http.StatusInternalServerError)
return
}
startSlot, err := slots.EpochStart(epoch)
if err != nil {
httputil.HandleError(w, "Could not get epoch start slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get epoch start slot: "+err.Error(), http.StatusInternalServerError)
return
}
endSlot, err := slots.EpochEnd(epoch)
if err != nil {
httputil.HandleError(w, "Could not get epoch end slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get epoch end slot: "+err.Error(), http.StatusInternalServerError)
return
}
committeesPerSlot := corehelpers.SlotCommitteeCount(activeCount)
@@ -1277,7 +1276,7 @@ func (s *Server) GetCommittees(w http.ResponseWriter, r *http.Request) {
}
committee, err := corehelpers.BeaconCommitteeFromState(ctx, st, slot, index)
if err != nil {
httputil.HandleError(w, "Could not get committee: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get committee: "+err.Error(), http.StatusInternalServerError)
return
}
var validators []string
@@ -1295,17 +1294,17 @@ func (s *Server) GetCommittees(w http.ResponseWriter, r *http.Request) {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
httputil.WriteJson(w, &structs.GetCommitteesResponse{Data: committees, ExecutionOptimistic: isOptimistic, Finalized: isFinalized})
httputil2.WriteJson(w, &structs.GetCommitteesResponse{Data: committees, ExecutionOptimistic: isOptimistic, Finalized: isFinalized})
}
// GetBlockHeaders retrieves block headers matching given query. By default it will fetch current head slot blocks.
@@ -1329,7 +1328,7 @@ func (s *Server) GetBlockHeaders(w http.ResponseWriter, r *http.Request) {
if rawParentRoot != "" {
blks, blkRoots, err = s.BeaconDB.Blocks(ctx, filters.NewFilter().SetParentRoot(parentRoot))
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for parent root %s", parentRoot).Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for parent root %s", parentRoot).Error(), http.StatusInternalServerError)
return
}
} else {
@@ -1338,18 +1337,18 @@ func (s *Server) GetBlockHeaders(w http.ResponseWriter, r *http.Request) {
}
blks, err = s.BeaconDB.BlocksBySlot(ctx, primitives.Slot(slot))
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for slot %d", slot).Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for slot %d", slot).Error(), http.StatusInternalServerError)
return
}
_, blkRoots, err = s.BeaconDB.BlockRootsBySlot(ctx, primitives.Slot(slot))
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for slot %d", slot).Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not retrieve blocks for slot %d", slot).Error(), http.StatusInternalServerError)
return
}
}
if len(blks) == 0 {
httputil.HandleError(w, "No blocks found", http.StatusNotFound)
httputil2.HandleError(w, "No blocks found", http.StatusNotFound)
return
}
@@ -1359,23 +1358,23 @@ func (s *Server) GetBlockHeaders(w http.ResponseWriter, r *http.Request) {
for i, bl := range blks {
v1alpha1Header, err := bl.Header()
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not get block header from block").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not get block header from block").Error(), http.StatusInternalServerError)
return
}
headerRoot, err := v1alpha1Header.Header.HashTreeRoot()
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not hash block header").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not hash block header").Error(), http.StatusInternalServerError)
return
}
canonical, err := s.ChainInfoFetcher.IsCanonical(ctx, blkRoots[i])
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not determine if block root is canonical").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not determine if block root is canonical").Error(), http.StatusInternalServerError)
return
}
if !isOptimistic {
isOptimistic, err = s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, blkRoots[i])
if err != nil {
httputil.HandleError(w, errors.Wrapf(err, "Could not check if block is optimistic").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrapf(err, "Could not check if block is optimistic").Error(), http.StatusInternalServerError)
return
}
}
@@ -1397,7 +1396,7 @@ func (s *Server) GetBlockHeaders(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetBlockHeader retrieves block header for given block id.
@@ -1407,7 +1406,7 @@ func (s *Server) GetBlockHeader(w http.ResponseWriter, r *http.Request) {
blockID := r.PathValue("block_id")
if blockID == "" {
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
return
}
@@ -1418,27 +1417,27 @@ func (s *Server) GetBlockHeader(w http.ResponseWriter, r *http.Request) {
}
blockHeader, err := blk.Header()
if err != nil {
httputil.HandleError(w, "Could not get block header: %s"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get block header: %s"+err.Error(), http.StatusInternalServerError)
return
}
headerRoot, err := blockHeader.Header.HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not hash block header: %s"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not hash block header: %s"+err.Error(), http.StatusInternalServerError)
return
}
blkRoot, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not hash block: %s"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not hash block: %s"+err.Error(), http.StatusInternalServerError)
return
}
canonical, err := s.ChainInfoFetcher.IsCanonical(ctx, blkRoot)
if err != nil {
httputil.HandleError(w, "Could not determine if block root is canonical: %s"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not determine if block root is canonical: %s"+err.Error(), http.StatusInternalServerError)
return
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, blkRoot)
if err != nil {
httputil.HandleError(w, "Could not check if block is optimistic: %s"+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if block is optimistic: %s"+err.Error(), http.StatusInternalServerError)
return
}
@@ -1454,7 +1453,7 @@ func (s *Server) GetBlockHeader(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: s.FinalizationFetcher.IsFinalized(ctx, blkRoot),
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetFinalityCheckpoints returns finality checkpoints for state with given 'stateId'. In case finality is
@@ -1465,7 +1464,7 @@ func (s *Server) GetFinalityCheckpoints(w http.ResponseWriter, r *http.Request)
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
@@ -1476,12 +1475,12 @@ func (s *Server) GetFinalityCheckpoints(w http.ResponseWriter, r *http.Request)
}
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -1507,7 +1506,7 @@ func (s *Server) GetFinalityCheckpoints(w http.ResponseWriter, r *http.Request)
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetGenesis retrieves details of the chain's genesis which can be used to identify chain.
@@ -1517,12 +1516,12 @@ func (s *Server) GetGenesis(w http.ResponseWriter, r *http.Request) {
genesisTime := s.GenesisTimeFetcher.GenesisTime()
if genesisTime.IsZero() {
httputil.HandleError(w, "Chain genesis info is not yet known", http.StatusNotFound)
httputil2.HandleError(w, "Chain genesis info is not yet known", http.StatusNotFound)
return
}
validatorsRoot := s.ChainInfoFetcher.GenesisValidatorsRoot()
if bytes.Equal(validatorsRoot[:], params.BeaconConfig().ZeroHash[:]) {
httputil.HandleError(w, "Chain genesis info is not yet known", http.StatusNotFound)
httputil2.HandleError(w, "Chain genesis info is not yet known", http.StatusNotFound)
return
}
forkVersion := params.BeaconConfig().GenesisForkVersion
@@ -1534,7 +1533,7 @@ func (s *Server) GetGenesis(w http.ResponseWriter, r *http.Request) {
GenesisForkVersion: hexutil.Encode(forkVersion),
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// Deprecated: no longer needed post Electra
@@ -1546,32 +1545,32 @@ func (s *Server) GetDepositSnapshot(w http.ResponseWriter, r *http.Request) {
eth1data, err := s.BeaconDB.ExecutionChainData(ctx)
if err != nil {
httputil.HandleError(w, "Could not retrieve execution chain data: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve execution chain data: "+err.Error(), http.StatusInternalServerError)
return
}
if eth1data == nil {
httputil.HandleError(w, "Could not retrieve execution chain data: empty Eth1Data", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve execution chain data: empty Eth1Data", http.StatusInternalServerError)
return
}
snapshot := eth1data.DepositSnapshot
if snapshot == nil || len(snapshot.Finalized) == 0 {
httputil.HandleError(w, "No finalized snapshot available", http.StatusNotFound)
httputil2.HandleError(w, "No finalized snapshot available", http.StatusNotFound)
return
}
if len(snapshot.Finalized) > depositsnapshot.DepositContractDepth {
httputil.HandleError(w, "Retrieved invalid deposit snapshot", http.StatusInternalServerError)
httputil2.HandleError(w, "Retrieved invalid deposit snapshot", http.StatusInternalServerError)
return
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
sszData, err := snapshot.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal deposit snapshot into SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal deposit snapshot into SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszData)
httputil2.WriteSsz(w, sszData)
return
}
httputil.WriteJson(
httputil2.WriteJson(
w,
&structs.GetDepositSnapshotResponse{
Data: structs.DepositSnapshotFromConsensus(snapshot),
@@ -1622,7 +1621,7 @@ func (s *Server) GetPendingDeposits(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -1631,31 +1630,31 @@ func (s *Server) GetPendingDeposits(w http.ResponseWriter, r *http.Request) {
return
}
if st.Version() < version.Electra {
httputil.HandleError(w, "state_id is prior to electra", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is prior to electra", http.StatusBadRequest)
return
}
pd, err := st.PendingDeposits()
if err != nil {
httputil.HandleError(w, "Could not get pending deposits: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get pending deposits: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(st.Version()))
if httputil.RespondWithSsz(r) {
w.Header().Set(httputil2.VersionHeader, version.String(st.Version()))
if httputil2.RespondWithSsz(r) {
sszData, err := serializeItems(pd)
if err != nil {
httputil.HandleError(w, "Failed to serialize pending deposits: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Failed to serialize pending deposits: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszData)
httputil2.WriteSsz(w, sszData)
} else {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -1665,7 +1664,7 @@ func (s *Server) GetPendingDeposits(w http.ResponseWriter, r *http.Request) {
Finalized: isFinalized,
Data: structs.PendingDepositsFromConsensus(pd),
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
}
@@ -1678,7 +1677,7 @@ func (s *Server) GetPendingPartialWithdrawals(w http.ResponseWriter, r *http.Req
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -1687,31 +1686,31 @@ func (s *Server) GetPendingPartialWithdrawals(w http.ResponseWriter, r *http.Req
return
}
if st.Version() < version.Electra {
httputil.HandleError(w, "state_id is prior to electra", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is prior to electra", http.StatusBadRequest)
return
}
ppw, err := st.PendingPartialWithdrawals()
if err != nil {
httputil.HandleError(w, "Could not get pending partial withdrawals: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get pending partial withdrawals: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(st.Version()))
if httputil.RespondWithSsz(r) {
w.Header().Set(httputil2.VersionHeader, version.String(st.Version()))
if httputil2.RespondWithSsz(r) {
sszData, err := serializeItems(ppw)
if err != nil {
httputil.HandleError(w, "Failed to serialize pending partial withdrawals: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Failed to serialize pending partial withdrawals: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszData)
httputil2.WriteSsz(w, sszData)
} else {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -1721,7 +1720,7 @@ func (s *Server) GetPendingPartialWithdrawals(w http.ResponseWriter, r *http.Req
Finalized: isFinalized,
Data: structs.PendingPartialWithdrawalsFromConsensus(ppw),
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
}

View File

@@ -11,7 +11,7 @@ import (
"time"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
@@ -26,7 +26,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/time/slots"
@@ -64,7 +63,7 @@ func (s *Server) ListAttestations(w http.ResponseWriter, r *http.Request) {
var includeAttestation bool
att, ok := a.(*eth.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", a), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", a), http.StatusInternalServerError)
return
}
@@ -77,11 +76,11 @@ func (s *Server) ListAttestations(w http.ResponseWriter, r *http.Request) {
attsData, err := json.Marshal(filteredAtts)
if err != nil {
httputil.HandleError(w, "Could not marshal attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal attestations: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ListAttestationsResponse{
httputil2.WriteJson(w, &structs.ListAttestationsResponse{
Data: attsData,
})
}
@@ -120,7 +119,7 @@ func (s *Server) ListAttestationsV2(w http.ResponseWriter, r *http.Request) {
if v >= version.Electra && att.Version() >= version.Electra {
attElectra, ok := att.(*eth.AttestationElectra)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)
return
}
@@ -132,7 +131,7 @@ func (s *Server) ListAttestationsV2(w http.ResponseWriter, r *http.Request) {
} else if v < version.Electra && att.Version() < version.Electra {
attOld, ok := att.(*eth.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert attestation of type %T", att), http.StatusInternalServerError)
return
}
@@ -146,12 +145,12 @@ func (s *Server) ListAttestationsV2(w http.ResponseWriter, r *http.Request) {
attsData, err := json.Marshal(filteredAtts)
if err != nil {
httputil.HandleError(w, "Could not marshal attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal attestations: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(v))
httputil.WriteJson(w, &structs.ListAttestationsResponse{
w.Header().Set(httputil2.VersionHeader, version.String(v))
httputil2.WriteJson(w, &structs.ListAttestationsResponse{
Version: version.String(v),
Data: attsData,
})
@@ -186,21 +185,21 @@ func (s *Server) SubmitAttestations(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
attFailures, failedBroadcasts, err := s.handleAttestations(ctx, req.Data)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
if len(failedBroadcasts) > 0 {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Attestations at index %s could not be broadcasted", strings.Join(failedBroadcasts, ", ")),
http.StatusInternalServerError,
@@ -214,7 +213,7 @@ func (s *Server) SubmitAttestations(w http.ResponseWriter, r *http.Request) {
Message: "One or more attestations failed validation",
Failures: attFailures,
}
httputil.WriteError(w, failuresErr)
httputil2.WriteError(w, failuresErr)
}
}
@@ -224,14 +223,14 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "beacon.SubmitAttestationsV2")
defer span.End()
versionHeader := r.Header.Get(api.VersionHeader)
versionHeader := r.Header.Get(httputil2.VersionHeader)
if versionHeader == "" {
httputil.HandleError(w, api.VersionHeader+" header is required", http.StatusBadRequest)
httputil2.HandleError(w, httputil2.VersionHeader+" header is required", http.StatusBadRequest)
return
}
v, err := version.FromString(versionHeader)
if err != nil {
httputil.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
return
}
@@ -239,10 +238,10 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) {
err = json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
@@ -255,12 +254,12 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) {
attFailures, failedBroadcasts, err = s.handleAttestations(ctx, req.Data)
}
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Failed to handle attestations: %v", err), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Failed to handle attestations: %v", err), http.StatusBadRequest)
return
}
if len(failedBroadcasts) > 0 {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Attestations at index %s could not be broadcasted", strings.Join(failedBroadcasts, ", ")),
http.StatusInternalServerError,
@@ -274,7 +273,7 @@ func (s *Server) SubmitAttestationsV2(w http.ResponseWriter, r *http.Request) {
Message: "One or more attestations failed validation",
Failures: attFailures,
}
httputil.WriteError(w, failuresErr)
httputil2.WriteError(w, failuresErr)
}
}
@@ -441,7 +440,7 @@ func (s *Server) ListVoluntaryExits(w http.ResponseWriter, r *http.Request) {
sourceExits, err := s.VoluntaryExitsPool.PendingExits()
if err != nil {
httputil.HandleError(w, "Could not get exits from the pool: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get exits from the pool: "+err.Error(), http.StatusInternalServerError)
return
}
exits := make([]*structs.SignedVoluntaryExit, len(sourceExits))
@@ -449,7 +448,7 @@ func (s *Server) ListVoluntaryExits(w http.ResponseWriter, r *http.Request) {
exits[i] = structs.SignedExitFromConsensus(e)
}
httputil.WriteJson(w, &structs.ListVoluntaryExitsResponse{Data: exits})
httputil2.WriteJson(w, &structs.ListVoluntaryExitsResponse{Data: exits})
}
// SubmitVoluntaryExit submits a SignedVoluntaryExit object to node's pool
@@ -462,51 +461,51 @@ func (s *Server) SubmitVoluntaryExit(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
exit, err := req.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request exit to consensus exit: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request exit to consensus exit: "+err.Error(), http.StatusBadRequest)
return
}
headState, err := s.ChainInfoFetcher.HeadState(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
epochStart, err := slots.EpochStart(exit.Exit.Epoch)
if err != nil {
httputil.HandleError(w, "Could not get epoch start: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get epoch start: "+err.Error(), http.StatusInternalServerError)
return
}
headState, err = transition.ProcessSlotsIfPossible(ctx, headState, epochStart)
if err != nil {
httputil.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
return
}
val, err := headState.ValidatorAtIndexReadOnly(exit.Exit.ValidatorIndex)
if err != nil {
if errors.Is(err, consensus_types.ErrOutOfBounds) {
httputil.HandleError(w, "Could not get validator: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not get validator: "+err.Error(), http.StatusBadRequest)
return
}
httputil.HandleError(w, "Could not get validator: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator: "+err.Error(), http.StatusInternalServerError)
return
}
if err = blocks.VerifyExitAndSignature(val, headState, exit); err != nil {
httputil.HandleError(w, "Invalid exit: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid exit: "+err.Error(), http.StatusBadRequest)
return
}
s.VoluntaryExitsPool.InsertVoluntaryExit(exit)
if err = s.Broadcaster.Broadcast(ctx, exit); err != nil {
httputil.HandleError(w, "Could not broadcast exit: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not broadcast exit: "+err.Error(), http.StatusInternalServerError)
return
}
}
@@ -520,14 +519,14 @@ func (s *Server) SubmitSyncCommitteeSignatures(w http.ResponseWriter, r *http.Re
err := json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(req.Data) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
@@ -547,7 +546,7 @@ func (s *Server) SubmitSyncCommitteeSignatures(w http.ResponseWriter, r *http.Re
for _, msg := range validMessages {
if rpcerr := s.CoreService.SubmitSyncMessage(ctx, msg); rpcerr != nil {
httputil.HandleError(w, "Could not submit message: "+rpcerr.Err.Error(), core.ErrorReasonToHTTP(rpcerr.Reason))
httputil2.HandleError(w, "Could not submit message: "+rpcerr.Err.Error(), core.ErrorReasonToHTTP(rpcerr.Reason))
return
}
}
@@ -558,7 +557,7 @@ func (s *Server) SubmitSyncCommitteeSignatures(w http.ResponseWriter, r *http.Re
Message: "One or more messages failed validation",
Failures: msgFailures,
}
httputil.WriteError(w, failuresErr)
httputil2.WriteError(w, failuresErr)
}
}
@@ -569,7 +568,7 @@ func (s *Server) SubmitBLSToExecutionChanges(w http.ResponseWriter, r *http.Requ
defer span.End()
st, err := s.ChainInfoFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get head state: %v", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get head state: %v", err), http.StatusInternalServerError)
return
}
var failures []*server.IndexedVerificationFailure
@@ -579,14 +578,14 @@ func (s *Server) SubmitBLSToExecutionChanges(w http.ResponseWriter, r *http.Requ
err = json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(req) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
@@ -632,7 +631,7 @@ func (s *Server) SubmitBLSToExecutionChanges(w http.ResponseWriter, r *http.Requ
Message: "One or more BLSToExecutionChange failed validation",
Failures: failures,
}
httputil.WriteError(w, failuresErr)
httputil2.WriteError(w, failuresErr)
}
}
@@ -691,11 +690,11 @@ func (s *Server) ListBLSToExecutionChanges(w http.ResponseWriter, r *http.Reques
sourceChanges, err := s.BLSChangesPool.PendingBLSToExecChanges()
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get BLS to execution changes: %v", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get BLS to execution changes: %v", err), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.BLSToExecutionChangesPoolResponse{
httputil2.WriteJson(w, &structs.BLSToExecutionChangesPoolResponse{
Data: structs.SignedBLSChangesFromConsensus(sourceChanges),
})
}
@@ -709,7 +708,7 @@ func (s *Server) GetAttesterSlashings(w http.ResponseWriter, r *http.Request) {
headState, err := s.ChainInfoFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
sourceSlashings := s.SlashingsPool.PendingAttesterSlashings(ctx, headState, true /* return unlimited slashings */)
@@ -717,17 +716,17 @@ func (s *Server) GetAttesterSlashings(w http.ResponseWriter, r *http.Request) {
for i, slashing := range sourceSlashings {
as, ok := slashing.(*eth.AttesterSlashing)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T", slashing), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T", slashing), http.StatusInternalServerError)
return
}
slashings[i] = structs.AttesterSlashingFromConsensus(as)
}
attBytes, err := json.Marshal(slashings)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Failed to marshal slashings: %v", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Failed to marshal slashings: %v", err), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.GetAttesterSlashingsResponse{Data: attBytes})
httputil2.WriteJson(w, &structs.GetAttesterSlashingsResponse{Data: attBytes})
}
// GetAttesterSlashingsV2 retrieves attester slashings known by the node but
@@ -739,7 +738,7 @@ func (s *Server) GetAttesterSlashingsV2(w http.ResponseWriter, r *http.Request)
v := slots.ToForkVersion(s.TimeFetcher.CurrentSlot())
headState, err := s.ChainInfoFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
var attStructs []interface{}
@@ -750,14 +749,14 @@ func (s *Server) GetAttesterSlashingsV2(w http.ResponseWriter, r *http.Request)
if v >= version.Electra && slashing.Version() >= version.Electra {
a, ok := slashing.(*eth.AttesterSlashingElectra)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T to an Electra slashing", slashing), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T to an Electra slashing", slashing), http.StatusInternalServerError)
return
}
attStruct = structs.AttesterSlashingElectraFromConsensus(a)
} else if v < version.Electra && slashing.Version() < version.Electra {
a, ok := slashing.(*eth.AttesterSlashing)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T to a Phase0 slashing", slashing), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Unable to convert slashing of type %T to a Phase0 slashing", slashing), http.StatusInternalServerError)
return
}
attStruct = structs.AttesterSlashingFromConsensus(a)
@@ -769,7 +768,7 @@ func (s *Server) GetAttesterSlashingsV2(w http.ResponseWriter, r *http.Request)
attBytes, err := json.Marshal(attStructs)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Failed to marshal slashing: %v", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Failed to marshal slashing: %v", err), http.StatusInternalServerError)
return
}
@@ -777,8 +776,8 @@ func (s *Server) GetAttesterSlashingsV2(w http.ResponseWriter, r *http.Request)
Version: version.String(v),
Data: attBytes,
}
w.Header().Set(api.VersionHeader, version.String(v))
httputil.WriteJson(w, resp)
w.Header().Set(httputil2.VersionHeader, version.String(v))
httputil2.WriteJson(w, resp)
}
// SubmitAttesterSlashings submits an attester slashing object to node's pool and
@@ -791,16 +790,16 @@ func (s *Server) SubmitAttesterSlashings(w http.ResponseWriter, r *http.Request)
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
slashing, err := req.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
return
}
s.submitAttesterSlashing(w, ctx, slashing)
@@ -812,13 +811,13 @@ func (s *Server) SubmitAttesterSlashingsV2(w http.ResponseWriter, r *http.Reques
ctx, span := trace.StartSpan(r.Context(), "beacon.SubmitAttesterSlashingsV2")
defer span.End()
versionHeader := r.Header.Get(api.VersionHeader)
versionHeader := r.Header.Get(httputil2.VersionHeader)
if versionHeader == "" {
httputil.HandleError(w, api.VersionHeader+" header is required", http.StatusBadRequest)
httputil2.HandleError(w, httputil2.VersionHeader+" header is required", http.StatusBadRequest)
}
v, err := version.FromString(versionHeader)
if err != nil {
httputil.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
return
}
@@ -827,16 +826,16 @@ func (s *Server) SubmitAttesterSlashingsV2(w http.ResponseWriter, r *http.Reques
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
slashing, err := req.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
return
}
s.submitAttesterSlashing(w, ctx, slashing)
@@ -845,16 +844,16 @@ func (s *Server) SubmitAttesterSlashingsV2(w http.ResponseWriter, r *http.Reques
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
slashing, err := req.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
return
}
s.submitAttesterSlashing(w, ctx, slashing)
@@ -868,23 +867,23 @@ func (s *Server) submitAttesterSlashing(
) {
headState, err := s.ChainInfoFetcher.HeadState(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
headState, err = transition.ProcessSlotsIfPossible(ctx, headState, slashing.FirstAttestation().GetData().Slot)
if err != nil {
httputil.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
return
}
err = blocks.VerifyAttesterSlashing(ctx, headState, slashing)
if err != nil {
httputil.HandleError(w, "Invalid attester slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid attester slashing: "+err.Error(), http.StatusBadRequest)
return
}
err = s.SlashingsPool.InsertAttesterSlashing(ctx, headState, slashing)
if err != nil {
httputil.HandleError(w, "Could not insert attester slashing into pool: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not insert attester slashing into pool: "+err.Error(), http.StatusInternalServerError)
return
}
// notify events
@@ -896,7 +895,7 @@ func (s *Server) submitAttesterSlashing(
})
if !features.Get().DisableBroadcastSlashings {
if err = s.Broadcaster.Broadcast(ctx, slashing); err != nil {
httputil.HandleError(w, "Could not broadcast slashing object: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not broadcast slashing object: "+err.Error(), http.StatusInternalServerError)
return
}
}
@@ -910,13 +909,13 @@ func (s *Server) GetProposerSlashings(w http.ResponseWriter, r *http.Request) {
headState, err := s.ChainInfoFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
sourceSlashings := s.SlashingsPool.PendingProposerSlashings(ctx, headState, true /* return unlimited slashings */)
slashings := structs.ProposerSlashingsFromConsensus(sourceSlashings)
httputil.WriteJson(w, &structs.GetProposerSlashingsResponse{Data: slashings})
httputil2.WriteJson(w, &structs.GetProposerSlashingsResponse{Data: slashings})
}
// SubmitProposerSlashing submits a proposer slashing object to node's pool and if
@@ -929,37 +928,37 @@ func (s *Server) SubmitProposerSlashing(w http.ResponseWriter, r *http.Request)
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
slashing, err := req.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request slashing to consensus slashing: "+err.Error(), http.StatusBadRequest)
return
}
headState, err := s.ChainInfoFetcher.HeadState(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
headState, err = transition.ProcessSlotsIfPossible(ctx, headState, slashing.Header_1.Header.Slot)
if err != nil {
httputil.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not process slots: "+err.Error(), http.StatusInternalServerError)
return
}
err = blocks.VerifyProposerSlashing(headState, slashing)
if err != nil {
httputil.HandleError(w, "Invalid proposer slashing: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid proposer slashing: "+err.Error(), http.StatusBadRequest)
return
}
err = s.SlashingsPool.InsertProposerSlashing(ctx, headState, slashing)
if err != nil {
httputil.HandleError(w, "Could not insert proposer slashing into pool: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not insert proposer slashing into pool: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -973,7 +972,7 @@ func (s *Server) SubmitProposerSlashing(w http.ResponseWriter, r *http.Request)
if !features.Get().DisableBroadcastSlashings {
if err = s.Broadcaster.Broadcast(ctx, slashing); err != nil {
httputil.HandleError(w, "Could not broadcast slashing object: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not broadcast slashing object: "+err.Error(), http.StatusInternalServerError)
return
}
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
blockchainmock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
@@ -36,7 +36,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/encoding/ssz"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpbv1alpha1 "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
@@ -632,7 +631,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(singleAtt)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -661,7 +660,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(multipleAtts)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -673,7 +672,7 @@ func TestSubmitAttestations(t *testing.T) {
})
t.Run("no body", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -689,7 +688,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString("[]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -705,7 +704,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(invalidAtt)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -728,7 +727,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(singleAttElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -757,7 +756,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(multipleAttsElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -769,7 +768,7 @@ func TestSubmitAttestations(t *testing.T) {
})
t.Run("no body", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -785,7 +784,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString("[]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -801,7 +800,7 @@ func TestSubmitAttestations(t *testing.T) {
_, err := body.WriteString(invalidAttElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -2100,7 +2099,7 @@ func TestSubmitAttesterSlashings(t *testing.T) {
_, err = body.Write(b)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/beacon/pool/attester_electras", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -2164,7 +2163,7 @@ func TestSubmitAttesterSlashings(t *testing.T) {
_, err = body.Write(b)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/beacon/pool/attester_slashings", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -2194,7 +2193,7 @@ func TestSubmitAttesterSlashings(t *testing.T) {
_, err = body.WriteString(invalidAttesterSlashing)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/beacon/pool/attester_slashings", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

View File

@@ -8,6 +8,7 @@ import (
"strconv"
"github.com/ethereum/go-ethereum/common/hexutil"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers"
@@ -18,7 +19,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpbalpha "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -35,7 +35,7 @@ func (s *Server) GetStateRoot(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
@@ -43,10 +43,10 @@ func (s *Server) GetStateRoot(w http.ResponseWriter, r *http.Request) {
if err != nil {
var rootNotFoundErr *lookup.StateRootNotFoundError
if errors.As(err, &rootNotFoundErr) {
httputil.HandleError(w, "State root not found: "+rootNotFoundErr.Error(), http.StatusNotFound)
httputil2.HandleError(w, "State root not found: "+rootNotFoundErr.Error(), http.StatusNotFound)
return
}
httputil.HandleError(w, "Could not get state root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get state root: "+err.Error(), http.StatusInternalServerError)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -56,12 +56,12 @@ func (s *Server) GetStateRoot(w http.ResponseWriter, r *http.Request) {
}
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -73,7 +73,7 @@ func (s *Server) GetStateRoot(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetRandao fetches the RANDAO mix for the requested epoch from the state identified by state_id.
@@ -86,7 +86,7 @@ func (s *Server) GetRandao(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
rawEpoch, e, ok := shared.UintFromQuery(w, r, "epoch", false)
@@ -113,25 +113,25 @@ func (s *Server) GetRandao(w http.ResponseWriter, r *http.Request) {
randaoEpochLowerBound = uint64(stEpoch) - uint64(st.RandaoMixesLength())
}
if epoch > stEpoch || uint64(epoch) < randaoEpochLowerBound+1 {
httputil.HandleError(w, "Epoch is out of range for the randao mixes of the state", http.StatusBadRequest)
httputil2.HandleError(w, "Epoch is out of range for the randao mixes of the state", http.StatusBadRequest)
return
}
idx := epoch % params.BeaconConfig().EpochsPerHistoricalVector
randao, err := st.RandaoMixAtIndex(uint64(idx))
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get randao mix at index %d: %v", idx, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get randao mix at index %d: %v", idx, err), http.StatusInternalServerError)
return
}
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -141,7 +141,7 @@ func (s *Server) GetRandao(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetSyncCommittees retrieves the sync committees for the given epoch.
@@ -152,7 +152,7 @@ func (s *Server) GetSyncCommittees(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
rawEpoch, e, ok := shared.UintFromQuery(w, r, "epoch", false)
@@ -165,7 +165,7 @@ func (s *Server) GetSyncCommittees(w http.ResponseWriter, r *http.Request) {
currentEpoch := slots.ToEpoch(currentSlot)
currentPeriodStartEpoch, err := slots.SyncCommitteePeriodStartEpoch(currentEpoch)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not calculate start period for slot %d: %v", currentSlot, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not calculate start period for slot %d: %v", currentSlot, err), http.StatusInternalServerError)
return
}
@@ -173,11 +173,11 @@ func (s *Server) GetSyncCommittees(w http.ResponseWriter, r *http.Request) {
if rawEpoch != "" {
reqPeriodStartEpoch, err := slots.SyncCommitteePeriodStartEpoch(epoch)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not calculate start period for epoch %d: %v", e, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not calculate start period for epoch %d: %v", e, err), http.StatusInternalServerError)
return
}
if reqPeriodStartEpoch > currentPeriodStartEpoch+params.BeaconConfig().EpochsPerSyncCommitteePeriod {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Could not fetch sync committee too far in the future (requested epoch %d, current epoch %d)", e, currentEpoch),
http.StatusBadRequest,
@@ -208,32 +208,32 @@ func (s *Server) GetSyncCommittees(w http.ResponseWriter, r *http.Request) {
// Get the next sync committee and sync committee indices from the state.
committeeIndices, committee, err = nextCommitteeIndicesFromState(st)
if err != nil {
httputil.HandleError(w, "Could not get next sync committee indices: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get next sync committee indices: "+err.Error(), http.StatusInternalServerError)
return
}
} else {
// Get the current sync committee and sync committee indices from the state.
committeeIndices, committee, err = currentCommitteeIndicesFromState(st)
if err != nil {
httputil.HandleError(w, "Could not get current sync committee indices: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get current sync committee indices: "+err.Error(), http.StatusInternalServerError)
return
}
}
subcommittees, err := extractSyncSubcommittees(st, committee)
if err != nil {
httputil.HandleError(w, "Could not extract sync subcommittees: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not extract sync subcommittees: "+err.Error(), http.StatusInternalServerError)
return
}
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -246,7 +246,7 @@ func (s *Server) GetSyncCommittees(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
func committeeIndicesFromState(st state.BeaconState, committee *ethpbalpha.SyncCommittee) ([]string, *ethpbalpha.SyncCommittee, error) {
@@ -316,7 +316,7 @@ func (s *Server) stateForSyncCommittee(ctx context.Context, w http.ResponseWrite
if req.epoch != nil {
slot, err := slots.EpochStart(*req.epoch)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not calculate start slot for epoch %d: %v", *req.epoch, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not calculate start slot for epoch %d: %v", *req.epoch, err), http.StatusInternalServerError)
return nil, false
}
st, err := s.Stater.State(ctx, []byte(strconv.FormatUint(uint64(slot), 10)))

View File

@@ -12,6 +12,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
dbTest "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing"
@@ -20,7 +21,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpbalpha "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"

View File

@@ -16,7 +16,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositsnapshot"
@@ -36,7 +36,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
@@ -424,13 +423,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -447,13 +446,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Altair), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Altair), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -470,13 +469,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -493,13 +492,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Capella), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Capella), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -516,13 +515,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -539,13 +538,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Electra), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Electra), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -562,13 +561,13 @@ func TestGetBlockSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlockV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Fulu), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Fulu), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1212,13 +1211,13 @@ func TestGetBlindedBlockSSZ(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blinded_blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlindedBlock(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1234,13 +1233,13 @@ func TestGetBlindedBlockSSZ(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blinded_blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlindedBlock(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Altair), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Altair), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1256,13 +1255,13 @@ func TestGetBlindedBlockSSZ(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blinded_blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlindedBlock(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1278,13 +1277,13 @@ func TestGetBlindedBlockSSZ(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blinded_blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlindedBlock(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Capella), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Capella), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1300,13 +1299,13 @@ func TestGetBlindedBlockSSZ(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v1/beacon/blinded_blocks/{block_id}", nil)
request.SetPathValue("block_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBlindedBlock(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := b.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -1331,7 +1330,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.Phase0Block)))
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1353,7 +1352,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.AltairBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1377,7 +1376,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1401,7 +1400,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.CapellaBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1456,7 +1455,7 @@ func TestPublishBlock(t *testing.T) {
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.DenebBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1479,7 +1478,7 @@ func TestPublishBlock(t *testing.T) {
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.ElectraBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1547,7 +1546,7 @@ func TestPublishBlock(t *testing.T) {
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.FuluBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1559,7 +1558,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1572,7 +1571,7 @@ func TestPublishBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1793,8 +1792,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetPhase0().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1823,8 +1822,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetAltair().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1848,8 +1847,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1874,8 +1873,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetCapella().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1900,8 +1899,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetDeneb().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1926,8 +1925,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetElectra().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1952,8 +1951,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetFulu().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1972,8 +1971,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -1993,8 +1992,8 @@ func TestPublishBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -2011,7 +2010,7 @@ func TestPublishBlockSSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte("foo")))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlock(writer, request)
@@ -2038,7 +2037,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.Phase0Block)))
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2060,7 +2059,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.AltairBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2084,7 +2083,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2108,7 +2107,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedCapellaBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2132,7 +2131,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedDenebBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2156,7 +2155,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedElectraBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2226,7 +2225,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedFuluBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2238,7 +2237,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2251,7 +2250,7 @@ func TestPublishBlindedBlock(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2301,8 +2300,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetPhase0().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2331,8 +2330,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetAltair().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2357,8 +2356,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2383,8 +2382,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedCapella().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2409,8 +2408,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedDeneb().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2435,8 +2434,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedElectra().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2461,8 +2460,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedFulu().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2474,7 +2473,7 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2494,8 +2493,8 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2512,7 +2511,7 @@ func TestPublishBlindedBlockSSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte("foo")))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -2539,7 +2538,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.Phase0Block)))
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2561,7 +2560,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.AltairBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2585,7 +2584,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2609,7 +2608,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.CapellaBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2633,7 +2632,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.DenebBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2657,7 +2656,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.ElectraBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2681,7 +2680,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.FuluBlockContents)))
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2693,7 +2692,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2706,7 +2705,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2723,7 +2722,7 @@ func TestPublishBlockV2(t *testing.T) {
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
assert.Equal(t, http.StatusBadRequest, writer.Code)
assert.StringContains(t, api.VersionHeader+" header is required", writer.Body.String())
assert.StringContains(t, httputil.VersionHeader+" header is required", writer.Body.String())
})
t.Run("syncing", func(t *testing.T) {
chainService := &chainMock.ChainService{}
@@ -2735,7 +2734,7 @@ func TestPublishBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte("foo")))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2769,8 +2768,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetPhase0().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2799,8 +2798,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetAltair().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2824,8 +2823,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2850,8 +2849,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetCapella().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2876,8 +2875,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetDeneb().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2902,8 +2901,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetElectra().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2928,8 +2927,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetFulu().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2948,8 +2947,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2969,8 +2968,8 @@ func TestPublishBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -2983,12 +2982,12 @@ func TestPublishBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.CapellaBlock)))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
assert.Equal(t, http.StatusBadRequest, writer.Code)
assert.StringContains(t, api.VersionHeader+" header is required", writer.Body.String())
assert.StringContains(t, httputil.VersionHeader+" header is required", writer.Body.String())
})
t.Run("syncing", func(t *testing.T) {
chainService := &chainMock.ChainService{}
@@ -3000,7 +2999,7 @@ func TestPublishBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte("foo")))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
@@ -3027,7 +3026,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.Phase0Block)))
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3049,7 +3048,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.AltairBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3073,7 +3072,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3097,7 +3096,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedCapellaBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3121,7 +3120,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedDenebBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3145,7 +3144,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedElectraBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3169,7 +3168,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedFuluBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3181,7 +3180,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3194,7 +3193,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedBellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3211,7 +3210,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
assert.Equal(t, http.StatusBadRequest, writer.Code)
assert.StringContains(t, api.VersionHeader+" header is required", writer.Body.String())
assert.StringContains(t, httputil.VersionHeader+" header is required", writer.Body.String())
})
t.Run("syncing", func(t *testing.T) {
chainService := &chainMock.ChainService{}
@@ -3256,8 +3255,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetPhase0().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3286,8 +3285,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetAltair().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3312,8 +3311,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3338,8 +3337,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedCapella().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3364,8 +3363,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedDeneb().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -3390,8 +3389,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedElectra().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -3416,8 +3415,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedFulu().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Fulu))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Fulu))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlock(writer, request)
@@ -3429,7 +3428,7 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BellatrixBlock)))
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3449,8 +3448,8 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
ssz, err := genericBlock.GetBlindedBellatrix().MarshalSSZ()
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader(ssz))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set(api.VersionHeader, version.String(version.Capella))
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
request.Header.Set(httputil.VersionHeader, version.String(version.Capella))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -3463,12 +3462,12 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte(rpctesting.BlindedCapellaBlock)))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlockV2(writer, request)
assert.Equal(t, http.StatusBadRequest, writer.Code)
assert.StringContains(t, api.VersionHeader+" header is required", writer.Body.String())
assert.StringContains(t, httputil.VersionHeader+" header is required", writer.Body.String())
})
t.Run("syncing", func(t *testing.T) {
chainService := &chainMock.ChainService{}
@@ -3480,7 +3479,7 @@ func TestPublishBlindedBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodPost, "http://foo.example", bytes.NewReader([]byte("foo")))
request.Header.Set("Content-Type", api.OctetStreamMediaType)
request.Header.Set("Content-Type", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.PublishBlindedBlockV2(writer, request)
@@ -4697,7 +4696,7 @@ func TestGetDepositSnapshot(t *testing.T) {
})
t.Run("SSZ response", func(t *testing.T) {
writer.Body = &bytes.Buffer{}
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
s.GetDepositSnapshot(writer, request)
assert.Equal(t, http.StatusOK, writer.Code)
resp := &eth.DepositSnapshot{}
@@ -4795,7 +4794,7 @@ func TestGetPendingDeposits(t *testing.T) {
server.GetPendingDeposits(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "electra", rec.Header().Get(api.VersionHeader))
require.Equal(t, "electra", rec.Header().Get(httputil.VersionHeader))
var resp structs.GetPendingDepositsResponse
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
@@ -4818,7 +4817,7 @@ func TestGetPendingDeposits(t *testing.T) {
server.GetPendingDeposits(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "electra", rec.Header().Get(api.VersionHeader))
require.Equal(t, "electra", rec.Header().Get(httputil.VersionHeader))
responseBytes := rec.Body.Bytes()
var recoveredDeposits []*eth.PendingDeposit
@@ -4982,7 +4981,7 @@ func TestGetPendingPartialWithdrawals(t *testing.T) {
server.GetPendingPartialWithdrawals(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "electra", rec.Header().Get(api.VersionHeader))
require.Equal(t, "electra", rec.Header().Get(httputil.VersionHeader))
var resp structs.GetPendingPartialWithdrawalsResponse
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
@@ -5006,7 +5005,7 @@ func TestGetPendingPartialWithdrawals(t *testing.T) {
server.GetPendingPartialWithdrawals(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "electra", rec.Header().Get(api.VersionHeader))
require.Equal(t, "electra", rec.Header().Get(httputil.VersionHeader))
responseBytes := rec.Body.Bytes()
var recoveredWithdrawals []*eth.PendingPartialWithdrawal

View File

@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
@@ -21,7 +22,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/validator"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -33,7 +33,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -44,12 +44,12 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -59,10 +59,10 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
err = json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
}
@@ -91,7 +91,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
return
}
@@ -107,7 +107,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
for i, val := range readOnlyVals {
valStatus, err := helpers.ValidatorSubStatus(val, epoch)
if err != nil {
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
return
}
id := primitives.ValidatorIndex(i)
@@ -116,7 +116,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
}
balance, err := st.BalanceAtIndex(id)
if err != nil {
httputil.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
return
}
containers[i] = valContainerFromReadOnlyVal(val, id, balance, valStatus)
@@ -126,7 +126,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
return
}
@@ -134,7 +134,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
for _, ss := range statuses {
ok, vs := validator.StatusFromString(ss)
if !ok {
httputil.HandleError(w, "Invalid status "+ss, http.StatusBadRequest)
httputil2.HandleError(w, "Invalid status "+ss, http.StatusBadRequest)
return
}
filteredStatuses[vs] = true
@@ -143,12 +143,12 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
for i, val := range readOnlyVals {
valStatus, err := helpers.ValidatorStatus(val, epoch)
if err != nil {
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
return
}
valSubStatus, err := helpers.ValidatorSubStatus(val, epoch)
if err != nil {
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
return
}
if filteredStatuses[valStatus] || filteredStatuses[valSubStatus] {
@@ -159,7 +159,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
}
balance, err := st.BalanceAtIndex(id)
if err != nil {
httputil.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
return
}
container = valContainerFromReadOnlyVal(val, id, balance, valSubStatus)
@@ -172,7 +172,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetValidator returns a validator specified by state and id or public key along with status and balance.
@@ -182,12 +182,12 @@ func (s *Server) GetValidator(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
valId := r.PathValue("validator_id")
if valId == "" {
httputil.HandleError(w, "validator_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "validator_id is required in URL params", http.StatusBadRequest)
return
}
@@ -205,29 +205,29 @@ func (s *Server) GetValidator(w http.ResponseWriter, r *http.Request) {
return
}
if len(ids) == 0 || len(readOnlyVals) == 0 {
httputil.HandleError(w, "No validator returned for the given ID", http.StatusInternalServerError)
httputil2.HandleError(w, "No validator returned for the given ID", http.StatusInternalServerError)
return
}
valSubStatus, err := helpers.ValidatorSubStatus(readOnlyVals[0], slots.ToEpoch(st.Slot()))
if err != nil {
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
return
}
bal, err := st.BalanceAtIndex(ids[0])
if err != nil {
httputil.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator balance: "+err.Error(), http.StatusInternalServerError)
return
}
container := valContainerFromReadOnlyVal(readOnlyVals[0], ids[0], bal, valSubStatus)
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -237,7 +237,7 @@ func (s *Server) GetValidator(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetValidatorBalances returns a filterable list of validator balances.
@@ -247,7 +247,7 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -258,12 +258,12 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -275,10 +275,10 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
err = json.NewDecoder(r.Body).Decode(&rawIds)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
}
@@ -294,7 +294,7 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
return
}
@@ -323,7 +323,7 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetValidatorIdentities returns a filterable list of validators identities.
@@ -333,7 +333,7 @@ func (s *Server) GetValidatorIdentities(w http.ResponseWriter, r *http.Request)
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
st, err := s.Stater.State(ctx, []byte(stateId))
@@ -346,10 +346,10 @@ func (s *Server) GetValidatorIdentities(w http.ResponseWriter, r *http.Request)
err = json.NewDecoder(r.Body).Decode(&rawIds)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
@@ -358,7 +358,7 @@ func (s *Server) GetValidatorIdentities(w http.ResponseWriter, r *http.Request)
return
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
s.getValidatorIdentitiesSSZ(w, st, rawIds, ids)
} else {
s.getValidatorIdentitiesJSON(r.Context(), w, st, stateId, rawIds, ids)
@@ -368,7 +368,7 @@ func (s *Server) GetValidatorIdentities(w http.ResponseWriter, r *http.Request)
func (s *Server) getValidatorIdentitiesSSZ(w http.ResponseWriter, st state.BeaconState, rawIds []string, ids []primitives.ValidatorIndex) {
// return no data if all IDs are ignored
if len(rawIds) > 0 && len(ids) == 0 {
httputil.WriteSsz(w, []byte{})
httputil2.WriteSsz(w, []byte{})
return
}
@@ -401,12 +401,12 @@ func (s *Server) getValidatorIdentitiesSSZ(w http.ResponseWriter, st state.Beaco
for i, vi := range identities {
ssz, err := vi.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal validator identity to SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal validator identity to SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
copy(resp[i*sszLen:(i+1)*sszLen], ssz)
}
httputil.WriteSsz(w, resp)
httputil2.WriteSsz(w, resp)
}
func (s *Server) getValidatorIdentitiesJSON(
@@ -419,12 +419,12 @@ func (s *Server) getValidatorIdentitiesJSON(
) {
isOptimistic, err := helpers.IsOptimistic(ctx, []byte(stateId), s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -436,7 +436,7 @@ func (s *Server) getValidatorIdentitiesJSON(
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
return
}
@@ -469,7 +469,7 @@ func (s *Server) getValidatorIdentitiesJSON(
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// decodeIds takes in a list of validator ID strings (as either a pubkey or a validator index)
@@ -481,7 +481,7 @@ func decodeIds(w http.ResponseWriter, st state.BeaconState, rawIds []string, ign
pubkey, err := hexutil.Decode(rawId)
if err == nil {
if len(pubkey) != fieldparams.BLSPubkeyLength {
httputil.HandleError(w, fmt.Sprintf("Pubkey length is %d instead of %d", len(pubkey), fieldparams.BLSPubkeyLength), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Pubkey length is %d instead of %d", len(pubkey), fieldparams.BLSPubkeyLength), http.StatusBadRequest)
return nil, false
}
valIndex, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubkey))
@@ -489,7 +489,7 @@ func decodeIds(w http.ResponseWriter, st state.BeaconState, rawIds []string, ign
if ignoreUnknown {
continue
}
httputil.HandleError(w, fmt.Sprintf("Unknown validator: %s", hexutil.Encode(pubkey)), http.StatusNotFound)
httputil2.HandleError(w, fmt.Sprintf("Unknown validator: %s", hexutil.Encode(pubkey)), http.StatusNotFound)
return nil, false
}
ids = append(ids, valIndex)
@@ -498,14 +498,14 @@ func decodeIds(w http.ResponseWriter, st state.BeaconState, rawIds []string, ign
index, err := strconv.ParseUint(rawId, 10, 64)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Invalid validator index %s", rawId), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Invalid validator index %s", rawId), http.StatusBadRequest)
return nil, false
}
if index >= numVals {
if ignoreUnknown {
continue
}
httputil.HandleError(w, fmt.Sprintf("Invalid validator index %d", index), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Invalid validator index %d", index), http.StatusBadRequest)
return nil, false
}
ids = append(ids, primitives.ValidatorIndex(index))
@@ -523,13 +523,13 @@ func valsFromIds(w http.ResponseWriter, st state.BeaconState, ids []primitives.V
for _, id := range ids {
val, err := st.ValidatorAtIndex(id)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get validator at index %d: %s", id, err.Error()), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get validator at index %d: %s", id, err.Error()), http.StatusInternalServerError)
return nil, false
}
readOnlyVal, err := statenative.NewValidator(val)
if err != nil {
httputil.HandleError(w, "Could not convert validator: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not convert validator: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
vals = append(vals, readOnlyVal)

View File

@@ -11,7 +11,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
@@ -20,7 +20,6 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
@@ -1442,7 +1441,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString("[]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -1466,7 +1465,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString("[\"0\",\"1\"]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -1494,7 +1493,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString(fmt.Sprintf("[\"%s\",\"%s\"]", hexPubkey1, hexPubkey2))
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -1521,7 +1520,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString(fmt.Sprintf("[\"%s\",\"1\"]", hexPubkey))
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -1548,7 +1547,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString(fmt.Sprintf("[\"%s\",\"%s\"]", hexPubkey, hexutil.Encode([]byte(strings.Repeat("x", fieldparams.BLSPubkeyLength)))))
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -1572,7 +1571,7 @@ func TestGetValidatorIdentities(t *testing.T) {
_, err := body.WriteString("[\"1\",\"99999\"]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com/eth/v1/beacon/states/{state_id}/validator_identities", &body)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
request.SetPathValue("state_id", "head")
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

View File

@@ -9,7 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/blob",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/rpc/core:go_default_library",
@@ -19,7 +19,6 @@ go_library(
"//consensus-types/blocks:go_default_library",
"//consensus-types/primitives:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//runtime/version:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
@@ -31,7 +30,7 @@ go_test(
srcs = ["handlers_test.go"],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/db/filesystem:go_default_library",
@@ -41,7 +40,6 @@ go_test(
"//beacon-chain/verification:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core"
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
@@ -17,7 +17,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
@@ -28,7 +27,7 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
indices, err := parseIndices(r.URL, s.TimeFetcher.CurrentSlot())
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
segments := strings.Split(r.URL.Path, "/")
@@ -39,49 +38,49 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
code := core.ErrorReasonToHTTP(rpcErr.Reason)
switch code {
case http.StatusBadRequest:
httputil.HandleError(w, "Invalid block ID: "+rpcErr.Err.Error(), code)
httputil2.HandleError(w, "Invalid block ID: "+rpcErr.Err.Error(), code)
return
case http.StatusNotFound:
httputil.HandleError(w, "Block not found: "+rpcErr.Err.Error(), code)
httputil2.HandleError(w, "Block not found: "+rpcErr.Err.Error(), code)
return
case http.StatusInternalServerError:
httputil.HandleError(w, "Internal server error: "+rpcErr.Err.Error(), code)
httputil2.HandleError(w, "Internal server error: "+rpcErr.Err.Error(), code)
return
default:
httputil.HandleError(w, rpcErr.Err.Error(), code)
httputil2.HandleError(w, rpcErr.Err.Error(), code)
return
}
}
blk, err := s.Blocker.Block(ctx, []byte(blockId))
if err != nil {
httputil.HandleError(w, "Could not fetch block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not fetch block: "+err.Error(), http.StatusInternalServerError)
return
}
if blk == nil {
httputil.HandleError(w, "Block not found", http.StatusNotFound)
httputil2.HandleError(w, "Block not found", http.StatusNotFound)
return
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
sszResp, err := buildSidecarsSSZResponse(verifiedBlobs)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(blk.Version()))
httputil.WriteSsz(w, sszResp)
w.Header().Set(httputil2.VersionHeader, version.String(blk.Version()))
httputil2.WriteSsz(w, sszResp)
return
}
blkRoot, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not hash block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not hash block: "+err.Error(), http.StatusInternalServerError)
return
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, blkRoot)
if err != nil {
httputil.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -92,8 +91,8 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: isOptimistic,
Finalized: s.FinalizationFetcher.IsFinalized(ctx, blkRoot),
}
w.Header().Set(api.VersionHeader, version.String(blk.Version()))
httputil.WriteJson(w, resp)
w.Header().Set(httputil2.VersionHeader, version.String(blk.Version()))
httputil2.WriteJson(w, resp)
}
// parseIndices filters out invalid and duplicate blob indices

View File

@@ -14,7 +14,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
mockChain "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db/filesystem"
@@ -24,7 +24,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/verification"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
@@ -223,7 +222,7 @@ func TestBlobs(t *testing.T) {
}
s.Blobs(writer, request)
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(httputil.VersionHeader))
assert.Equal(t, http.StatusOK, writer.Code)
resp := &structs.SidecarsResponse{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
@@ -377,7 +376,7 @@ func TestBlobs(t *testing.T) {
BlobStorage: bs,
}
s.Blobs(writer, request)
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(httputil.VersionHeader))
assert.Equal(t, http.StatusOK, writer.Code)
require.Equal(t, len(writer.Body.Bytes()), fieldparams.BlobSidecarSize) // size of each sidecar
// can directly unmarshal to sidecar since there's only 1
@@ -446,7 +445,7 @@ func TestBlobs_Electra(t *testing.T) {
}
s.Blobs(writer, request)
assert.Equal(t, version.String(version.Electra), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Electra), writer.Header().Get(httputil.VersionHeader))
assert.Equal(t, http.StatusOK, writer.Code)
resp := &structs.SidecarsResponse{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
@@ -478,7 +477,7 @@ func TestBlobs_Electra(t *testing.T) {
}
s.Blobs(writer, request)
assert.Equal(t, version.String(version.Electra), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Electra), writer.Header().Get(httputil.VersionHeader))
assert.Equal(t, http.StatusOK, writer.Code)
resp := &structs.SidecarsResponse{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))

View File

@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/builder",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
@@ -16,7 +17,6 @@ go_library(
"//beacon-chain/rpc/lookup:go_default_library",
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library",
"//network/httputil:go_default_library",
"//proto/engine/v1:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
@@ -29,6 +29,7 @@ go_test(
srcs = ["handlers_test.go"],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/rpc/testutil:go_default_library",
@@ -36,7 +37,6 @@ go_test(
"//config/params:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",

View File

@@ -7,12 +7,12 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)

View File

@@ -9,6 +9,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil"
@@ -16,7 +17,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"

View File

@@ -6,11 +6,11 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/config",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//config/params:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/forks:go_default_library",
"//network/httputil:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
],
)

View File

@@ -8,11 +8,11 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/forks"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
)
// GetDepositContract retrieves deposit contract address and genesis fork version.
@@ -20,7 +20,7 @@ func GetDepositContract(w http.ResponseWriter, r *http.Request) {
_, span := trace.StartSpan(r.Context(), "config.GetDepositContract")
defer span.End()
httputil.WriteJson(w, &structs.GetDepositContractResponse{
httputil2.WriteJson(w, &structs.GetDepositContractResponse{
Data: &structs.DepositContractData{
ChainId: strconv.FormatUint(params.BeaconConfig().DepositChainID, 10),
Address: params.BeaconConfig().DepositContractAddress,
@@ -35,7 +35,7 @@ func GetForkSchedule(w http.ResponseWriter, r *http.Request) {
schedule := params.BeaconConfig().ForkVersionSchedule
if len(schedule) == 0 {
httputil.WriteJson(w, &structs.GetForkScheduleResponse{
httputil2.WriteJson(w, &structs.GetForkScheduleResponse{
Data: make([]*structs.Fork, 0),
})
return
@@ -59,7 +59,7 @@ func GetForkSchedule(w http.ResponseWriter, r *http.Request) {
}
}
httputil.WriteJson(w, &structs.GetForkScheduleResponse{
httputil2.WriteJson(w, &structs.GetForkScheduleResponse{
Data: chainForks,
})
}
@@ -74,10 +74,10 @@ func GetSpec(w http.ResponseWriter, r *http.Request) {
data, err := prepareConfigSpec()
if err != nil {
httputil.HandleError(w, "Could not prepare config spec: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not prepare config spec: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.GetSpecResponse{Data: data})
httputil2.WriteJson(w, &structs.GetSpecResponse{Data: data})
}
func prepareConfigSpec() (map[string]string, error) {

View File

@@ -9,7 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/debug",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/db:go_default_library",
@@ -17,7 +17,6 @@ go_library(
"//beacon-chain/rpc/eth/shared:go_default_library",
"//beacon-chain/rpc/lookup:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//runtime/version:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
],
@@ -28,7 +27,7 @@ go_test(
srcs = ["handlers_test.go"],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/db/testing:go_default_library",

View File

@@ -7,12 +7,11 @@ import (
"net/http"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
@@ -25,11 +24,11 @@ func (s *Server) GetBeaconStateV2(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
if httputil.RespondWithSsz(r) {
if httputil2.RespondWithSsz(r) {
s.getBeaconStateSSZV2(ctx, w, []byte(stateId))
} else {
s.getBeaconStateV2(ctx, w, []byte(stateId))
@@ -46,12 +45,12 @@ func (s *Server) getBeaconStateV2(ctx context.Context, w http.ResponseWriter, id
isOptimistic, err := helpers.IsOptimistic(ctx, id, s.OptimisticModeFetcher, s.Stater, s.ChainInfoFetcher, s.BeaconDB)
if err != nil {
httputil.HandleError(w, "Could not check if state is optimistic: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if state is optimistic: "+err.Error(), http.StatusInternalServerError)
return
}
blockRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not calculate root of latest block header: "+err.Error(), http.StatusInternalServerError)
return
}
isFinalized := s.FinalizationFetcher.IsFinalized(ctx, blockRoot)
@@ -61,53 +60,53 @@ func (s *Server) getBeaconStateV2(ctx context.Context, w http.ResponseWriter, id
case version.Phase0:
respSt, err = structs.BeaconStateFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Altair:
respSt, err = structs.BeaconStateAltairFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Bellatrix:
respSt, err = structs.BeaconStateBellatrixFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Capella:
respSt, err = structs.BeaconStateCapellaFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Deneb:
respSt, err = structs.BeaconStateDenebFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Electra:
respSt, err = structs.BeaconStateElectraFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
case version.Fulu:
respSt, err = structs.BeaconStateFuluFromConsensus(st)
if err != nil {
httputil.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errMsgStateFromConsensus+": "+err.Error(), http.StatusInternalServerError)
return
}
default:
httputil.HandleError(w, "Unsupported state version", http.StatusInternalServerError)
httputil2.HandleError(w, "Unsupported state version", http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(respSt)
if err != nil {
httputil.HandleError(w, "Could not marshal state into JSON: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal state into JSON: "+err.Error(), http.StatusInternalServerError)
return
}
ver := version.String(st.Version())
@@ -117,8 +116,8 @@ func (s *Server) getBeaconStateV2(ctx context.Context, w http.ResponseWriter, id
Finalized: isFinalized,
Data: jsonBytes,
}
w.Header().Set(api.VersionHeader, ver)
httputil.WriteJson(w, resp)
w.Header().Set(httputil2.VersionHeader, ver)
httputil2.WriteJson(w, resp)
}
// getBeaconStateSSZV2 returns the SSZ-serialized version of the full beacon state object for given state ID.
@@ -130,11 +129,11 @@ func (s *Server) getBeaconStateSSZV2(ctx context.Context, w http.ResponseWriter,
}
sszState, err := st.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal state into SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal state into SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set(api.VersionHeader, version.String(st.Version()))
httputil.WriteSsz(w, sszState)
w.Header().Set(httputil2.VersionHeader, version.String(st.Version()))
httputil2.WriteSsz(w, sszState)
}
// GetForkChoiceHeadsV2 retrieves the leaves of the current fork choice tree.
@@ -149,7 +148,7 @@ func (s *Server) GetForkChoiceHeadsV2(w http.ResponseWriter, r *http.Request) {
for i := range headRoots {
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, headRoots[i])
if err != nil {
httputil.HandleError(w, "Could not check if head is optimistic: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check if head is optimistic: "+err.Error(), http.StatusInternalServerError)
return
}
resp.Data[i] = &structs.ForkChoiceHead{
@@ -159,7 +158,7 @@ func (s *Server) GetForkChoiceHeadsV2(w http.ResponseWriter, r *http.Request) {
}
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetForkChoice returns a dump fork choice store.
@@ -169,7 +168,7 @@ func (s *Server) GetForkChoice(w http.ResponseWriter, r *http.Request) {
dump, err := s.ForkchoiceFetcher.ForkChoiceDump(ctx)
if err != nil {
httputil.HandleError(w, "Could not get forkchoice dump: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get forkchoice dump: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -206,5 +205,5 @@ func (s *Server) GetForkChoice(w http.ResponseWriter, r *http.Request) {
HeadRoot: hexutil.Encode(dump.HeadRoot),
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}

View File

@@ -9,7 +9,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
blockchainmock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
dbtest "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing"
@@ -311,13 +311,13 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Phase0), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := fakeState.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -335,13 +335,13 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Altair), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Altair), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := fakeState.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -359,13 +359,13 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Bellatrix), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := fakeState.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -383,13 +383,13 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Capella), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Capella), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := fakeState.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
@@ -407,13 +407,13 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "http://example.com/eth/v2/debug/beacon/states/{state_id}", nil)
request.SetPathValue("state_id", "head")
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.GetBeaconStateV2(writer, request)
require.Equal(t, http.StatusOK, writer.Code)
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(api.VersionHeader))
assert.Equal(t, version.String(version.Deneb), writer.Header().Get(httputil.VersionHeader))
sszExpected, err := fakeState.MarshalSSZ()
require.NoError(t, err)
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())

View File

@@ -10,7 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/events",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/cache:go_default_library",
@@ -25,7 +25,6 @@ go_library(
"//consensus-types/payload-attribute:go_default_library",
"//consensus-types/primitives:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -15,7 +15,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/operation"
@@ -28,7 +28,6 @@ import (
payloadattribute "github.com/prysmaticlabs/prysm/v5/consensus-types/payload-attribute"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
engine "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -193,7 +192,7 @@ func (s *Server) StreamEvents(w http.ResponseWriter, r *http.Request) {
buffSize = DefaultEventFeedDepth
}
api.SetSSEHeaders(w)
httputil.SetSSEHeaders(w)
sw := newStreamingResponseController(w, timeout)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

View File

@@ -9,7 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/light-client",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/core/light-client:go_default_library",
@@ -23,7 +23,6 @@ go_library(
"//encoding/bytesutil:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/forks:go_default_library",
"//network/httputil:go_default_library",
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
lightclient "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/light-client"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing"
@@ -20,7 +20,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/forks"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -28,7 +27,7 @@ import (
// GetLightClientBootstrap - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/bootstrap.yaml
func (s *Server) GetLightClientBootstrap(w http.ResponseWriter, req *http.Request) {
if !features.Get().EnableLightClient {
httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
httputil2.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
return
}
@@ -39,48 +38,48 @@ func (s *Server) GetLightClientBootstrap(w http.ResponseWriter, req *http.Reques
// Get the block
blockRootParam, err := hexutil.Decode(req.PathValue("block_root"))
if err != nil {
httputil.HandleError(w, "Invalid block root: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid block root: "+err.Error(), http.StatusBadRequest)
return
}
blockRoot := bytesutil.ToBytes32(blockRootParam)
bootstrap, err := s.BeaconDB.LightClientBootstrap(ctx, blockRoot[:])
if err != nil {
httputil.HandleError(w, "Could not get light client bootstrap: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get light client bootstrap: "+err.Error(), http.StatusInternalServerError)
return
}
if bootstrap == nil {
httputil.HandleError(w, "Light client bootstrap not found", http.StatusNotFound)
httputil2.HandleError(w, "Light client bootstrap not found", http.StatusNotFound)
return
}
w.Header().Set(api.VersionHeader, version.String(bootstrap.Version()))
w.Header().Set(httputil2.VersionHeader, version.String(bootstrap.Version()))
if httputil.RespondWithSsz(req) {
if httputil2.RespondWithSsz(req) {
ssz, err := bootstrap.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal bootstrap to SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal bootstrap to SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, ssz)
httputil2.WriteSsz(w, ssz)
} else {
data, err := structs.LightClientBootstrapFromConsensus(bootstrap)
if err != nil {
httputil.HandleError(w, "Could not marshal bootstrap to JSON: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal bootstrap to JSON: "+err.Error(), http.StatusInternalServerError)
return
}
response := &structs.LightClientBootstrapResponse{
Version: version.String(bootstrap.Version()),
Data: data,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
}
// GetLightClientUpdatesByRange - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/updates.yaml
func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.Request) {
if !features.Get().EnableLightClient {
httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
httputil2.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
return
}
@@ -93,7 +92,7 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
if !gotCount {
return
} else if count == 0 {
httputil.HandleError(w, fmt.Sprintf("Got invalid 'count' query variable '%d': count must be greater than 0", count), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Got invalid 'count' query variable '%d': count must be greater than 0", count), http.StatusBadRequest)
return
}
@@ -111,16 +110,16 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
// get updates
updatesMap, err := s.BeaconDB.LightClientUpdates(ctx, startPeriod, endPeriod)
if err != nil {
httputil.HandleError(w, "Could not get light client updates from DB: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get light client updates from DB: "+err.Error(), http.StatusInternalServerError)
return
}
if httputil.RespondWithSsz(req) {
if httputil2.RespondWithSsz(req) {
w.Header().Set("Content-Type", "application/octet-stream")
for i := startPeriod; i <= endPeriod; i++ {
if ctx.Err() != nil {
httputil.HandleError(w, "Context error: "+ctx.Err().Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Context error: "+ctx.Err().Error(), http.StatusInternalServerError)
}
update, ok := updatesMap[i]
@@ -133,31 +132,31 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
updateEpoch := slots.ToEpoch(updateSlot)
updateFork, err := forks.Fork(updateEpoch)
if err != nil {
httputil.HandleError(w, "Could not get fork Version: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get fork Version: "+err.Error(), http.StatusInternalServerError)
return
}
forkDigest, err := signing.ComputeForkDigest(updateFork.CurrentVersion, params.BeaconConfig().GenesisValidatorsRoot[:])
if err != nil {
httputil.HandleError(w, "Could not compute fork digest: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not compute fork digest: "+err.Error(), http.StatusInternalServerError)
return
}
updateSSZ, err := update.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal update to SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal update to SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
var chunkLength []byte
chunkLength = ssz.MarshalUint64(chunkLength, uint64(len(updateSSZ)+4))
if _, err := w.Write(chunkLength); err != nil {
httputil.HandleError(w, "Could not write chunk length: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not write chunk length: "+err.Error(), http.StatusInternalServerError)
}
if _, err := w.Write(forkDigest[:]); err != nil {
httputil.HandleError(w, "Could not write fork digest: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not write fork digest: "+err.Error(), http.StatusInternalServerError)
}
if _, err := w.Write(updateSSZ); err != nil {
httputil.HandleError(w, "Could not write update SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not write update SSZ: "+err.Error(), http.StatusInternalServerError)
}
}
} else {
@@ -165,7 +164,7 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
for i := startPeriod; i <= endPeriod; i++ {
if ctx.Err() != nil {
httputil.HandleError(w, "Context error: "+ctx.Err().Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Context error: "+ctx.Err().Error(), http.StatusInternalServerError)
}
update, ok := updatesMap[i]
@@ -176,7 +175,7 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
updateJson, err := structs.LightClientUpdateFromConsensus(update)
if err != nil {
httputil.HandleError(w, "Could not convert light client update: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not convert light client update: "+err.Error(), http.StatusInternalServerError)
return
}
updateResponse := &structs.LightClientUpdateResponse{
@@ -186,14 +185,14 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
updates = append(updates, updateResponse)
}
httputil.WriteJson(w, updates)
httputil2.WriteJson(w, updates)
}
}
// GetLightClientFinalityUpdate - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/finality_update.yaml
func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.Request) {
if !features.Get().EnableLightClient {
httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
httputil2.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
return
}
@@ -211,7 +210,7 @@ func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.R
st, err := s.Stater.StateBySlot(ctx, block.Block().Slot())
if err != nil {
httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -223,14 +222,14 @@ func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.R
attestedSlot := attestedBlock.Block().Slot()
attestedState, err := s.Stater.StateBySlot(ctx, attestedSlot)
if err != nil {
httputil.HandleError(w, "Could not get attested state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get attested state: "+err.Error(), http.StatusInternalServerError)
return
}
var finalizedBlock interfaces.ReadOnlySignedBeaconBlock
finalizedCheckpoint := attestedState.FinalizedCheckpoint()
if finalizedCheckpoint == nil {
httputil.HandleError(w, "Attested state does not have a finalized checkpoint", http.StatusInternalServerError)
httputil2.HandleError(w, "Attested state does not have a finalized checkpoint", http.StatusInternalServerError)
return
}
finalizedRoot := bytesutil.ToBytes32(finalizedCheckpoint.Root)
@@ -241,35 +240,35 @@ func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.R
update, err := lightclient.NewLightClientFinalityUpdateFromBeaconState(ctx, s.ChainInfoFetcher.CurrentSlot(), st, block, attestedState, attestedBlock, finalizedBlock)
if err != nil {
httputil.HandleError(w, "Could not get light client finality update: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get light client finality update: "+err.Error(), http.StatusInternalServerError)
return
}
if httputil.RespondWithSsz(req) {
if httputil2.RespondWithSsz(req) {
ssz, err := update.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal finality update to SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal finality update to SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, ssz)
httputil2.WriteSsz(w, ssz)
} else {
updateStruct, err := structs.LightClientFinalityUpdateFromConsensus(update)
if err != nil {
httputil.HandleError(w, "Could not convert light client finality update to API struct: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not convert light client finality update to API struct: "+err.Error(), http.StatusInternalServerError)
return
}
response := &structs.LightClientFinalityUpdateResponse{
Version: version.String(attestedState.Version()),
Data: updateStruct,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
}
// GetLightClientOptimisticUpdate - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/optimistic_update.yaml
func (s *Server) GetLightClientOptimisticUpdate(w http.ResponseWriter, req *http.Request) {
if !features.Get().EnableLightClient {
httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
httputil2.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound)
return
}
@@ -282,50 +281,50 @@ func (s *Server) GetLightClientOptimisticUpdate(w http.ResponseWriter, req *http
}
st, err := s.Stater.StateBySlot(ctx, block.Block().Slot())
if err != nil {
httputil.HandleError(w, "could not get state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "could not get state: "+err.Error(), http.StatusInternalServerError)
return
}
attestedRoot := block.Block().ParentRoot()
attestedBlock, err := s.Blocker.Block(ctx, attestedRoot[:])
if err != nil {
httputil.HandleError(w, "Could not get attested block: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get attested block: "+err.Error(), http.StatusInternalServerError)
return
}
if attestedBlock == nil {
httputil.HandleError(w, "Attested block is nil", http.StatusInternalServerError)
httputil2.HandleError(w, "Attested block is nil", http.StatusInternalServerError)
return
}
attestedSlot := attestedBlock.Block().Slot()
attestedState, err := s.Stater.StateBySlot(ctx, attestedSlot)
if err != nil {
httputil.HandleError(w, "Could not get attested state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get attested state: "+err.Error(), http.StatusInternalServerError)
return
}
update, err := lightclient.NewLightClientOptimisticUpdateFromBeaconState(ctx, s.ChainInfoFetcher.CurrentSlot(), st, block, attestedState, attestedBlock)
if err != nil {
httputil.HandleError(w, "Could not get light client optimistic update: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get light client optimistic update: "+err.Error(), http.StatusInternalServerError)
return
}
if httputil.RespondWithSsz(req) {
if httputil2.RespondWithSsz(req) {
ssz, err := update.MarshalSSZ()
if err != nil {
httputil.HandleError(w, "Could not marshal optimistic update to SSZ: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal optimistic update to SSZ: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, ssz)
httputil2.WriteSsz(w, ssz)
} else {
updateStruct, err := structs.LightClientOptimisticUpdateFromConsensus(update)
if err != nil {
httputil.HandleError(w, "Could not convert light client optimistic update to API struct: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not convert light client optimistic update to API struct: "+err.Error(), http.StatusInternalServerError)
return
}
response := &structs.LightClientOptimisticUpdateResponse{
Version: version.String(attestedState.Version()),
Data: updateStruct,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
}

View File

@@ -10,6 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/node",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/db:go_default_library",
@@ -20,7 +21,6 @@ go_library(
"//beacon-chain/rpc/eth/shared:go_default_library",
"//beacon-chain/sync:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/migration:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
@@ -40,6 +40,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/p2p:go_default_library",
@@ -49,7 +50,6 @@ go_test(
"//beacon-chain/sync/initial-sync/testing:go_default_library",
"//consensus-types/primitives:go_default_library",
"//consensus-types/wrapper:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",

View File

@@ -7,11 +7,11 @@ import (
"strconv"
"github.com/ethereum/go-ethereum/common/hexutil"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
@@ -33,7 +33,7 @@ func (s *Server) GetSyncStatus(w http.ResponseWriter, r *http.Request) {
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -47,7 +47,7 @@ func (s *Server) GetSyncStatus(w http.ResponseWriter, r *http.Request) {
ElOffline: !s.ExecutionChainInfoFetcher.ExecutionClientConnected(),
},
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetIdentity retrieves data about the node's network presence.
@@ -63,7 +63,7 @@ func (s *Server) GetIdentity(w http.ResponseWriter, r *http.Request) {
}
sourceDisc, err := s.PeerManager.DiscoveryAddresses()
if err != nil {
httputil.HandleError(w, "Could not obtain discovery address: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain discovery address: "+err.Error(), http.StatusInternalServerError)
return
}
discoveryAddresses := make([]string, len(sourceDisc))
@@ -72,7 +72,7 @@ func (s *Server) GetIdentity(w http.ResponseWriter, r *http.Request) {
}
serializedEnr, err := p2p.SerializeENR(s.PeerManager.ENR())
if err != nil {
httputil.HandleError(w, "Could not obtain enr: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain enr: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -88,7 +88,7 @@ func (s *Server) GetIdentity(w http.ResponseWriter, r *http.Request) {
},
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetVersion requests that the beacon node identify information about its implementation in a
@@ -103,7 +103,7 @@ func (*Server) GetVersion(w http.ResponseWriter, r *http.Request) {
Version: v,
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetHealth returns node health status in http status codes. Useful for load balancers.
@@ -115,13 +115,13 @@ func (s *Server) GetHealth(w http.ResponseWriter, r *http.Request) {
// lint:ignore uintcast -- custom syncing status being outside of range is harmless
intSyncingStatus := int(syncingStatus)
if !ok || (rawSyncingStatus != "" && http.StatusText(intSyncingStatus) == "") {
httputil.HandleError(w, "syncing_status is not a valid HTTP status code", http.StatusBadRequest)
httputil2.HandleError(w, "syncing_status is not a valid HTTP status code", http.StatusBadRequest)
return
}
optimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
}
if s.SyncChecker.Synced() && !optimistic {
return

View File

@@ -7,12 +7,12 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers/peerdata"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/proto/migration"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
@@ -24,54 +24,54 @@ func (s *Server) GetPeer(w http.ResponseWriter, r *http.Request) {
rawId := r.PathValue("peer_id")
if rawId == "" {
httputil.HandleError(w, "peer_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "peer_id is required in URL params", http.StatusBadRequest)
return
}
peerStatus := s.PeersFetcher.Peers()
id, err := peer.Decode(rawId)
if err != nil {
httputil.HandleError(w, "Invalid peer ID: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid peer ID: "+err.Error(), http.StatusBadRequest)
return
}
enr, err := peerStatus.ENR(id)
if err != nil {
if errors.Is(err, peerdata.ErrPeerUnknown) {
httputil.HandleError(w, "Peer not found: "+err.Error(), http.StatusNotFound)
httputil2.HandleError(w, "Peer not found: "+err.Error(), http.StatusNotFound)
return
}
httputil.HandleError(w, "Could not obtain ENR: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain ENR: "+err.Error(), http.StatusInternalServerError)
return
}
serializedEnr, err := p2p.SerializeENR(enr)
if err != nil {
httputil.HandleError(w, "Could not obtain ENR: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain ENR: "+err.Error(), http.StatusInternalServerError)
return
}
p2pAddress, err := peerStatus.Address(id)
if err != nil {
httputil.HandleError(w, "Could not obtain address: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain address: "+err.Error(), http.StatusInternalServerError)
return
}
state, err := peerStatus.ConnectionState(id)
if err != nil {
httputil.HandleError(w, "Could not obtain connection state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain connection state: "+err.Error(), http.StatusInternalServerError)
return
}
direction, err := peerStatus.Direction(id)
if err != nil {
httputil.HandleError(w, "Could not obtain direction: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not obtain direction: "+err.Error(), http.StatusInternalServerError)
return
}
if eth.PeerDirection(direction) == eth.PeerDirection_UNKNOWN {
httputil.HandleError(w, "Peer not found", http.StatusNotFound)
httputil2.HandleError(w, "Peer not found", http.StatusNotFound)
return
}
v1ConnState := migration.V1Alpha1ConnectionStateToV1(eth.ConnectionState(state))
v1PeerDirection, err := migration.V1Alpha1PeerDirectionToV1(eth.PeerDirection(direction))
if err != nil {
httputil.HandleError(w, "Could not handle peer direction: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not handle peer direction: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -84,7 +84,7 @@ func (s *Server) GetPeer(w http.ResponseWriter, r *http.Request) {
Direction: strings.ToLower(v1PeerDirection.String()),
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetPeers retrieves data about the node's network peers.
@@ -104,7 +104,7 @@ func (s *Server) GetPeers(w http.ResponseWriter, r *http.Request) {
for _, id := range allIds {
p, err := peerInfo(peerStatus, id)
if err != nil {
httputil.HandleError(w, "Could not get peer info: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get peer info: "+err.Error(), http.StatusInternalServerError)
return
}
if p == nil {
@@ -113,7 +113,7 @@ func (s *Server) GetPeers(w http.ResponseWriter, r *http.Request) {
allPeers = append(allPeers, p)
}
resp := &structs.GetPeersResponse{Data: allPeers}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
return
}
@@ -168,7 +168,7 @@ func (s *Server) GetPeers(w http.ResponseWriter, r *http.Request) {
for _, id := range filteredIds {
p, err := peerInfo(peerStatus, id)
if err != nil {
httputil.HandleError(w, "Could not get peer info: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get peer info: "+err.Error(), http.StatusInternalServerError)
return
}
if p == nil {
@@ -178,7 +178,7 @@ func (s *Server) GetPeers(w http.ResponseWriter, r *http.Request) {
}
resp := &structs.GetPeersResponse{Data: filteredPeers}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetPeerCount retrieves number of known peers.
@@ -196,7 +196,7 @@ func (s *Server) GetPeerCount(w http.ResponseWriter, r *http.Request) {
Disconnecting: strconv.FormatInt(int64(len(peerStatus.Disconnecting())), 10),
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
func handleEmptyFilters(states []string, directions []string) (emptyState, emptyDirection bool) {

View File

@@ -14,11 +14,11 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
libp2ptest "github.com/libp2p/go-libp2p/p2p/host/peerstore/test"
ma "github.com/multiformats/go-multiaddr"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

View File

@@ -14,6 +14,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
@@ -22,7 +23,6 @@ import (
syncmock "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/consensus-types/wrapper"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"

View File

@@ -10,6 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/rewards",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/core/altair:go_default_library",
@@ -28,7 +29,6 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
"@com_github_wealdtech_go_bytesutil//:go_default_library",
@@ -43,6 +43,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/core/altair:go_default_library",
@@ -61,7 +62,6 @@ go_test(
"//crypto/bls:go_default_library",
"//crypto/bls/blst:go_default_library",
"//encoding/bytesutil:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",

View File

@@ -7,6 +7,7 @@ import (
"strconv"
"strings"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/epoch/precompute"
@@ -17,7 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/time/slots"
"github.com/wealdtech/go-bytesutil"
@@ -36,28 +36,28 @@ func (s *Server) BlockRewards(w http.ResponseWriter, r *http.Request) {
}
if err := blocks.BeaconBlockIsNil(blk); err != nil {
httputil.HandleError(w, fmt.Sprintf("block id %s was not found", blockId), http.StatusNotFound)
httputil2.HandleError(w, fmt.Sprintf("block id %s was not found", blockId), http.StatusNotFound)
return
}
if blk.Version() == version.Phase0 {
httputil.HandleError(w, "Block rewards are not supported for Phase 0 blocks", http.StatusBadRequest)
httputil2.HandleError(w, "Block rewards are not supported for Phase 0 blocks", http.StatusBadRequest)
return
}
optimistic, err := s.OptimisticModeFetcher.IsOptimistic(r.Context())
if err != nil {
httputil.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
return
}
blkRoot, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return
}
blockRewards, httpError := s.BlockRewardFetcher.GetBlockRewardsData(ctx, blk.Block())
if httpError != nil {
httputil.WriteError(w, httpError)
httputil2.WriteError(w, httpError)
return
}
response := &structs.BlockRewardsResponse{
@@ -65,7 +65,7 @@ func (s *Server) BlockRewards(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: optimistic,
Finalized: s.FinalizationFetcher.IsFinalized(ctx, blkRoot),
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// AttestationRewards retrieves attestation reward info for validators specified by array of public keys or validator index.
@@ -90,12 +90,12 @@ func (s *Server) AttestationRewards(w http.ResponseWriter, r *http.Request) {
optimistic, err := s.OptimisticModeFetcher.IsOptimistic(r.Context())
if err != nil {
httputil.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
return
}
blkRoot, err := st.LatestBlockHeader().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -107,7 +107,7 @@ func (s *Server) AttestationRewards(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: optimistic,
Finalized: s.FinalizationFetcher.IsFinalized(r.Context(), blkRoot),
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// SyncCommitteeRewards retrieves rewards info for sync committee members specified by array of public keys or validator index.
@@ -123,18 +123,18 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
return
}
if blk.Version() == version.Phase0 {
httputil.HandleError(w, "Sync committee rewards are not supported for Phase 0", http.StatusBadRequest)
httputil2.HandleError(w, "Sync committee rewards are not supported for Phase 0", http.StatusBadRequest)
return
}
st, httpErr := s.BlockRewardFetcher.GetStateForRewards(ctx, blk.Block())
if httpErr != nil {
httputil.WriteError(w, httpErr)
httputil2.WriteError(w, httpErr)
return
}
sa, err := blk.Block().Body().SyncAggregate()
if err != nil {
httputil.HandleError(w, "Could not get sync aggregate: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync aggregate: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -146,14 +146,14 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
for i, valIdx := range valIndices {
preProcessBals[i], err = st.BalanceAtIndex(valIdx)
if err != nil {
httputil.HandleError(w, "Could not get validator's balance: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator's balance: "+err.Error(), http.StatusInternalServerError)
return
}
}
_, proposerReward, err := altair.ProcessSyncAggregate(r.Context(), st, sa)
if err != nil {
httputil.HandleError(w, "Could not get sync aggregate rewards: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync aggregate rewards: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -162,7 +162,7 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
for i, valIdx := range valIndices {
bal, err := st.BalanceAtIndex(valIdx)
if err != nil {
httputil.HandleError(w, "Could not get validator's balance: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator's balance: "+err.Error(), http.StatusInternalServerError)
return
}
rewards[i] = int(bal - preProcessBals[i]) // lint:ignore uintcast
@@ -173,12 +173,12 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
optimistic, err := s.OptimisticModeFetcher.IsOptimistic(r.Context())
if err != nil {
httputil.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get optimistic mode info: "+err.Error(), http.StatusInternalServerError)
return
}
blkRoot, err := blk.Block().HashTreeRoot()
if err != nil {
httputil.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get block root: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -194,35 +194,35 @@ func (s *Server) SyncCommitteeRewards(w http.ResponseWriter, r *http.Request) {
ExecutionOptimistic: optimistic,
Finalized: s.FinalizationFetcher.IsFinalized(r.Context(), blkRoot),
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
func (s *Server) attRewardsState(w http.ResponseWriter, r *http.Request) (state.BeaconState, bool) {
segments := strings.Split(r.URL.Path, "/")
requestedEpoch, err := strconv.ParseUint(segments[len(segments)-1], 10, 64)
if err != nil {
httputil.HandleError(w, "Could not decode epoch: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode epoch: "+err.Error(), http.StatusBadRequest)
return nil, false
}
if primitives.Epoch(requestedEpoch) < params.BeaconConfig().AltairForkEpoch {
httputil.HandleError(w, "Attestation rewards are not supported for Phase 0", http.StatusNotFound)
httputil2.HandleError(w, "Attestation rewards are not supported for Phase 0", http.StatusNotFound)
return nil, false
}
currentEpoch := uint64(slots.ToEpoch(s.TimeFetcher.CurrentSlot()))
if requestedEpoch+1 >= currentEpoch {
httputil.HandleError(w,
httputil2.HandleError(w,
"Attestation rewards are available after two epoch transitions to ensure all attestations have a chance of inclusion",
http.StatusNotFound)
return nil, false
}
nextEpochEnd, err := slots.EpochEnd(primitives.Epoch(requestedEpoch + 1))
if err != nil {
httputil.HandleError(w, "Could not get next epoch's ending slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get next epoch's ending slot: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
st, err := s.Stater.StateBySlot(r.Context(), nextEpochEnd)
if err != nil {
httputil.HandleError(w, "Could not get state for epoch's starting slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get state for epoch's starting slot: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
return st, true
@@ -235,12 +235,12 @@ func attRewardsBalancesAndVals(
) (*precompute.Balance, []*precompute.Validator, []primitives.ValidatorIndex, bool) {
allVals, bal, err := altair.InitializePrecomputeValidators(r.Context(), st)
if err != nil {
httputil.HandleError(w, "Could not initialize precompute validators: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not initialize precompute validators: "+err.Error(), http.StatusBadRequest)
return nil, nil, nil, false
}
allVals, bal, err = altair.ProcessEpochParticipation(r.Context(), st, bal, allVals)
if err != nil {
httputil.HandleError(w, "Could not process epoch participation: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not process epoch participation: "+err.Error(), http.StatusBadRequest)
return nil, nil, nil, false
}
valIndices, ok := requestedValIndices(w, r, st, allVals)
@@ -294,7 +294,7 @@ func idealAttRewards(
}
deltas, err := altair.AttestationsDelta(st, bal, idealVals)
if err != nil {
httputil.HandleError(w, "Could not get attestations delta: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get attestations delta: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
for i, d := range deltas {
@@ -331,7 +331,7 @@ func totalAttRewards(
}
deltas, err := altair.AttestationsDelta(st, bal, vals)
if err != nil {
httputil.HandleError(w, "Could not get attestations delta: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get attestations delta: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
for i, d := range deltas {
@@ -362,7 +362,7 @@ func syncRewardsVals(
) ([]*precompute.Validator, []primitives.ValidatorIndex, bool) {
allVals, _, err := altair.InitializePrecomputeValidators(r.Context(), st)
if err != nil {
httputil.HandleError(w, "Could not initialize precompute validators: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not initialize precompute validators: "+err.Error(), http.StatusBadRequest)
return nil, nil, false
}
valIndices, ok := requestedValIndices(w, r, st, allVals)
@@ -372,14 +372,14 @@ func syncRewardsVals(
sc, err := st.CurrentSyncCommittee()
if err != nil {
httputil.HandleError(w, "Could not get current sync committee: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not get current sync committee: "+err.Error(), http.StatusBadRequest)
return nil, nil, false
}
allScIndices := make([]primitives.ValidatorIndex, len(sc.Pubkeys))
for i, pk := range sc.Pubkeys {
valIdx, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(pk))
if !ok {
httputil.HandleError(w, fmt.Sprintf("No validator index found for pubkey %#x", pk), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("No validator index found for pubkey %#x", pk), http.StatusBadRequest)
return nil, nil, false
}
allScIndices[i] = valIdx
@@ -404,7 +404,7 @@ func requestedValIndices(w http.ResponseWriter, r *http.Request, st state.Beacon
var rawValIds []string
if r.Body != http.NoBody {
if err := json.NewDecoder(r.Body).Decode(&rawValIds); err != nil {
httputil.HandleError(w, "Could not decode validators: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode validators: "+err.Error(), http.StatusBadRequest)
return nil, false
}
}
@@ -414,18 +414,18 @@ func requestedValIndices(w http.ResponseWriter, r *http.Request, st state.Beacon
if err != nil {
pubkey, err := bytesutil.FromHexString(v)
if err != nil || len(pubkey) != fieldparams.BLSPubkeyLength {
httputil.HandleError(w, fmt.Sprintf("%s is not a validator index or pubkey", v), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("%s is not a validator index or pubkey", v), http.StatusBadRequest)
return nil, false
}
var ok bool
valIndices[i], ok = st.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubkey))
if !ok {
httputil.HandleError(w, fmt.Sprintf("No validator index found for pubkey %#x", pubkey), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("No validator index found for pubkey %#x", pubkey), http.StatusBadRequest)
return nil, false
}
} else {
if index >= uint64(st.NumValidators()) {
httputil.HandleError(w, fmt.Sprintf("Validator index %d is too large. Maximum allowed index is %d", index, st.NumValidators()-1), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Validator index %d is too large. Maximum allowed index is %d", index, st.NumValidators()-1), http.StatusBadRequest)
return nil, false
}
valIndices[i] = primitives.ValidatorIndex(index)

View File

@@ -13,6 +13,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
@@ -30,7 +31,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/crypto/bls/blst"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"strconv"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
coreblocks "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
@@ -15,7 +16,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen"
consensusblocks "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)

View File

@@ -6,9 +6,9 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/rewards/testing",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/state:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//network/httputil:go_default_library",
],
)

View File

@@ -3,10 +3,10 @@ package testing
import (
"context"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
)
type MockBlockRewardFetcher struct {

View File

@@ -9,13 +9,13 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/rpc/lookup:go_default_library",
"//beacon-chain/sync:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//network/httputil:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
@@ -29,8 +29,8 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//beacon-chain/rpc/lookup:go_default_library",
"//network/httputil:go_default_library",
"//testing/assert:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],

View File

@@ -4,10 +4,10 @@ import (
"net/http"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
)
// WriteStateFetchError writes an appropriate error based on the supplied argument.

View File

@@ -7,8 +7,8 @@ import (
"testing"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
)

View File

@@ -9,10 +9,10 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/sync"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
)
func UintFromQuery(w http.ResponseWriter, r *http.Request, name string, required bool) (string, uint64, bool) {
@@ -59,24 +59,24 @@ func HexFromRoute(w http.ResponseWriter, r *http.Request, name string, length in
func ValidateHex(w http.ResponseWriter, name, s string, length int) ([]byte, bool) {
if s == "" {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: name + " is required",
Code: http.StatusBadRequest,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return nil, false
}
hexBytes, err := hexutil.Decode(s)
if err != nil {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: name + " is invalid: " + err.Error(),
Code: http.StatusBadRequest,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return nil, false
}
if len(hexBytes) != length {
httputil.HandleError(w, fmt.Sprintf("Invalid %s: %s is not length %d", name, s, length), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Invalid %s: %s is not length %d", name, s, length), http.StatusBadRequest)
return nil, false
}
return hexBytes, true
@@ -84,20 +84,20 @@ func ValidateHex(w http.ResponseWriter, name, s string, length int) ([]byte, boo
func ValidateUint(w http.ResponseWriter, name, s string) (uint64, bool) {
if s == "" {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: name + " is required",
Code: http.StatusBadRequest,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return 0, false
}
v, err := strconv.ParseUint(s, 10, 64)
if err != nil {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: name + " is invalid: " + err.Error(),
Code: http.StatusBadRequest,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return 0, false
}
return v, true
@@ -119,11 +119,11 @@ func IsSyncing(
headSlot := headFetcher.HeadSlot()
isOptimistic, err := optimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: "Could not check optimistic status: " + err.Error(),
Code: http.StatusInternalServerError,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return true
}
syncDetails := &structs.SyncDetailsContainer{
@@ -140,10 +140,10 @@ func IsSyncing(
if err == nil {
msg += " Details: " + string(details)
}
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: msg,
Code: http.StatusServiceUnavailable}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return true
}
@@ -155,20 +155,20 @@ func IsOptimistic(
) (bool, error) {
isOptimistic, err := optimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: "Could not check optimistic status: " + err.Error(),
Code: http.StatusInternalServerError,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return true, err
}
if !isOptimistic {
return false, nil
}
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Code: http.StatusServiceUnavailable,
Message: "Beacon node is currently optimistic and not serving validators",
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
return true, nil
}

View File

@@ -11,7 +11,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/validator",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/builder:go_default_library",
@@ -40,7 +40,6 @@ go_library(
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/attestation/aggregation/attestations:go_default_library",
"//runtime/version:go_default_library",
@@ -62,7 +61,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/builder/testing:go_default_library",
@@ -87,7 +86,6 @@ go_test(
"//crypto/bls:go_default_library",
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",

View File

@@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/builder"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/cache"
@@ -33,7 +33,6 @@ import (
validator2 "github.com/prysmaticlabs/prysm/v5/consensus-types/validator"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpbalpha "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation/aggregation/attestations"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
@@ -64,15 +63,15 @@ func (s *Server) GetAggregateAttestation(w http.ResponseWriter, r *http.Request)
}
typedAgg, ok := agg.(*ethpbalpha.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.Attestation{}), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.Attestation{}), http.StatusInternalServerError)
return
}
data, err := json.Marshal(structs.AttFromConsensus(typedAgg))
if err != nil {
httputil.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.AggregateAttestationResponse{Data: data})
httputil2.WriteJson(w, &structs.AggregateAttestationResponse{Data: data})
}
// GetAggregateAttestationV2 aggregates all attestations matching the given attestation data root and slot, returning the aggregated result.
@@ -104,30 +103,30 @@ func (s *Server) GetAggregateAttestationV2(w http.ResponseWriter, r *http.Reques
if v >= version.Electra {
typedAgg, ok := agg.(*ethpbalpha.AttestationElectra)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.AttestationElectra{}), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.AttestationElectra{}), http.StatusInternalServerError)
return
}
data, err := json.Marshal(structs.AttElectraFromConsensus(typedAgg))
if err != nil {
httputil.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
return
}
resp.Data = data
} else {
typedAgg, ok := agg.(*ethpbalpha.Attestation)
if !ok {
httputil.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.Attestation{}), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Attestation is not of type %T", &ethpbalpha.Attestation{}), http.StatusInternalServerError)
return
}
data, err := json.Marshal(structs.AttFromConsensus(typedAgg))
if err != nil {
httputil.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not marshal attestation: "+err.Error(), http.StatusInternalServerError)
return
}
resp.Data = data
}
w.Header().Set(api.VersionHeader, version.String(v))
httputil.WriteJson(w, resp)
w.Header().Set(httputil2.VersionHeader, version.String(v))
httputil2.WriteJson(w, resp)
}
func (s *Server) aggregatedAttestation(w http.ResponseWriter, slot primitives.Slot, attDataRoot []byte, index primitives.CommitteeIndex) ethpbalpha.Att {
@@ -137,13 +136,13 @@ func (s *Server) aggregatedAttestation(w http.ResponseWriter, slot primitives.Sl
if features.Get().EnableExperimentalAttestationPool {
match, err = matchingAtts(s.AttestationCache.GetAll(), slot, attDataRoot, index)
if err != nil {
httputil.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
return nil
}
} else {
match, err = matchingAtts(s.AttestationsPool.AggregatedAttestations(), slot, attDataRoot, index)
if err != nil {
httputil.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
return nil
}
}
@@ -165,16 +164,16 @@ func (s *Server) aggregatedAttestation(w http.ResponseWriter, slot primitives.Sl
atts := s.AttestationsPool.UnaggregatedAttestations()
match, err = matchingAtts(atts, slot, attDataRoot, index)
if err != nil {
httputil.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get matching attestations: "+err.Error(), http.StatusInternalServerError)
return nil
}
if len(match) == 0 {
httputil.HandleError(w, "No matching attestations found", http.StatusNotFound)
httputil2.HandleError(w, "No matching attestations found", http.StatusNotFound)
return nil
}
agg, err := attestations.Aggregate(match)
if err != nil {
httputil.HandleError(w, "Could not aggregate unaggregated attestations: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not aggregate unaggregated attestations: "+err.Error(), http.StatusInternalServerError)
return nil
}
@@ -224,30 +223,30 @@ func (s *Server) SubmitContributionAndProofs(w http.ResponseWriter, r *http.Requ
var reqData []json.RawMessage
if err := json.NewDecoder(r.Body).Decode(&reqData); err != nil {
if errors.Is(err, io.EOF) {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
} else {
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
}
return
}
if len(reqData) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
for _, item := range reqData {
var contribution structs.SignedContributionAndProof
if err := json.Unmarshal(item, &contribution); err != nil {
httputil.HandleError(w, "Could not decode item: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode item: "+err.Error(), http.StatusBadRequest)
return
}
consensusItem, err := contribution.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert contribution to consensus format: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert contribution to consensus format: "+err.Error(), http.StatusBadRequest)
return
}
if rpcError := s.CoreService.SubmitSignedContributionAndProof(ctx, consensusItem); rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
}
@@ -263,14 +262,14 @@ func (s *Server) SubmitAggregateAndProofs(w http.ResponseWriter, r *http.Request
err := json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(req.Data) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
@@ -279,12 +278,12 @@ func (s *Server) SubmitAggregateAndProofs(w http.ResponseWriter, r *http.Request
var signedAggregate structs.SignedAggregateAttestationAndProof
err := json.Unmarshal(item, &signedAggregate)
if err != nil {
httputil.HandleError(w, "Could not decode item: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode item: "+err.Error(), http.StatusBadRequest)
return
}
consensusItem, err := signedAggregate.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
return
}
rpcError := s.CoreService.SubmitSignedAggregateSelectionProof(ctx, consensusItem)
@@ -294,14 +293,14 @@ func (s *Server) SubmitAggregateAndProofs(w http.ResponseWriter, r *http.Request
if ok {
broadcastFailed = true
} else {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
}
}
if broadcastFailed {
httputil.HandleError(w, "Could not broadcast one or more signed aggregated attestations", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not broadcast one or more signed aggregated attestations", http.StatusInternalServerError)
}
}
@@ -313,24 +312,24 @@ func (s *Server) SubmitAggregateAndProofsV2(w http.ResponseWriter, r *http.Reque
var reqData []json.RawMessage
if err := json.NewDecoder(r.Body).Decode(&reqData); err != nil {
if errors.Is(err, io.EOF) {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
} else {
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
}
return
}
if len(reqData) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
versionHeader := r.Header.Get(api.VersionHeader)
versionHeader := r.Header.Get(httputil2.VersionHeader)
if versionHeader == "" {
httputil.HandleError(w, api.VersionHeader+" header is required", http.StatusBadRequest)
httputil2.HandleError(w, httputil2.VersionHeader+" header is required", http.StatusBadRequest)
}
v, err := version.FromString(versionHeader)
if err != nil {
httputil.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid version: "+err.Error(), http.StatusBadRequest)
return
}
@@ -341,12 +340,12 @@ func (s *Server) SubmitAggregateAndProofsV2(w http.ResponseWriter, r *http.Reque
var signedAggregate structs.SignedAggregateAttestationAndProofElectra
err = json.Unmarshal(raw, &signedAggregate)
if err != nil {
httputil.HandleError(w, "Failed to parse aggregate attestation and proof: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Failed to parse aggregate attestation and proof: "+err.Error(), http.StatusBadRequest)
return
}
consensusItem, err := signedAggregate.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
return
}
rpcError = s.CoreService.SubmitSignedAggregateSelectionProof(ctx, consensusItem)
@@ -354,12 +353,12 @@ func (s *Server) SubmitAggregateAndProofsV2(w http.ResponseWriter, r *http.Reque
var signedAggregate structs.SignedAggregateAttestationAndProof
err = json.Unmarshal(raw, &signedAggregate)
if err != nil {
httputil.HandleError(w, "Failed to parse aggregate attestation and proof: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Failed to parse aggregate attestation and proof: "+err.Error(), http.StatusBadRequest)
return
}
consensusItem, err := signedAggregate.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request aggregate to consensus aggregate: "+err.Error(), http.StatusBadRequest)
return
}
rpcError = s.CoreService.SubmitSignedAggregateSelectionProof(ctx, consensusItem)
@@ -370,13 +369,13 @@ func (s *Server) SubmitAggregateAndProofsV2(w http.ResponseWriter, r *http.Reque
if errors.As(rpcError.Err, &aggregateBroadcastFailedError) {
broadcastFailed = true
} else {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
}
}
if broadcastFailed {
httputil.HandleError(w, "Could not broadcast one or more signed aggregated attestations", http.StatusInternalServerError)
httputil2.HandleError(w, "Could not broadcast one or more signed aggregated attestations", http.StatusInternalServerError)
}
}
@@ -397,20 +396,20 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
err := json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(req.Data) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
st, err := s.HeadFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
currEpoch := slots.ToEpoch(st.Slot())
@@ -419,13 +418,13 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
for i, item := range req.Data {
consensusItem, err := item.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request subscription to consensus subscription: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request subscription to consensus subscription: "+err.Error(), http.StatusBadRequest)
return
}
subscriptions[i] = consensusItem
val, err := st.ValidatorAtIndexReadOnly(consensusItem.ValidatorIndex)
if err != nil {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Could not get validator at index %d: %s", consensusItem.ValidatorIndex, err.Error()),
http.StatusInternalServerError,
@@ -434,7 +433,7 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
}
valStatus, err := rpchelpers.ValidatorSubStatus(val, currEpoch)
if err != nil {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Could not get validator status at index %d: %s", consensusItem.ValidatorIndex, err.Error()),
http.StatusInternalServerError,
@@ -442,7 +441,7 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
return
}
if valStatus != validator2.ActiveOngoing && valStatus != validator2.ActiveExiting {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Validator at index %d is not active or exiting", consensusItem.ValidatorIndex),
http.StatusBadRequest,
@@ -454,13 +453,13 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
startEpoch, err := slots.SyncCommitteePeriodStartEpoch(currEpoch)
if err != nil {
httputil.HandleError(w, "Could not get sync committee period start epoch: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee period start epoch: "+err.Error(), http.StatusInternalServerError)
return
}
for i, sub := range subscriptions {
if sub.UntilEpoch <= currEpoch {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Epoch for subscription at index %d is in the past. It must be at least %d", i, currEpoch+1),
http.StatusBadRequest,
@@ -469,7 +468,7 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
}
maxValidUntilEpoch := startEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod*2
if sub.UntilEpoch > maxValidUntilEpoch {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Epoch for subscription at index %d is too far in the future. It can be at most %d", i, maxValidUntilEpoch),
http.StatusBadRequest,
@@ -507,20 +506,20 @@ func (s *Server) SubmitBeaconCommitteeSubscription(w http.ResponseWriter, r *htt
err := json.NewDecoder(r.Body).Decode(&req.Data)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(req.Data) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
st, err := s.HeadFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -530,17 +529,17 @@ func (s *Server) SubmitBeaconCommitteeSubscription(w http.ResponseWriter, r *htt
for i, item := range req.Data {
consensusItem, err := item.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not convert request subscription to consensus subscription: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not convert request subscription to consensus subscription: "+err.Error(), http.StatusBadRequest)
return
}
subscriptions[i] = consensusItem
val, err := st.ValidatorAtIndexReadOnly(consensusItem.ValidatorIndex)
if err != nil {
if errors.Is(err, consensus_types.ErrOutOfBounds) {
httputil.HandleError(w, "Could not get validator: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not get validator: "+err.Error(), http.StatusBadRequest)
return
}
httputil.HandleError(w, "Could not get validator: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator: "+err.Error(), http.StatusInternalServerError)
return
}
validators[i] = val
@@ -558,7 +557,7 @@ func (s *Server) SubmitBeaconCommitteeSubscription(w http.ResponseWriter, r *htt
// Request the head validator indices of epoch represented by the first requested slot.
currValsLen, err := fetchValsLen(subscriptions[0].Slot)
if err != nil {
httputil.HandleError(w, "Could not retrieve head validator length: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve head validator length: "+err.Error(), http.StatusInternalServerError)
return
}
currEpoch := slots.ToEpoch(subscriptions[0].Slot)
@@ -567,7 +566,7 @@ func (s *Server) SubmitBeaconCommitteeSubscription(w http.ResponseWriter, r *htt
if currEpoch != slots.ToEpoch(sub.Slot) {
currValsLen, err = fetchValsLen(sub.Slot)
if err != nil {
httputil.HandleError(w, "Could not retrieve head validator length: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not retrieve head validator length: "+err.Error(), http.StatusInternalServerError)
return
}
currEpoch = slots.ToEpoch(sub.Slot)
@@ -605,7 +604,7 @@ func (s *Server) GetAttestationData(w http.ResponseWriter, r *http.Request) {
})
if rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
@@ -624,7 +623,7 @@ func (s *Server) GetAttestationData(w http.ResponseWriter, r *http.Request) {
},
},
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// ProduceSyncCommitteeContribution requests that the beacon node produce a sync committee contribution.
@@ -634,11 +633,11 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
if isOptimistic {
httputil.HandleError(w, "Beacon node is currently syncing and not serving request on that endpoint", http.StatusServiceUnavailable)
httputil2.HandleError(w, "Beacon node is currently syncing and not serving request on that endpoint", http.StatusServiceUnavailable)
return
}
@@ -653,7 +652,7 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
rawBlockRoot := r.URL.Query().Get("beacon_block_root")
blockRoot, err := hexutil.Decode(rawBlockRoot)
if err != nil {
httputil.HandleError(w, "Invalid Beacon Block Root: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Invalid Beacon Block Root: "+err.Error(), http.StatusBadRequest)
return
}
contribution, ok := s.produceSyncCommitteeContribution(ctx, w, primitives.Slot(slot), index, blockRoot)
@@ -663,7 +662,7 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http
response := &structs.ProduceSyncCommitteeContributionResponse{
Data: contribution,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// ProduceSyncCommitteeContribution requests that the beacon node produce a sync committee contribution.
@@ -676,11 +675,11 @@ func (s *Server) produceSyncCommitteeContribution(
) (*structs.SyncCommitteeContribution, bool) {
msgs, err := s.SyncCommitteePool.SyncCommitteeMessages(slot)
if err != nil {
httputil.HandleError(w, "Could not get sync subcommittee messages: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync subcommittee messages: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
if len(msgs) == 0 {
httputil.HandleError(w, "No subcommittee messages found", http.StatusNotFound)
httputil2.HandleError(w, "No subcommittee messages found", http.StatusNotFound)
return nil, false
}
sig, aggregatedBits, err := s.CoreService.AggregatedSigAndAggregationBits(
@@ -693,7 +692,7 @@ func (s *Server) produceSyncCommitteeContribution(
},
)
if err != nil {
httputil.HandleError(w, "Could not get contribution data: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get contribution data: "+err.Error(), http.StatusInternalServerError)
return nil, false
}
@@ -712,7 +711,7 @@ func (s *Server) RegisterValidator(w http.ResponseWriter, r *http.Request) {
defer span.End()
if s.BlockBuilder == nil || !s.BlockBuilder.Configured() {
httputil.HandleError(w, fmt.Sprintf("Could not register block builder: %v", builder.ErrNoBuilder), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Could not register block builder: %v", builder.ErrNoBuilder), http.StatusBadRequest)
return
}
@@ -720,10 +719,10 @@ func (s *Server) RegisterValidator(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&jsonRegistrations)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
@@ -731,18 +730,18 @@ func (s *Server) RegisterValidator(w http.ResponseWriter, r *http.Request) {
for i, registration := range jsonRegistrations {
reg, err := registration.ToConsensus()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
registrations[i] = reg
}
if len(registrations) == 0 {
httputil.HandleError(w, "Validator registration request is empty", http.StatusBadRequest)
httputil2.HandleError(w, "Validator registration request is empty", http.StatusBadRequest)
return
}
if err := s.BlockBuilder.RegisterValidator(ctx, registrations); err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
}
@@ -753,10 +752,10 @@ func (s *Server) PrepareBeaconProposer(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&jsonFeeRecipients)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
var validatorIndices []primitives.ValidatorIndex
@@ -813,14 +812,14 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&indices)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(indices) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
requestedValIndices := make([]primitives.ValidatorIndex, len(indices))
@@ -836,7 +835,7 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
currentEpoch := slots.ToEpoch(cs)
nextEpoch := currentEpoch + 1
if requestedEpoch > nextEpoch {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Request epoch %d can not be greater than next epoch %d", requestedEpoch, nextEpoch),
http.StatusBadRequest,
@@ -851,24 +850,24 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
startSlot, err = slots.EpochStart(requestedEpoch)
}
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get start slot from epoch %d: %v", requestedEpoch, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get start slot from epoch %d: %v", requestedEpoch, err), http.StatusInternalServerError)
return
}
st, err := s.Stater.StateBySlot(ctx, startSlot)
if err != nil {
httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
return
}
assignments, err := helpers.CommitteeAssignments(ctx, st, requestedEpoch, requestedValIndices)
if err != nil {
httputil.HandleError(w, "Could not compute committee assignments: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not compute committee assignments: "+err.Error(), http.StatusInternalServerError)
return
}
activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, st, requestedEpoch)
if err != nil {
httputil.HandleError(w, "Could not get active validator count: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get active validator count: "+err.Error(), http.StatusInternalServerError)
return
}
committeesAtSlot := helpers.SlotCommitteeCount(activeValidatorCount)
@@ -878,7 +877,7 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
pubkey := st.PubkeyAtIndex(index)
var zeroPubkey [fieldparams.BLSPubkeyLength]byte
if bytes.Equal(pubkey[:], zeroPubkey[:]) {
httputil.HandleError(w, fmt.Sprintf("Invalid validator index %d", index), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Invalid validator index %d", index), http.StatusBadRequest)
return
}
committee := assignments[index]
@@ -909,20 +908,20 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
if requestedEpoch <= 1 {
r, err := s.BeaconDB.GenesisBlockRoot(ctx)
if err != nil {
httputil.HandleError(w, "Could not get genesis block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get genesis block root: "+err.Error(), http.StatusInternalServerError)
return
}
dependentRoot = r[:]
} else {
dependentRoot, err = attestationDependentRoot(st, requestedEpoch)
if err != nil {
httputil.HandleError(w, "Could not get dependent root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get dependent root: "+err.Error(), http.StatusInternalServerError)
return
}
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -931,7 +930,7 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) {
Data: duties,
ExecutionOptimistic: isOptimistic,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetProposerDuties requests beacon node to provide all validators that are scheduled to propose a block in the given epoch.
@@ -954,7 +953,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
nextEpoch := currentEpoch + 1
var nextEpochLookahead bool
if requestedEpoch > nextEpoch {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Request epoch %d can not be greater than next epoch %d", requestedEpoch, currentEpoch+1),
http.StatusBadRequest,
@@ -968,7 +967,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
epochStartSlot, err := slots.EpochStart(requestedEpoch)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get start slot of epoch %d: %v", requestedEpoch, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get start slot of epoch %d: %v", requestedEpoch, err), http.StatusInternalServerError)
return
}
var st state.BeaconState
@@ -976,25 +975,25 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
if requestedEpoch < currentEpoch {
st, err = s.Stater.StateBySlot(ctx, epochStartSlot)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get state for slot %d: %v ", epochStartSlot, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get state for slot %d: %v ", epochStartSlot, err), http.StatusInternalServerError)
return
}
} else {
st, err = s.HeadFetcher.HeadState(ctx)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get head state: %v ", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get head state: %v ", err), http.StatusInternalServerError)
return
}
// Advance state with empty transitions up to the requested epoch start slot.
if st.Slot() < epochStartSlot {
headRoot, err := s.HeadFetcher.HeadRoot(ctx)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get head root: %v ", err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get head root: %v ", err), http.StatusInternalServerError)
return
}
st, err = transition.ProcessSlotsUsingNextSlotCache(ctx, st, headRoot, epochStartSlot)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not process slots up to %d: %v ", epochStartSlot, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not process slots up to %d: %v ", epochStartSlot, err), http.StatusInternalServerError)
return
}
}
@@ -1007,7 +1006,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
assignments, err = helpers.ProposerAssignments(ctx, st, requestedEpoch)
}
if err != nil {
httputil.HandleError(w, "Could not compute committee assignments: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not compute committee assignments: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -1015,7 +1014,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
for index, proposalSlots := range assignments {
val, err := st.ValidatorAtIndexReadOnly(index)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not get validator at index %d: %v", index, err), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not get validator at index %d: %v", index, err), http.StatusInternalServerError)
return
}
pubkey48 := val.PublicKey()
@@ -1033,20 +1032,20 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
if requestedEpoch == 0 {
r, err := s.BeaconDB.GenesisBlockRoot(ctx)
if err != nil {
httputil.HandleError(w, "Could not get genesis block root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get genesis block root: "+err.Error(), http.StatusInternalServerError)
return
}
dependentRoot = r[:]
} else {
dependentRoot, err = proposalDependentRoot(st, requestedEpoch)
if err != nil {
httputil.HandleError(w, "Could not get dependent root: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get dependent root: "+err.Error(), http.StatusInternalServerError)
return
}
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
if !sortProposerDuties(w, duties) {
@@ -1058,7 +1057,7 @@ func (s *Server) GetProposerDuties(w http.ResponseWriter, r *http.Request) {
Data: duties,
ExecutionOptimistic: isOptimistic,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetSyncCommitteeDuties provides a set of sync committee duties for a particular epoch.
@@ -1086,21 +1085,21 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
}
requestedEpoch := primitives.Epoch(requestedEpochUint)
if requestedEpoch < params.BeaconConfig().AltairForkEpoch {
httputil.HandleError(w, "Sync committees are not supported for Phase0", http.StatusBadRequest)
httputil2.HandleError(w, "Sync committees are not supported for Phase0", http.StatusBadRequest)
return
}
var indices []string
err := json.NewDecoder(r.Body).Decode(&indices)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(indices) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
requestedValIndices := make([]primitives.ValidatorIndex, len(indices))
@@ -1115,7 +1114,7 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
currentEpoch := slots.ToEpoch(s.TimeFetcher.CurrentSlot())
lastValidEpoch := syncCommitteeDutiesLastValidEpoch(currentEpoch)
if requestedEpoch > lastValidEpoch {
httputil.HandleError(w, fmt.Sprintf("Epoch is too far in the future, maximum valid epoch is %d", lastValidEpoch), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Epoch is too far in the future, maximum valid epoch is %d", lastValidEpoch), http.StatusBadRequest)
return
}
@@ -1125,18 +1124,18 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
}
slot, err := slots.EpochStart(startingEpoch)
if err != nil {
httputil.HandleError(w, "Could not get sync committee slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee slot: "+err.Error(), http.StatusInternalServerError)
return
}
st, err := s.Stater.State(ctx, []byte(strconv.FormatUint(uint64(slot), 10)))
if err != nil {
httputil.HandleError(w, "Could not get sync committee state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee state: "+err.Error(), http.StatusInternalServerError)
return
}
currentSyncCommitteeFirstEpoch, err := slots.SyncCommitteePeriodStartEpoch(startingEpoch)
if err != nil {
httputil.HandleError(w, "Could not get sync committee period start epoch: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee period start epoch: "+err.Error(), http.StatusInternalServerError)
return
}
nextSyncCommitteeFirstEpoch := currentSyncCommitteeFirstEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod
@@ -1145,13 +1144,13 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
if isCurrentCommitteeRequested {
committee, err = st.CurrentSyncCommittee()
if err != nil {
httputil.HandleError(w, "Could not get sync committee: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee: "+err.Error(), http.StatusInternalServerError)
return
}
} else {
committee, err = st.NextSyncCommittee()
if err != nil {
httputil.HandleError(w, "Could not get sync committee: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get sync committee: "+err.Error(), http.StatusInternalServerError)
return
}
}
@@ -1162,7 +1161,7 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
}
duties, vals, err := syncCommitteeDutiesAndVals(st, requestedValIndices, committeePubkeys)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, err.Error(), http.StatusBadRequest)
return
}
@@ -1176,18 +1175,18 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
pk := v.PublicKey()
valStatus, err := rpchelpers.ValidatorStatus(v, requestedEpoch)
if err != nil {
httputil.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get validator status: "+err.Error(), http.StatusInternalServerError)
return
}
if err := registerSyncSubnet(st, requestedEpoch, pk[:], valStatus); err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not register sync subnet for pubkey %#x", pk), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not register sync subnet for pubkey %#x", pk), http.StatusInternalServerError)
return
}
}
isOptimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not check optimistic status: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -1195,7 +1194,7 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request)
Data: duties,
ExecutionOptimistic: isOptimistic,
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetLiveness requests the beacon node to indicate if a validator has been observed to be live in a given epoch.
@@ -1218,14 +1217,14 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&indices)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
if len(indices) == 0 {
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
}
requestedValIndices := make([]primitives.ValidatorIndex, len(indices))
@@ -1243,12 +1242,12 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) {
// We can also use the head state to get participation info for the previous epoch.
headSt, err := s.HeadFetcher.HeadState(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
currEpoch := slots.ToEpoch(headSt.Slot())
if requestedEpoch > currEpoch {
httputil.HandleError(w, "Requested epoch cannot be in the future", http.StatusBadRequest)
httputil2.HandleError(w, "Requested epoch cannot be in the future", http.StatusBadRequest)
return
}
@@ -1258,30 +1257,30 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) {
st = headSt
participation, err = st.CurrentEpochParticipation()
if err != nil {
httputil.HandleError(w, "Could not get current epoch participation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get current epoch participation: "+err.Error(), http.StatusInternalServerError)
return
}
} else if requestedEpoch == currEpoch-1 {
st = headSt
participation, err = st.PreviousEpochParticipation()
if err != nil {
httputil.HandleError(w, "Could not get previous epoch participation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get previous epoch participation: "+err.Error(), http.StatusInternalServerError)
return
}
} else {
epochEnd, err := slots.EpochEnd(requestedEpoch)
if err != nil {
httputil.HandleError(w, "Could not get requested epoch's end slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get requested epoch's end slot: "+err.Error(), http.StatusInternalServerError)
return
}
st, err = s.Stater.StateBySlot(ctx, epochEnd)
if err != nil {
httputil.HandleError(w, "Could not get slot for requested epoch: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get slot for requested epoch: "+err.Error(), http.StatusInternalServerError)
return
}
participation, err = st.CurrentEpochParticipation()
if err != nil {
httputil.HandleError(w, "Could not get current epoch participation: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get current epoch participation: "+err.Error(), http.StatusInternalServerError)
return
}
}
@@ -1291,7 +1290,7 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) {
}
for i, vi := range requestedValIndices {
if vi >= primitives.ValidatorIndex(len(participation)) {
httputil.HandleError(w, fmt.Sprintf("Validator index %d is invalid", vi), http.StatusBadRequest)
httputil2.HandleError(w, fmt.Sprintf("Validator index %d is invalid", vi), http.StatusBadRequest)
return
}
resp.Data[i] = &structs.Liveness{
@@ -1300,19 +1299,19 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) {
}
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// BeaconCommitteeSelections responds with appropriate message and status code according the spec:
// https://ethereum.github.io/beacon-APIs/#/Validator/submitBeaconCommitteeSelections.
func (s *Server) BeaconCommitteeSelections(w http.ResponseWriter, _ *http.Request) {
httputil.HandleError(w, "Endpoint not implemented", 501)
httputil2.HandleError(w, "Endpoint not implemented", 501)
}
// SyncCommitteeSelections responds with appropriate message and status code according the spec:
// https://ethereum.github.io/beacon-APIs/#/Validator/submitSyncCommitteeSelections.
func (s *Server) SyncCommitteeSelections(w http.ResponseWriter, _ *http.Request) {
httputil.HandleError(w, "Endpoint not implemented", 501)
httputil2.HandleError(w, "Endpoint not implemented", 501)
}
// attestationDependentRoot is get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch - 1) - 1)
@@ -1401,13 +1400,13 @@ func sortProposerDuties(w http.ResponseWriter, duties []*structs.ProposerDuty) b
sort.Slice(duties, func(i, j int) bool {
si, err := strconv.ParseUint(duties[i].Slot, 10, 64)
if err != nil {
httputil.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError)
ok = false
return false
}
sj, err := strconv.ParseUint(duties[j].Slot, 10, 64)
if err != nil {
httputil.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not parse slot: "+err.Error(), http.StatusInternalServerError)
ok = false
return false
}

View File

@@ -9,7 +9,7 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/rewards"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
@@ -19,7 +19,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/crypto/bls/common"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"google.golang.org/protobuf/types/known/wrapperspb"
@@ -62,7 +61,7 @@ func (s *Server) ProduceBlockV2(w http.ResponseWriter, r *http.Request) {
} else {
rr, err := bytesutil.DecodeHexWithLength(rawRandaoReveal, fieldparams.BLSSignatureLength)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
return
}
randaoReveal = rr
@@ -71,7 +70,7 @@ func (s *Server) ProduceBlockV2(w http.ResponseWriter, r *http.Request) {
if rawGraffiti != "" {
g, err := bytesutil.DecodeHexWithLength(rawGraffiti, 32)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
return
}
graffiti = g
@@ -114,7 +113,7 @@ func (s *Server) ProduceBlindedBlock(w http.ResponseWriter, r *http.Request) {
} else {
rr, err := bytesutil.DecodeHexWithLength(rawRandaoReveal, fieldparams.BLSSignatureLength)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
return
}
randaoReveal = rr
@@ -123,7 +122,7 @@ func (s *Server) ProduceBlindedBlock(w http.ResponseWriter, r *http.Request) {
if rawGraffiti != "" {
g, err := bytesutil.DecodeHexWithLength(rawGraffiti, 32)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
return
}
graffiti = g
@@ -179,7 +178,7 @@ func (s *Server) ProduceBlockV3(w http.ResponseWriter, r *http.Request) {
} else {
rr, err := bytesutil.DecodeHexWithLength(rawRandaoReveal, fieldparams.BLSSignatureLength)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode randao reveal").Error(), http.StatusBadRequest)
return
}
randaoReveal = rr
@@ -188,7 +187,7 @@ func (s *Server) ProduceBlockV3(w http.ResponseWriter, r *http.Request) {
if rawGraffiti != "" {
g, err := bytesutil.DecodeHexWithLength(rawGraffiti, 32)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
httputil2.HandleError(w, errors.Wrap(err, "Unable to decode graffiti").Error(), http.StatusBadRequest)
return
}
graffiti = g
@@ -204,18 +203,18 @@ func (s *Server) ProduceBlockV3(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) produceBlockV3(ctx context.Context, w http.ResponseWriter, r *http.Request, v1alpha1req *eth.BlockRequest, requiredType blockType) {
isSSZ := httputil.RespondWithSsz(r)
isSSZ := httputil2.RespondWithSsz(r)
v1alpha1resp, err := s.V1Alpha1Server.GetBeaconBlock(ctx, v1alpha1req)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
if requiredType == blinded && !v1alpha1resp.IsBlinded {
httputil.HandleError(w, "Prepared block is not blinded", http.StatusInternalServerError)
httputil2.HandleError(w, "Prepared block is not blinded", http.StatusInternalServerError)
return
} else if requiredType == full && v1alpha1resp.IsBlinded {
httputil.HandleError(w, "Prepared block is blinded", http.StatusInternalServerError)
httputil2.HandleError(w, "Prepared block is blinded", http.StatusInternalServerError)
return
}
@@ -226,98 +225,98 @@ func (s *Server) produceBlockV3(ctx context.Context, w http.ResponseWriter, r *h
consensusBlockValue = ""
}
w.Header().Set(api.ExecutionPayloadBlindedHeader, fmt.Sprintf("%v", v1alpha1resp.IsBlinded))
w.Header().Set(api.ExecutionPayloadValueHeader, v1alpha1resp.PayloadValue)
w.Header().Set(api.ConsensusBlockValueHeader, consensusBlockValue)
w.Header().Set(httputil2.ExecutionPayloadBlindedHeader, fmt.Sprintf("%v", v1alpha1resp.IsBlinded))
w.Header().Set(httputil2.ExecutionPayloadValueHeader, v1alpha1resp.PayloadValue)
w.Header().Set(httputil2.ConsensusBlockValueHeader, consensusBlockValue)
phase0Block, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Phase0)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Phase0))
w.Header().Set(httputil2.VersionHeader, version.String(version.Phase0))
// rewards aren't used in phase 0
handleProducePhase0V3(w, isSSZ, phase0Block, v1alpha1resp.PayloadValue)
return
}
altairBlock, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Altair)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Altair))
w.Header().Set(httputil2.VersionHeader, version.String(version.Altair))
handleProduceAltairV3(w, isSSZ, altairBlock, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
optimistic, err := s.OptimisticModeFetcher.IsOptimistic(ctx)
if err != nil {
httputil.HandleError(w, errors.Wrap(err, "Could not determine if the node is a optimistic node").Error(), http.StatusInternalServerError)
httputil2.HandleError(w, errors.Wrap(err, "Could not determine if the node is a optimistic node").Error(), http.StatusInternalServerError)
return
}
if optimistic {
httputil.HandleError(w, "The node is currently optimistic and cannot serve validators", http.StatusServiceUnavailable)
httputil2.HandleError(w, "The node is currently optimistic and cannot serve validators", http.StatusServiceUnavailable)
return
}
blindedBellatrixBlock, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_BlindedBellatrix)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Bellatrix))
w.Header().Set(httputil2.VersionHeader, version.String(version.Bellatrix))
handleProduceBlindedBellatrixV3(w, isSSZ, blindedBellatrixBlock, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
bellatrixBlock, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Bellatrix)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Bellatrix))
w.Header().Set(httputil2.VersionHeader, version.String(version.Bellatrix))
handleProduceBellatrixV3(w, isSSZ, bellatrixBlock, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
blindedCapellaBlock, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_BlindedCapella)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Capella))
w.Header().Set(httputil2.VersionHeader, version.String(version.Capella))
handleProduceBlindedCapellaV3(w, isSSZ, blindedCapellaBlock, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
capellaBlock, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Capella)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Capella))
w.Header().Set(httputil2.VersionHeader, version.String(version.Capella))
handleProduceCapellaV3(w, isSSZ, capellaBlock, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
blindedDenebBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_BlindedDeneb)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Deneb))
w.Header().Set(httputil2.VersionHeader, version.String(version.Deneb))
handleProduceBlindedDenebV3(w, isSSZ, blindedDenebBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
denebBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Deneb)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Deneb))
w.Header().Set(httputil2.VersionHeader, version.String(version.Deneb))
handleProduceDenebV3(w, isSSZ, denebBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
blindedElectraBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_BlindedElectra)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Electra))
w.Header().Set(httputil2.VersionHeader, version.String(version.Electra))
handleProduceBlindedElectraV3(w, isSSZ, blindedElectraBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
electraBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Electra)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Electra))
w.Header().Set(httputil2.VersionHeader, version.String(version.Electra))
handleProduceElectraV3(w, isSSZ, electraBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
blindedFuluBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_BlindedFulu)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Fulu))
w.Header().Set(httputil2.VersionHeader, version.String(version.Fulu))
handleProduceBlindedFuluV3(w, isSSZ, blindedFuluBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
fuluBlockContents, ok := v1alpha1resp.Block.(*eth.GenericBeaconBlock_Fulu)
if ok {
w.Header().Set(api.VersionHeader, version.String(version.Fulu))
w.Header().Set(httputil2.VersionHeader, version.String(version.Fulu))
handleProduceFuluV3(w, isSSZ, fuluBlockContents, v1alpha1resp.PayloadValue, consensusBlockValue)
return
}
}
func getConsensusBlockValue(ctx context.Context, blockRewardsFetcher rewards.BlockRewardsFetcher, i interface{} /* block as argument */) (string, *httputil.DefaultJsonError) {
func getConsensusBlockValue(ctx context.Context, blockRewardsFetcher rewards.BlockRewardsFetcher, i interface{} /* block as argument */) (string, *httputil2.DefaultJsonError) {
bb, err := blocks.NewBeaconBlock(i)
if err != nil {
return "", &httputil.DefaultJsonError{
return "", &httputil2.DefaultJsonError{
Message: err.Error(),
Code: http.StatusInternalServerError,
}
@@ -334,7 +333,7 @@ func getConsensusBlockValue(ctx context.Context, blockRewardsFetcher rewards.Blo
}
gwei, ok := big.NewInt(0).SetString(blockRewards.Total, 10)
if !ok {
return "", &httputil.DefaultJsonError{
return "", &httputil2.DefaultJsonError{
Message: "Could not parse consensus block value",
Code: http.StatusInternalServerError,
}
@@ -352,18 +351,18 @@ func handleProducePhase0V3(
if isSSZ {
sszResp, err := blk.Phase0.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
jsonBytes, err := json.Marshal(structs.BeaconBlockFromConsensus(blk.Phase0))
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Phase0),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: payloadValue, // mev not available at this point
@@ -382,18 +381,18 @@ func handleProduceAltairV3(
if isSSZ {
sszResp, err := blk.Altair.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
jsonBytes, err := json.Marshal(structs.BeaconBlockAltairFromConsensus(blk.Altair))
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Altair),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point
@@ -412,23 +411,23 @@ func handleProduceBellatrixV3(
if isSSZ {
sszResp, err := blk.Bellatrix.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
block, err := structs.BeaconBlockBellatrixFromConsensus(blk.Bellatrix)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(block)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Bellatrix),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point
@@ -447,23 +446,23 @@ func handleProduceBlindedBellatrixV3(
if isSSZ {
sszResp, err := blk.BlindedBellatrix.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
block, err := structs.BlindedBeaconBlockBellatrixFromConsensus(blk.BlindedBellatrix)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(block)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Bellatrix),
ExecutionPayloadBlinded: true,
ExecutionPayloadValue: executionPayloadValue,
@@ -482,23 +481,23 @@ func handleProduceBlindedCapellaV3(
if isSSZ {
sszResp, err := blk.BlindedCapella.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
block, err := structs.BlindedBeaconBlockCapellaFromConsensus(blk.BlindedCapella)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(block)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Capella),
ExecutionPayloadBlinded: true,
ExecutionPayloadValue: executionPayloadValue,
@@ -517,23 +516,23 @@ func handleProduceCapellaV3(
if isSSZ {
sszResp, err := blk.Capella.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
block, err := structs.BeaconBlockCapellaFromConsensus(blk.Capella)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(block)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Capella),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point
@@ -552,23 +551,23 @@ func handleProduceBlindedDenebV3(
if isSSZ {
sszResp, err := blk.BlindedDeneb.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blindedBlock, err := structs.BlindedBeaconBlockDenebFromConsensus(blk.BlindedDeneb)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blindedBlock)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Deneb),
ExecutionPayloadBlinded: true,
ExecutionPayloadValue: executionPayloadValue,
@@ -587,24 +586,24 @@ func handleProduceDenebV3(
if isSSZ {
sszResp, err := blk.Deneb.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blockContents, err := structs.BeaconBlockContentsDenebFromConsensus(blk.Deneb)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blockContents)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Deneb),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point
@@ -623,23 +622,23 @@ func handleProduceBlindedElectraV3(
if isSSZ {
sszResp, err := blk.BlindedElectra.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blindedBlock, err := structs.BlindedBeaconBlockElectraFromConsensus(blk.BlindedElectra)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blindedBlock)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Electra),
ExecutionPayloadBlinded: true,
ExecutionPayloadValue: executionPayloadValue,
@@ -658,24 +657,24 @@ func handleProduceElectraV3(
if isSSZ {
sszResp, err := blk.Electra.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blockContents, err := structs.BeaconBlockContentsElectraFromConsensus(blk.Electra)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blockContents)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Electra),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point
@@ -694,23 +693,23 @@ func handleProduceBlindedFuluV3(
if isSSZ {
sszResp, err := blk.BlindedFulu.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blindedBlock, err := structs.BlindedBeaconBlockFuluFromConsensus(blk.BlindedFulu)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blindedBlock)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Fulu),
ExecutionPayloadBlinded: true,
ExecutionPayloadValue: executionPayloadValue,
@@ -729,24 +728,24 @@ func handleProduceFuluV3(
if isSSZ {
sszResp, err := blk.Fulu.MarshalSSZ()
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteSsz(w, sszResp)
httputil2.WriteSsz(w, sszResp)
return
}
blockContents, err := structs.BeaconBlockContentsFuluFromConsensus(blk.Fulu)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(blockContents)
if err != nil {
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, err.Error(), http.StatusInternalServerError)
return
}
httputil.WriteJson(w, &structs.ProduceBlockV3Response{
httputil2.WriteJson(w, &structs.ProduceBlockV3Response{
Version: version.String(version.Fulu),
ExecutionPayloadBlinded: false,
ExecutionPayloadValue: executionPayloadValue, // mev not available at this point

View File

@@ -10,13 +10,12 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
blockchainTesting "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
rewardtesting "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/rewards/testing"
rpctesting "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared/testing"
mockSync "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
mock2 "github.com/prysmaticlabs/prysm/v5/testing/mock"
@@ -66,7 +65,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"phase0","execution_payload_blinded":false,"execution_payload_value":"","consensus_block_value":"","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "phase0", writer.Header().Get(api.VersionHeader))
require.Equal(t, "phase0", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Altair", func(t *testing.T) {
var block *structs.SignedBeaconBlockAltair
@@ -99,7 +98,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"altair","execution_payload_blinded":false,"execution_payload_value":"","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "altair", writer.Header().Get(api.VersionHeader))
require.Equal(t, "altair", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Bellatrix", func(t *testing.T) {
var block *structs.SignedBeaconBlockBellatrix
@@ -136,7 +135,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"bellatrix","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
})
t.Run("BlindedBellatrix", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockBellatrix
@@ -205,7 +204,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"capella","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Capella", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockCapella
@@ -274,7 +273,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"deneb","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Deneb", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockDeneb
@@ -343,7 +342,7 @@ func TestProduceBlockV2(t *testing.T) {
want := fmt.Sprintf(`{"version":"electra","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Electra", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockElectra
@@ -466,7 +465,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -478,7 +477,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Phase0.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "phase0", writer.Header().Get(api.VersionHeader))
require.Equal(t, "phase0", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Altair", func(t *testing.T) {
var block *structs.SignedBeaconBlockAltair
@@ -503,7 +502,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -515,7 +514,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Altair.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "altair", writer.Header().Get(api.VersionHeader))
require.Equal(t, "altair", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Bellatrix", func(t *testing.T) {
var block *structs.SignedBeaconBlockBellatrix
@@ -540,7 +539,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -552,7 +551,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Bellatrix.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
})
t.Run("BlindedBellatrix", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockBellatrix
@@ -577,7 +576,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -610,7 +609,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -622,7 +621,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Capella.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Capella", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockCapella
@@ -650,7 +649,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -683,7 +682,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -695,7 +694,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Deneb.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Deneb", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockDeneb
@@ -720,7 +719,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -753,7 +752,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -765,7 +764,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
ssz, err := bl.Electra.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Blinded Electra", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockElectra
@@ -790,7 +789,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v2/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV2(writer, request)
@@ -943,7 +942,7 @@ func TestProduceBlindedBlock(t *testing.T) {
want := fmt.Sprintf(`{"version":"bellatrix","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Capella", func(t *testing.T) {
var block *structs.SignedBeaconBlockCapella
@@ -1012,7 +1011,7 @@ func TestProduceBlindedBlock(t *testing.T) {
want := fmt.Sprintf(`{"version":"capella","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Deneb", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsDeneb
@@ -1081,7 +1080,7 @@ func TestProduceBlindedBlock(t *testing.T) {
want := fmt.Sprintf(`{"version":"deneb","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
})
t.Run("Electra", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsElectra
@@ -1150,7 +1149,7 @@ func TestProduceBlindedBlock(t *testing.T) {
want := fmt.Sprintf(`{"version":"electra","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
})
t.Run("invalid query parameter slot empty", func(t *testing.T) {
v1alpha1Server := mock2.NewMockBeaconNodeValidatorServer(ctrl)
@@ -1248,10 +1247,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"phase0","execution_payload_blinded":false,"execution_payload_value":"","consensus_block_value":"","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "phase0", writer.Header().Get(api.VersionHeader))
require.Equal(t, "", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "phase0", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Altair", func(t *testing.T) {
var block *structs.SignedBeaconBlockAltair
@@ -1284,10 +1283,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"altair","execution_payload_blinded":false,"execution_payload_value":"","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "altair", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "altair", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Bellatrix", func(t *testing.T) {
var block *structs.SignedBeaconBlockBellatrix
@@ -1322,10 +1321,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"bellatrix","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("BlindedBellatrix", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockBellatrix
@@ -1360,10 +1359,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"bellatrix","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Capella", func(t *testing.T) {
var block *structs.SignedBeaconBlockCapella
@@ -1398,10 +1397,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"capella","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Capella", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockCapella
@@ -1436,10 +1435,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"capella","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Deneb", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsDeneb
@@ -1474,10 +1473,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"deneb","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Deneb", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockDeneb
@@ -1512,10 +1511,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"deneb","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Electra", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsElectra
@@ -1550,10 +1549,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"electra","execution_payload_blinded":false,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Electra", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockElectra
@@ -1588,10 +1587,10 @@ func TestProduceBlockV3(t *testing.T) {
want := fmt.Sprintf(`{"version":"electra","execution_payload_blinded":true,"execution_payload_value":"2000","consensus_block_value":"10000000000","data":%s}`, string(jsonBytes))
body := strings.ReplaceAll(writer.Body.String(), "\n", "")
require.Equal(t, want, body)
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("invalid query parameter slot empty", func(t *testing.T) {
v1alpha1Server := mock2.NewMockBeaconNodeValidatorServer(ctrl)
@@ -1679,7 +1678,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
SyncChecker: syncChecker,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1691,10 +1690,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Phase0.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "phase0", writer.Header().Get(api.VersionHeader))
require.Equal(t, "", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "phase0", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Altair", func(t *testing.T) {
var block *structs.SignedBeaconBlockAltair
@@ -1717,7 +1716,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1729,10 +1728,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Altair.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "altair", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "altair", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Bellatrix", func(t *testing.T) {
var block *structs.SignedBeaconBlockBellatrix
@@ -1759,7 +1758,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1771,10 +1770,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Bellatrix.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("BlindedBellatrix", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockBellatrix
@@ -1800,7 +1799,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1812,10 +1811,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.BlindedBellatrix.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "bellatrix", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Capella", func(t *testing.T) {
var block *structs.SignedBeaconBlockCapella
@@ -1841,7 +1840,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1853,10 +1852,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Capella.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Capella", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockCapella
@@ -1882,7 +1881,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1894,10 +1893,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.BlindedCapella.Block.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "capella", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Deneb", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsDeneb
@@ -1923,7 +1922,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1935,10 +1934,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Deneb.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Deneb", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockDeneb
@@ -1964,7 +1963,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -1976,10 +1975,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.BlindedDeneb.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "deneb", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Electra", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsElectra
@@ -2005,7 +2004,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -2017,10 +2016,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Electra.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Electra", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockElectra
@@ -2046,7 +2045,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -2058,10 +2057,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.BlindedElectra.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "electra", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Fulu", func(t *testing.T) {
var block *structs.SignedBeaconBlockContentsFulu
@@ -2087,7 +2086,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -2099,10 +2098,10 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.Fulu.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "false", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "fulu", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "false", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "fulu", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
t.Run("Blinded Fulu", func(t *testing.T) {
var block *structs.SignedBlindedBeaconBlockFulu
@@ -2128,7 +2127,7 @@ func TestProduceBlockV3SSZ(t *testing.T) {
BlockRewardFetcher: rewardFetcher,
}
request := httptest.NewRequest(http.MethodGet, fmt.Sprintf("http://foo.example/eth/v3/validator/blocks/1?randao_reveal=%s&graffiti=%s", randao, graffiti), nil)
request.Header.Set("Accept", api.OctetStreamMediaType)
request.Header.Set("Accept", httputil.OctetStreamMediaType)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
server.ProduceBlockV3(writer, request)
@@ -2140,9 +2139,9 @@ func TestProduceBlockV3SSZ(t *testing.T) {
ssz, err := bl.BlindedFulu.MarshalSSZ()
require.NoError(t, err)
require.Equal(t, string(ssz), writer.Body.String())
require.Equal(t, "true", writer.Header().Get(api.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(api.ExecutionPayloadValueHeader))
require.Equal(t, "fulu", writer.Header().Get(api.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(api.ConsensusBlockValueHeader))
require.Equal(t, "true", writer.Header().Get(httputil.ExecutionPayloadBlindedHeader))
require.Equal(t, "2000", writer.Header().Get(httputil.ExecutionPayloadValueHeader))
require.Equal(t, "fulu", writer.Header().Get(httputil.VersionHeader))
require.Equal(t, "10000000000", writer.Header().Get(httputil.ConsensusBlockValueHeader))
})
}

View File

@@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
mockChain "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
builderTest "github.com/prysmaticlabs/prysm/v5/beacon-chain/builder/testing"
@@ -38,7 +38,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/crypto/bls/common"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpbalpha "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
@@ -687,7 +686,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(singleAggregateElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -703,7 +702,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(singleAggregate)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -720,7 +719,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(multipleAggregatesElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -737,7 +736,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(multipleAggregates)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Phase0))
request.Header.Set(httputil.VersionHeader, version.String(version.Phase0))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -747,7 +746,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
})
t.Run("no body", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -760,7 +759,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
})
t.Run("no body-pre-electra", func(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
request.Header.Set(api.VersionHeader, version.String(version.Bellatrix))
request.Header.Set(httputil.VersionHeader, version.String(version.Bellatrix))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -776,7 +775,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString("[]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -792,7 +791,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString("[]")
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Altair))
request.Header.Set(httputil.VersionHeader, version.String(version.Altair))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -808,7 +807,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(invalidAggregateElectra)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Electra))
request.Header.Set(httputil.VersionHeader, version.String(version.Electra))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
@@ -823,7 +822,7 @@ func TestSubmitAggregateAndProofs(t *testing.T) {
_, err := body.WriteString(invalidAggregate)
require.NoError(t, err)
request := httptest.NewRequest(http.MethodPost, "http://example.com", &body)
request.Header.Set(api.VersionHeader, version.String(version.Deneb))
request.Header.Set(httputil.VersionHeader, version.String(version.Deneb))
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}

View File

@@ -10,6 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/prysm/beacon",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
@@ -28,7 +29,6 @@ go_library(
"//consensus-types/validator:go_default_library",
"//encoding/bytesutil:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//time/slots:go_default_library",
@@ -45,6 +45,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
@@ -65,7 +66,6 @@ go_test(
"//consensus-types/blocks:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",

View File

@@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core"
@@ -19,7 +20,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -36,27 +36,27 @@ func (s *Server) GetWeakSubjectivity(w http.ResponseWriter, r *http.Request) {
hs, err := s.HeadFetcher.HeadStateReadOnly(ctx)
if err != nil {
httputil.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get head state: "+err.Error(), http.StatusInternalServerError)
return
}
wsEpoch, err := helpers.LatestWeakSubjectivityEpoch(ctx, hs, params.BeaconConfig())
if err != nil {
httputil.HandleError(w, "Could not get weak subjectivity epoch: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get weak subjectivity epoch: "+err.Error(), http.StatusInternalServerError)
return
}
wsSlot, err := slots.EpochStart(wsEpoch)
if err != nil {
httputil.HandleError(w, "Could not get weak subjectivity slot: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not get weak subjectivity slot: "+err.Error(), http.StatusInternalServerError)
return
}
cbr, err := s.CanonicalHistory.BlockRootForSlot(ctx, wsSlot)
if err != nil {
httputil.HandleError(w, fmt.Sprintf("Could not find highest block below slot %d: %s", wsSlot, err.Error()), http.StatusInternalServerError)
httputil2.HandleError(w, fmt.Sprintf("Could not find highest block below slot %d: %s", wsSlot, err.Error()), http.StatusInternalServerError)
return
}
cb, err := s.BeaconDB.Block(ctx, cbr)
if err != nil {
httputil.HandleError(
httputil2.HandleError(
w,
fmt.Sprintf("Block with root %#x from slot index %d not found in db: %s", cbr, wsSlot, err.Error()),
http.StatusInternalServerError,
@@ -75,7 +75,7 @@ func (s *Server) GetWeakSubjectivity(w http.ResponseWriter, r *http.Request) {
StateRoot: hexutil.Encode(stateRoot[:]),
},
}
httputil.WriteJson(w, resp)
httputil2.WriteJson(w, resp)
}
// GetIndividualVotes returns a list of validators individual vote status of a given epoch.
@@ -87,10 +87,10 @@ func (s *Server) GetIndividualVotes(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
@@ -98,21 +98,21 @@ func (s *Server) GetIndividualVotes(w http.ResponseWriter, r *http.Request) {
for i, s := range req.PublicKeys {
bs, err := hexutil.Decode(s)
if err != nil {
httputil.HandleError(w, "could not decode public keys: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "could not decode public keys: "+err.Error(), http.StatusBadRequest)
return
}
publicKeyBytes[i] = bs
}
epoch, err := strconv.ParseUint(req.Epoch, 10, 64)
if err != nil {
httputil.HandleError(w, "invalid epoch: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "invalid epoch: "+err.Error(), http.StatusBadRequest)
return
}
var indices []primitives.ValidatorIndex
for _, i := range req.Indices {
u, err := strconv.ParseUint(i, 10, 64)
if err != nil {
httputil.HandleError(w, "invalid indices: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "invalid indices: "+err.Error(), http.StatusBadRequest)
return
}
indices = append(indices, primitives.ValidatorIndex(u))
@@ -127,7 +127,7 @@ func (s *Server) GetIndividualVotes(w http.ResponseWriter, r *http.Request) {
)
if rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
v := make([]*structs.IndividualVote, 0, len(votes.IndividualVotes))
@@ -154,7 +154,7 @@ func (s *Server) GetIndividualVotes(w http.ResponseWriter, r *http.Request) {
response := &structs.GetIndividualVotesResponse{
IndividualVotes: v,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetChainHead retrieves information about the head of the beacon chain from
@@ -165,7 +165,7 @@ func (s *Server) GetChainHead(w http.ResponseWriter, r *http.Request) {
ch, rpcError := s.CoreService.ChainHead(ctx)
if rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
response := &structs.ChainHead{
@@ -183,7 +183,7 @@ func (s *Server) GetChainHead(w http.ResponseWriter, r *http.Request) {
PreviousJustifiedBlockRoot: hexutil.Encode(ch.PreviousJustifiedBlockRoot),
OptimisticStatus: ch.OptimisticStatus,
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
func (s *Server) PublishBlobs(w http.ResponseWriter, r *http.Request) {
@@ -195,41 +195,41 @@ func (s *Server) PublishBlobs(w http.ResponseWriter, r *http.Request) {
var req structs.PublishBlobsRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httputil.HandleError(w, "Could not decode JSON request body", http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode JSON request body", http.StatusBadRequest)
return
}
if req.BlobSidecars == nil {
httputil.HandleError(w, "Missing blob sidecars", http.StatusBadRequest)
httputil2.HandleError(w, "Missing blob sidecars", http.StatusBadRequest)
return
}
root, err := bytesutil.DecodeHexWithLength(req.BlockRoot, 32)
if err != nil {
httputil.HandleError(w, "Could not decode block root: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode block root: "+err.Error(), http.StatusBadRequest)
return
}
for _, blobSidecar := range req.BlobSidecars.Sidecars {
sc, err := blobSidecar.ToConsensus()
if err != nil {
httputil.HandleError(w, "Could not decode blob sidecar: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode blob sidecar: "+err.Error(), http.StatusBadRequest)
return
}
readOnlySc, err := blocks.NewROBlobWithRoot(sc, bytesutil.ToBytes32(root))
if err != nil {
httputil.HandleError(w, "Could not create read-only blob: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not create read-only blob: "+err.Error(), http.StatusInternalServerError)
return
}
verifiedBlob := blocks.NewVerifiedROBlob(readOnlySc)
if err := s.BlobReceiver.ReceiveBlob(ctx, verifiedBlob); err != nil {
httputil.HandleError(w, "Could not receive blob: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Could not receive blob: "+err.Error(), http.StatusInternalServerError)
return
}
if err := s.Broadcaster.BroadcastBlob(ctx, sc.Index, sc); err != nil {
httputil.HandleError(w, "Failed to broadcast blob: "+err.Error(), http.StatusInternalServerError)
httputil2.HandleError(w, "Failed to broadcast blob: "+err.Error(), http.StatusInternalServerError)
return
}
}

View File

@@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
@@ -14,7 +15,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/consensus-types/validator"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/time/slots"

View File

@@ -12,6 +12,7 @@ import (
"strings"
"testing"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
@@ -19,7 +20,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util"

View File

@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/prysm/node",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/db:go_default_library",
@@ -18,7 +19,6 @@ go_library(
"//beacon-chain/p2p/peers/peerdata:go_default_library",
"//beacon-chain/sync:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_libp2p_go_libp2p//core/network:go_default_library",
"@com_github_libp2p_go_libp2p//core/peer:go_default_library",
@@ -31,11 +31,11 @@ go_test(
srcs = ["handlers_test.go"],
embed = [":go_default_library"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/p2p/peers:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//network/httputil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",

View File

@@ -9,12 +9,12 @@ import (
corenet "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers/peerdata"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)

View File

@@ -14,11 +14,11 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
libp2ptest "github.com/libp2p/go-libp2p/p2p/host/peerstore/test"
ma "github.com/multiformats/go-multiaddr"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

View File

@@ -10,6 +10,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/prysm/validator",
visibility = ["//visibility:public"],
deps = [
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/blockchain:go_default_library",
"//beacon-chain/db:go_default_library",
@@ -18,7 +19,6 @@ go_library(
"//beacon-chain/rpc/lookup:go_default_library",
"//consensus-types/primitives:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",

View File

@@ -5,12 +5,12 @@ import (
"net/http"
"github.com/ethereum/go-ethereum/common/hexutil"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/time/slots"
)
@@ -23,7 +23,7 @@ func (s *Server) GetParticipation(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
@@ -35,7 +35,7 @@ func (s *Server) GetParticipation(w http.ResponseWriter, r *http.Request) {
stEpoch := slots.ToEpoch(st.Slot())
vp, rpcError := s.CoreService.ValidatorParticipation(ctx, stEpoch)
if rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
@@ -55,7 +55,7 @@ func (s *Server) GetParticipation(w http.ResponseWriter, r *http.Request) {
PreviousEpochHeadAttestingGwei: fmt.Sprintf("%d", vp.Participation.PreviousEpochHeadAttestingGwei),
},
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
// GetActiveSetChanges retrieves the active set changes for a given epoch.
@@ -68,7 +68,7 @@ func (s *Server) GetActiveSetChanges(w http.ResponseWriter, r *http.Request) {
stateId := r.PathValue("state_id")
if stateId == "" {
httputil.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
httputil2.HandleError(w, "state_id is required in URL params", http.StatusBadRequest)
return
}
@@ -81,7 +81,7 @@ func (s *Server) GetActiveSetChanges(w http.ResponseWriter, r *http.Request) {
as, rpcError := s.CoreService.ValidatorActiveSetChanges(ctx, stEpoch)
if rpcError != nil {
httputil.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
httputil2.HandleError(w, rpcError.Err.Error(), core.ErrorReasonToHTTP(rpcError.Reason))
return
}
@@ -96,7 +96,7 @@ func (s *Server) GetActiveSetChanges(w http.ResponseWriter, r *http.Request) {
EjectedPublicKeys: byteSlice2dToStringSlice(as.EjectedPublicKeys),
EjectedIndices: uint64SliceToStringSlice(as.EjectedIndices),
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
func byteSlice2dToStringSlice(byteArrays [][]byte) []string {

View File

@@ -6,10 +6,10 @@ import (
"net/http"
"github.com/pkg/errors"
httputil2 "github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/core"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
)
@@ -23,10 +23,10 @@ func (s *Server) GetPerformance(w http.ResponseWriter, r *http.Request) {
err := json.NewDecoder(r.Body).Decode(&req)
switch {
case errors.Is(err, io.EOF):
httputil.HandleError(w, "No data submitted", http.StatusBadRequest)
httputil2.HandleError(w, "No data submitted", http.StatusBadRequest)
return
case err != nil:
httputil.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
httputil2.HandleError(w, "Could not decode request body: "+err.Error(), http.StatusBadRequest)
return
}
@@ -52,13 +52,13 @@ func (s *Server) GetPerformance(w http.ResponseWriter, r *http.Request) {
MissingValidators: computed.MissingValidators,
InactivityScores: computed.InactivityScores, // Only populated in Altair
}
httputil.WriteJson(w, response)
httputil2.WriteJson(w, response)
}
func handleHTTPError(w http.ResponseWriter, message string, code int) {
errJson := &httputil.DefaultJsonError{
errJson := &httputil2.DefaultJsonError{
Message: message,
Code: code,
}
httputil.WriteError(w, errJson)
httputil2.WriteError(w, errJson)
}

View File

@@ -13,6 +13,7 @@ go_library(
deps = [
"//api/client:go_default_library",
"//api/client/beacon:go_default_library",
"//api/httputil:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/state:go_default_library",

View File

@@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/config/params"
@@ -32,7 +33,7 @@ type APIInitializer struct {
// NewAPIInitializer creates an APIInitializer, handling the set up of a beacon node api client
// using the provided host string.
func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
c, err := beacon.NewClient(beaconNodeHost, client.WithMaxBodySize(client.MaxBodySizeState))
c, err := beacon.NewClient(beaconNodeHost, client.WithMaxBodySize(httputil.MaxBodySizeState))
if err != nil {
return nil, errors.Wrapf(err, "unable to parse beacon node url or hostname - %s", beaconNodeHost)
}

View File

@@ -4,8 +4,8 @@ import (
"context"
"github.com/pkg/errors"
base "github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/ssz/detect"
@@ -21,7 +21,7 @@ func ComputeWeakSubjectivityCheckpoint(ctx context.Context, client *beacon.Clien
ws, err := client.GetWeakSubjectivity(ctx)
if err != nil {
// a 404/405 is expected if querying an endpoint that doesn't support the weak subjectivity checkpoint api
if !errors.Is(err, base.ErrNotOK) {
if !errors.Is(err, httputil.ErrNotOK) {
return nil, errors.Wrap(err, "unexpected API response for prysm-only weak subjectivity checkpoint API")
}
// fall back to vanilla Beacon Node API method

View File

@@ -12,6 +12,7 @@ go_library(
deps = [
"//api/client:go_default_library",
"//api/client/beacon:go_default_library",
"//api/httputil:go_default_library",
"//beacon-chain/db:go_default_library",
"//crypto/hash:go_default_library",
"//io/file:go_default_library",

View File

@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db"
)
@@ -18,7 +19,7 @@ type APIInitializer struct {
// NewAPIInitializer creates an APIInitializer, handling the set up of a beacon node api client
// using the provided host string.
func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
c, err := beacon.NewClient(beaconNodeHost, client.WithMaxBodySize(client.MaxBodySizeState))
c, err := beacon.NewClient(beaconNodeHost, client.WithMaxBodySize(httputil.MaxBodySizeState))
if err != nil {
return nil, errors.Wrapf(err, "unable to parse beacon node url or hostname - %s", beaconNodeHost)
}

View File

@@ -0,0 +1,3 @@
### Ignored
- migrating network/httputil to api/httputil and merging apiutils with httputil.

View File

@@ -11,6 +11,7 @@ go_library(
deps = [
"//api/client:go_default_library",
"//api/client/beacon:go_default_library",
"//api/httputil:go_default_library",
"//beacon-chain/sync/checkpoint:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",

View File

@@ -7,6 +7,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/api/client"
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/checkpoint"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@@ -47,7 +48,7 @@ func cliActionDownload(_ *cli.Context) error {
ctx := context.Background()
f := downloadFlags
opts := []client.ClientOpt{client.WithTimeout(f.Timeout), client.WithMaxBodySize(client.MaxBodySizeState)}
opts := []client.ClientOpt{client.WithTimeout(f.Timeout), client.WithMaxBodySize(httputil.MaxBodySizeState)}
client, err := beacon.NewClient(downloadFlags.BeaconNodeHost, opts...)
if err != nil {
return err

View File

@@ -14,7 +14,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/cmd/validator/accounts",
visibility = ["//visibility:public"],
deps = [
"//api/grpc:go_default_library",
"//api/grpcutil:go_default_library",
"//cmd:go_default_library",
"//cmd/validator/flags:go_default_library",
"//config/features:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
grpcutil "github.com/prysmaticlabs/prysm/v5/api/grpc"
grpcutil "github.com/prysmaticlabs/prysm/v5/api/grpcutil"
"github.com/prysmaticlabs/prysm/v5/cmd"
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"

View File

@@ -15,7 +15,7 @@ go_library(
"//validator:__subpackages__",
],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//config/params:go_default_library",
"//io/file:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",

View File

@@ -8,7 +8,7 @@ import (
"runtime"
"time"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/io/file"
"github.com/urfave/cli/v2"
@@ -136,7 +136,7 @@ var (
AuthTokenPathFlag = &cli.StringFlag{
Name: "keymanager-token-file",
Usage: "Path to auth token file used for validator apis.",
Value: filepath.Join(filepath.Join(DefaultValidatorDir(), WalletDefaultDirName), api.AuthTokenFileName),
Value: filepath.Join(filepath.Join(DefaultValidatorDir(), WalletDefaultDirName), httputil.AuthTokenFileName),
Aliases: []string{"validator-api-bearer-file"},
}
// WalletDirFlag defines the path to a wallet directory for Prysm accounts.

View File

@@ -9,7 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/cmd/validator/web",
visibility = ["//visibility:public"],
deps = [
"//api:go_default_library",
"//api/httputil:go_default_library",
"//cmd:go_default_library",
"//cmd/validator/flags:go_default_library",
"//config/features:go_default_library",

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"path/filepath"
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/httputil"
"github.com/prysmaticlabs/prysm/v5/cmd"
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
"github.com/prysmaticlabs/prysm/v5/config/features"
@@ -46,7 +46,7 @@ var Commands = &cli.Command{
host := cliCtx.String(flags.HTTPServerHost.Name)
port := cliCtx.Int(flags.HTTPServerPort.Name)
validatorWebAddr := fmt.Sprintf("%s:%d", host, port)
authTokenPath := filepath.Join(walletDirPath, api.AuthTokenFileName)
authTokenPath := filepath.Join(walletDirPath, httputil.AuthTokenFileName)
tempAuthTokenPath := cliCtx.String(flags.AuthTokenPathFlag.Name)
if tempAuthTokenPath != "" {
authTokenPath = tempAuthTokenPath

View File

@@ -1,13 +0,0 @@
package httputil
import (
"net/http"
)
func HandleError(w http.ResponseWriter, message string, code int) {
errJson := &DefaultJsonError{
Message: message,
Code: code,
}
WriteError(w, errJson)
}

View File

@@ -22,6 +22,7 @@ go_library(
visibility = ["//testing/endtoend:__subpackages__"],
deps = [
"//api/client/beacon:go_default_library",
"//api/httputil:go_default_library",
"//api/server/structs:go_default_library",
"//beacon-chain/core/altair:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
@@ -39,7 +40,6 @@ go_library(
"//encoding/ssz:go_default_library",
"//encoding/ssz/detect:go_default_library",
"//network/forks:go_default_library",
"//network/httputil:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/interop:go_default_library",
"//runtime/version:go_default_library",

Some files were not shown because too many files have changed in this diff Show More