diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index eaf95ba772..6a2bae14fe 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1333,9 +1333,9 @@ func (p *BlobPool) GetMetadata(hash common.Hash) *txpool.TxMetadata { // retrieve blobs from the pools directly instead of the network. // // The version argument specifies the type of proofs to return, either the -// blob proofs (version 0) or the cell proofs (version 1). Proofs are computed -// on-the-fly in case of a version mismatch. -func (p *BlobPool) GetBlobs(vhashes []common.Hash, version byte) ([]*kzg4844.Blob, []kzg4844.Commitment, [][]kzg4844.Proof, error) { +// blob proofs (version 0) or the cell proofs (version 1). Proofs conversion is +// CPU intensive, so only done if explicitly requested with the convert flag. +func (p *BlobPool) GetBlobs(vhashes []common.Hash, version byte, convert bool) ([]*kzg4844.Blob, []kzg4844.Commitment, [][]kzg4844.Proof, error) { var ( blobs = make([]*kzg4844.Blob, len(vhashes)) commitments = make([]kzg4844.Commitment, len(vhashes)) @@ -1384,6 +1384,9 @@ func (p *BlobPool) GetBlobs(vhashes []common.Hash, version byte) ([]*kzg4844.Blo continue // non-interesting blob } var pf []kzg4844.Proof + if !convert && sidecar.Version != version { + return nil, nil, nil, fmt.Errorf("blob sidecar version mismatch: want %d, have %d", version, sidecar.Version) + } switch version { case types.BlobSidecarVersion0: if sidecar.Version == types.BlobSidecarVersion0 { diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index e46529a241..b189d6395f 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -423,11 +423,11 @@ func verifyBlobRetrievals(t *testing.T, pool *BlobPool) { hashes = append(hashes, tx.vhashes...) } } - blobs1, _, proofs1, err := pool.GetBlobs(hashes, types.BlobSidecarVersion0) + blobs1, _, proofs1, err := pool.GetBlobs(hashes, types.BlobSidecarVersion0, true) if err != nil { t.Fatal(err) } - blobs2, _, proofs2, err := pool.GetBlobs(hashes, types.BlobSidecarVersion1) + blobs2, _, proofs2, err := pool.GetBlobs(hashes, types.BlobSidecarVersion1, true) if err != nil { t.Fatal(err) } @@ -2014,7 +2014,7 @@ func TestGetBlobs(t *testing.T) { filled[len(vhashes)] = struct{}{} vhashes = append(vhashes, testrand.Hash()) } - blobs, _, proofs, err := pool.GetBlobs(vhashes, c.version) + blobs, _, proofs, err := pool.GetBlobs(vhashes, c.version, true) if err != nil { t.Errorf("Unexpected error for case %d, %v", i, err) } diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index b222470228..8030410fc1 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -482,7 +482,7 @@ func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProo if len(hashes) > 128 { return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes))) } - blobs, _, proofs, err := api.eth.BlobTxPool().GetBlobs(hashes, types.BlobSidecarVersion0) + blobs, _, proofs, err := api.eth.BlobTxPool().GetBlobs(hashes, types.BlobSidecarVersion0, true) if err != nil { return nil, engine.InvalidParams.With(err) } @@ -542,7 +542,7 @@ func (api *ConsensusAPI) GetBlobsV2(hashes []common.Hash) ([]*engine.BlobAndProo return nil, nil } - blobs, _, proofs, err := api.eth.BlobTxPool().GetBlobs(hashes, types.BlobSidecarVersion1) + blobs, _, proofs, err := api.eth.BlobTxPool().GetBlobs(hashes, types.BlobSidecarVersion1, true) if err != nil { return nil, engine.InvalidParams.With(err) }