core/txpool: update GetBlobs code again

This commit is contained in:
Felix Lange 2025-09-19 14:03:10 +02:00
parent 1c766f4629
commit 0a407b0fd5

View file

@ -1347,13 +1347,14 @@ func (p *BlobPool) GetBlobs(vhashes []common.Hash, version byte, convert bool) (
for i, h := range vhashes { for i, h := range vhashes {
indices[h] = append(indices[h], i) indices[h] = append(indices[h], i)
} }
for _, vhash := range vhashes { for _, vhash := range vhashes {
// Skip duplicate vhash that was already resolved in a previous iteration
if _, ok := filled[vhash]; ok { if _, ok := filled[vhash]; ok {
// Skip vhash that was already resolved in a previous iteration
continue continue
} }
// Retrieve the corresponding blob tx with the vhash, skip blob resolution
// if it's not found locally and place the null instead. // Retrieve the corresponding blob tx with the vhash.
p.lock.RLock() p.lock.RLock()
txID, exists := p.lookup.storeidOfBlob(vhash) txID, exists := p.lookup.storeidOfBlob(vhash)
p.lock.RUnlock() p.lock.RUnlock()
@ -1383,41 +1384,46 @@ func (p *BlobPool) GetBlobs(vhashes []common.Hash, version byte, convert bool) (
if !ok { if !ok {
continue // non-interesting blob continue // non-interesting blob
} }
// Mark hash as seen.
filled[hash] = struct{}{}
if sidecar.Version != version && !convert {
// Skip blobs with incompatible version. Note we still track the blob hash
// in `filled` here, ensuring that we do not resolve this tx another time.
continue
}
// Get or convert the proof.
var pf []kzg4844.Proof var pf []kzg4844.Proof
if convert || sidecar.Version == version { switch version {
switch version { case types.BlobSidecarVersion0:
case types.BlobSidecarVersion0: if sidecar.Version == types.BlobSidecarVersion0 {
if sidecar.Version == types.BlobSidecarVersion0 { pf = []kzg4844.Proof{sidecar.Proofs[i]}
pf = []kzg4844.Proof{sidecar.Proofs[i]} } else {
} else { proof, err := kzg4844.ComputeBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i])
proof, err := kzg4844.ComputeBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i]) if err != nil {
if err != nil { return nil, nil, nil, err
return nil, nil, nil, err
}
pf = []kzg4844.Proof{proof}
}
case types.BlobSidecarVersion1:
if sidecar.Version == types.BlobSidecarVersion0 {
cellProofs, err := kzg4844.ComputeCellProofs(&sidecar.Blobs[i])
if err != nil {
return nil, nil, nil, err
}
pf = cellProofs
} else {
cellProofs, err := sidecar.CellProofsAt(i)
if err != nil {
return nil, nil, nil, err
}
pf = cellProofs
} }
pf = []kzg4844.Proof{proof}
} }
for _, index := range list { case types.BlobSidecarVersion1:
blobs[index] = &sidecar.Blobs[i] if sidecar.Version == types.BlobSidecarVersion0 {
commitments[index] = sidecar.Commitments[i] cellProofs, err := kzg4844.ComputeCellProofs(&sidecar.Blobs[i])
proofs[index] = pf if err != nil {
return nil, nil, nil, err
}
pf = cellProofs
} else {
cellProofs, err := sidecar.CellProofsAt(i)
if err != nil {
return nil, nil, nil, err
}
pf = cellProofs
} }
} }
filled[hash] = struct{}{} for _, index := range list {
blobs[index] = &sidecar.Blobs[i]
commitments[index] = sidecar.Commitments[i]
proofs[index] = pf
}
} }
} }
return blobs, commitments, proofs, nil return blobs, commitments, proofs, nil