mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
core/types, internal/ethapi, signer/core/apitypes: avoid copying 128KB blobs in range loops (#33717)
kzg4844.Blob is 131072 bytes. Using `for _, blob := range` copies the entire blob on each iteration. With up to 6 blobs per transaction, this wastes ~768KB of memory copies. Switch to index-based iteration and pass pointers directly.
This commit is contained in:
parent
b9288765a3
commit
54a91b3ad8
3 changed files with 16 additions and 16 deletions
|
|
@ -118,8 +118,8 @@ func (sc *BlobTxSidecar) ToV1() error {
|
|||
}
|
||||
if sc.Version == BlobSidecarVersion0 {
|
||||
proofs := make([]kzg4844.Proof, 0, len(sc.Blobs)*kzg4844.CellProofsPerBlob)
|
||||
for _, blob := range sc.Blobs {
|
||||
cellProofs, err := kzg4844.ComputeCellProofs(&blob)
|
||||
for i := range sc.Blobs {
|
||||
cellProofs, err := kzg4844.ComputeCellProofs(&sc.Blobs[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,8 +329,8 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
|
|||
commitments = make([]kzg4844.Commitment, n)
|
||||
proofs = make([]kzg4844.Proof, 0, proofLen)
|
||||
)
|
||||
for i, b := range args.Blobs {
|
||||
c, err := kzg4844.BlobToCommitment(&b)
|
||||
for i := range args.Blobs {
|
||||
c, err := kzg4844.BlobToCommitment(&args.Blobs[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
|
||||
}
|
||||
|
|
@ -338,13 +338,13 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
|
|||
|
||||
switch config.blobSidecarVersion {
|
||||
case types.BlobSidecarVersion0:
|
||||
p, err := kzg4844.ComputeBlobProof(&b, c)
|
||||
p, err := kzg4844.ComputeBlobProof(&args.Blobs[i], c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
|
||||
}
|
||||
proofs = append(proofs, p)
|
||||
case types.BlobSidecarVersion1:
|
||||
ps, err := kzg4844.ComputeCellProofs(&b)
|
||||
ps, err := kzg4844.ComputeCellProofs(&args.Blobs[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
|
||||
}
|
||||
|
|
@ -356,8 +356,8 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
|
|||
} else {
|
||||
switch config.blobSidecarVersion {
|
||||
case types.BlobSidecarVersion0:
|
||||
for i, b := range args.Blobs {
|
||||
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
|
||||
for i := range args.Blobs {
|
||||
if err := kzg4844.VerifyBlobProof(&args.Blobs[i], args.Commitments[i], args.Proofs[i]); err != nil {
|
||||
return fmt.Errorf("failed to verify blob proof: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,8 +242,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
|||
if args.Proofs != nil {
|
||||
if len(args.Proofs) == n {
|
||||
// v1 transaction
|
||||
for i, b := range args.Blobs {
|
||||
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
|
||||
for i := range args.Blobs {
|
||||
if err := kzg4844.VerifyBlobProof(&args.Blobs[i], args.Commitments[i], args.Proofs[i]); err != nil {
|
||||
return fmt.Errorf("failed to verify blob proof: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -259,8 +259,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
|||
if args.Commitments == nil {
|
||||
// Generate commitment and proof.
|
||||
commitments := make([]kzg4844.Commitment, n)
|
||||
for i, b := range args.Blobs {
|
||||
c, err := kzg4844.BlobToCommitment(&b)
|
||||
for i := range args.Blobs {
|
||||
c, err := kzg4844.BlobToCommitment(&args.Blobs[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
|
||||
}
|
||||
|
|
@ -269,8 +269,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
|||
var proofs []kzg4844.Proof
|
||||
if args.BlobVersion == types.BlobSidecarVersion1 {
|
||||
proofs = make([]kzg4844.Proof, 0, n*kzg4844.CellProofsPerBlob)
|
||||
for i, b := range args.Blobs {
|
||||
p, err := kzg4844.ComputeCellProofs(&b)
|
||||
for i := range args.Blobs {
|
||||
p, err := kzg4844.ComputeCellProofs(&args.Blobs[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing cell proof: %v", i, err)
|
||||
}
|
||||
|
|
@ -278,8 +278,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
|||
}
|
||||
} else {
|
||||
proofs = make([]kzg4844.Proof, 0, n)
|
||||
for i, b := range args.Blobs {
|
||||
p, err := kzg4844.ComputeBlobProof(&b, commitments[i])
|
||||
for i := range args.Blobs {
|
||||
p, err := kzg4844.ComputeBlobProof(&args.Blobs[i], commitments[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue