mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
FIX: removing extra container for ssz blob sidecar response (#14451)
* removing extra container for ssz blob sidecar response * gaz and changelog * gaz * fixing dependencies * fixing test * updating values based on feedback"
This commit is contained in:
@@ -60,6 +60,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
|
|||||||
- `== nil` checks before calling `IsNil()` on interfaces to prevent panics.
|
- `== nil` checks before calling `IsNil()` on interfaces to prevent panics.
|
||||||
- Core: Fixed slash processing causing extra hashing
|
- Core: Fixed slash processing causing extra hashing
|
||||||
- Core: Fixed extra allocations when processing slashings
|
- Core: Fixed extra allocations when processing slashings
|
||||||
|
- remove unneeded container in blob sidecar ssz response
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
|||||||
@@ -114,5 +114,5 @@ func (s *blobStorageCache) evict(key [32]byte) {
|
|||||||
func (s *blobStorageCache) updateMetrics(delta float64) {
|
func (s *blobStorageCache) updateMetrics(delta float64) {
|
||||||
s.nBlobs += delta
|
s.nBlobs += delta
|
||||||
blobDiskCount.Set(s.nBlobs)
|
blobDiskCount.Set(s.nBlobs)
|
||||||
blobDiskSize.Set(s.nBlobs * bytesPerSidecar)
|
blobDiskSize.Set(s.nBlobs * fieldparams.BlobSidecarSize)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const retentionBuffer primitives.Epoch = 2
|
const retentionBuffer primitives.Epoch = 2
|
||||||
const bytesPerSidecar = 131928
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errPruningFailures = errors.New("blobs could not be pruned for some roots")
|
errPruningFailures = errors.New("blobs could not be pruned for some roots")
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ go_library(
|
|||||||
"//beacon-chain/rpc/core:go_default_library",
|
"//beacon-chain/rpc/core:go_default_library",
|
||||||
"//beacon-chain/rpc/lookup:go_default_library",
|
"//beacon-chain/rpc/lookup:go_default_library",
|
||||||
"//config/fieldparams:go_default_library",
|
"//config/fieldparams:go_default_library",
|
||||||
|
"//consensus-types/blocks:go_default_library",
|
||||||
"//monitoring/tracing/trace:go_default_library",
|
"//monitoring/tracing/trace:go_default_library",
|
||||||
"//network/httputil:go_default_library",
|
"//network/httputil:go_default_library",
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
|
||||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||||
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ go_test(
|
|||||||
"//beacon-chain/rpc/lookup:go_default_library",
|
"//beacon-chain/rpc/lookup:go_default_library",
|
||||||
"//beacon-chain/rpc/testutil:go_default_library",
|
"//beacon-chain/rpc/testutil:go_default_library",
|
||||||
"//beacon-chain/verification:go_default_library",
|
"//beacon-chain/verification:go_default_library",
|
||||||
|
"//config/fieldparams:go_default_library",
|
||||||
"//config/params:go_default_library",
|
"//config/params:go_default_library",
|
||||||
"//network/httputil:go_default_library",
|
"//network/httputil:go_default_library",
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
|
"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/core"
|
||||||
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
||||||
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
||||||
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
|
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
|
||||||
"github.com/prysmaticlabs/prysm/v5/network/httputil"
|
"github.com/prysmaticlabs/prysm/v5/network/httputil"
|
||||||
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Blobs is an HTTP handler for Beacon API getBlobs.
|
// Blobs is an HTTP handler for Beacon API getBlobs.
|
||||||
func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx, span := trace.StartSpan(r.Context(), "beacon.Blobs")
|
ctx, span := trace.StartSpan(r.Context(), "beacon.Blobs")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
var sidecars []*eth.BlobSidecar
|
|
||||||
|
|
||||||
indices, err := parseIndices(r.URL)
|
indices, err := parseIndices(r.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,14 +48,9 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range verifiedBlobs {
|
|
||||||
sidecars = append(sidecars, verifiedBlobs[i].BlobSidecar)
|
|
||||||
}
|
|
||||||
if httputil.RespondWithSsz(r) {
|
if httputil.RespondWithSsz(r) {
|
||||||
sidecarResp := ð.BlobSidecars{
|
sszResp, err := buildSidecarsSSZResponse(verifiedBlobs)
|
||||||
Sidecars: sidecars,
|
|
||||||
}
|
|
||||||
sszResp, err := sidecarResp.MarshalSSZ()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
|
httputil.HandleError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -64,7 +59,7 @@ func (s *Server) Blobs(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
httputil.WriteJson(w, buildSidecarsResponse(sidecars))
|
httputil.WriteJson(w, buildSidecarsJsonResponse(verifiedBlobs))
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseIndices filters out invalid and duplicate blob indices
|
// parseIndices filters out invalid and duplicate blob indices
|
||||||
@@ -97,9 +92,9 @@ loop:
|
|||||||
return indices, nil
|
return indices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildSidecarsResponse(sidecars []*eth.BlobSidecar) *structs.SidecarsResponse {
|
func buildSidecarsJsonResponse(verifiedBlobs []*blocks.VerifiedROBlob) *structs.SidecarsResponse {
|
||||||
resp := &structs.SidecarsResponse{Data: make([]*structs.Sidecar, len(sidecars))}
|
resp := &structs.SidecarsResponse{Data: make([]*structs.Sidecar, len(verifiedBlobs))}
|
||||||
for i, sc := range sidecars {
|
for i, sc := range verifiedBlobs {
|
||||||
proofs := make([]string, len(sc.CommitmentInclusionProof))
|
proofs := make([]string, len(sc.CommitmentInclusionProof))
|
||||||
for j := range sc.CommitmentInclusionProof {
|
for j := range sc.CommitmentInclusionProof {
|
||||||
proofs[j] = hexutil.Encode(sc.CommitmentInclusionProof[j])
|
proofs[j] = hexutil.Encode(sc.CommitmentInclusionProof[j])
|
||||||
@@ -115,3 +110,15 @@ func buildSidecarsResponse(sidecars []*eth.BlobSidecar) *structs.SidecarsRespons
|
|||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildSidecarsSSZResponse(verifiedBlobs []*blocks.VerifiedROBlob) ([]byte, error) {
|
||||||
|
ssz := make([]byte, field_params.BlobSidecarSize*len(verifiedBlobs))
|
||||||
|
for i, sidecar := range verifiedBlobs {
|
||||||
|
sszrep, err := sidecar.MarshalSSZ()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "failed to marshal sidecar ssz")
|
||||||
|
}
|
||||||
|
copy(ssz[i*field_params.BlobSidecarSize:(i+1)*field_params.BlobSidecarSize], sszrep)
|
||||||
|
}
|
||||||
|
return ssz, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup"
|
||||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil"
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil"
|
||||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/verification"
|
"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/config/params"
|
||||||
"github.com/prysmaticlabs/prysm/v5/network/httputil"
|
"github.com/prysmaticlabs/prysm/v5/network/httputil"
|
||||||
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||||
@@ -366,7 +367,32 @@ func TestBlobs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
s.Blobs(writer, request)
|
s.Blobs(writer, request)
|
||||||
assert.Equal(t, http.StatusOK, writer.Code)
|
assert.Equal(t, http.StatusOK, writer.Code)
|
||||||
require.Equal(t, len(writer.Body.Bytes()), 131932)
|
require.Equal(t, len(writer.Body.Bytes()), fieldparams.BlobSidecarSize) // size of each sidecar
|
||||||
|
// can directly unmarshal to sidecar since there's only 1
|
||||||
|
var sidecar eth.BlobSidecar
|
||||||
|
require.NoError(t, sidecar.UnmarshalSSZ(writer.Body.Bytes()))
|
||||||
|
require.NotNil(t, sidecar.Blob)
|
||||||
|
})
|
||||||
|
t.Run("ssz multiple blobs", func(t *testing.T) {
|
||||||
|
u := "http://foo.example/finalized"
|
||||||
|
request := httptest.NewRequest("GET", u, nil)
|
||||||
|
request.Header.Add("Accept", "application/octet-stream")
|
||||||
|
writer := httptest.NewRecorder()
|
||||||
|
writer.Body = &bytes.Buffer{}
|
||||||
|
blocker := &lookup.BeaconDbBlocker{
|
||||||
|
ChainInfoFetcher: &mockChain.ChainService{FinalizedCheckPoint: ð.Checkpoint{Root: blockRoot[:]}},
|
||||||
|
GenesisTimeFetcher: &testutil.MockGenesisTimeFetcher{
|
||||||
|
Genesis: time.Now(),
|
||||||
|
},
|
||||||
|
BeaconDB: db,
|
||||||
|
BlobStorage: bs,
|
||||||
|
}
|
||||||
|
s := &Server{
|
||||||
|
Blocker: blocker,
|
||||||
|
}
|
||||||
|
s.Blobs(writer, request)
|
||||||
|
assert.Equal(t, http.StatusOK, writer.Code)
|
||||||
|
require.Equal(t, len(writer.Body.Bytes()), fieldparams.BlobSidecarSize*4) // size of each sidecar
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const (
|
|||||||
LogMaxBlobCommitments = 12 // Log_2 of MaxBlobCommitmentsPerBlock
|
LogMaxBlobCommitments = 12 // Log_2 of MaxBlobCommitmentsPerBlock
|
||||||
BlobLength = 131072 // BlobLength defines the byte length of a blob.
|
BlobLength = 131072 // BlobLength defines the byte length of a blob.
|
||||||
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
|
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
|
||||||
|
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen
|
||||||
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
|
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
|
||||||
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
|
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
|
||||||
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const (
|
|||||||
LogMaxBlobCommitments = 4 // Log_2 of MaxBlobCommitmentsPerBlock
|
LogMaxBlobCommitments = 4 // Log_2 of MaxBlobCommitmentsPerBlock
|
||||||
BlobLength = 131072 // BlobLength defines the byte length of a blob.
|
BlobLength = 131072 // BlobLength defines the byte length of a blob.
|
||||||
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
|
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
|
||||||
|
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen
|
||||||
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
|
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item
|
||||||
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
|
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch.
|
||||||
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
PendingBalanceDepositsLimit = 134217728 // Maximum number of pending balance deposits in the beacon state.
|
||||||
|
|||||||
Reference in New Issue
Block a user