Skip to content

cl/rpc: use count param for blob sidecar slice preallocation#19030

Open
VolodymyrBg wants to merge 1 commit intoerigontech:mainfrom
VolodymyrBg:fix/cl-rpc-blob-sidecar-prealloc
Open

cl/rpc: use count param for blob sidecar slice preallocation#19030
VolodymyrBg wants to merge 1 commit intoerigontech:mainfrom
VolodymyrBg:fix/cl-rpc-blob-sidecar-prealloc

Conversation

@VolodymyrBg
Copy link
Contributor

@VolodymyrBg VolodymyrBg commented Feb 8, 2026

The count parameter in sendBlobsSidecar

erigon/cl/rpc/rpc.go

Lines 99 to 114 in d2f7395

func (b *BeaconRpcP2P) sendBlobsSidecar(ctx context.Context, topic string, reqData []byte, count uint64) ([]*cltypes.BlobSidecar, string, error) {
responses, pid, err := b.sendRequest(ctx, topic, reqData)
if err != nil {
return nil, pid, err
}
responsePacket := []*cltypes.BlobSidecar{}
for _, data := range responses {
responseChunk := &cltypes.BlobSidecar{}
if err := responseChunk.DecodeSSZ(data.raw, int(data.version)); err != nil {
return nil, pid, err
}
responsePacket = append(responsePacket, responseChunk)
}
return responsePacket, pid, nil
was accepted but never used - both callers correctly compute the expected max number of blob sidecars, but the result slice was initialized as an empty literal []*BlobSidecar{} ignoring this value entirely.

Use make([]*cltypes.BlobSidecar, 0, count) to preallocate the response slice, avoiding unnecessary grow-and-copy cycles during append.

}

responsePacket := []*cltypes.BlobSidecar{}
responsePacket := make([]*cltypes.BlobSidecar, 0, count)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count coming from outside of program. maybe from User/Attacker. Means can't use it as a parameter of pre-allocating - because it's attack-vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants