From 251d19a2bef91145d91b210606c58edc1cdce97c Mon Sep 17 00:00:00 2001 From: Teddy Knox Date: Thu, 30 May 2024 15:33:11 -0400 Subject: [PATCH] Add high-level client endpoint for retrieving encoded data --- api/clients/eigenda_client.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/api/clients/eigenda_client.go b/api/clients/eigenda_client.go index 48e015c77b..76f8920c6a 100644 --- a/api/clients/eigenda_client.go +++ b/api/clients/eigenda_client.go @@ -16,7 +16,7 @@ import ( ) type IEigenDAClient interface { - GetBlob(ctx context.Context, BatchHeaderHash []byte, BlobIndex uint32) ([]byte, error) + GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32, decode bool) ([]byte, error) PutBlob(ctx context.Context, txData []byte) (*grpcdisperser.BlobInfo, error) } @@ -57,8 +57,14 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien }, nil } -func (m EigenDAClient) GetBlob(ctx context.Context, BatchHeaderHash []byte, BlobIndex uint32) ([]byte, error) { - data, err := m.Client.RetrieveBlob(ctx, BatchHeaderHash, BlobIndex) +// GetBlob retrieves a blob from the EigenDA service using the provided context, +// batch header hash, and blob index. If decode is set to true, the function +// decodes the retrieved blob data. If set to false it returns the encoded blob +// data, which is necessary for generating KZG proofs for data's correctness. +// The function handles potential errors during blob retrieval, data length +// checks, and decoding processes. +func (m EigenDAClient) GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32, decode bool) ([]byte, error) { + data, err := m.Client.RetrieveBlob(ctx, batchHeaderHash, blobIndex) if err != nil { return nil, err } @@ -67,6 +73,10 @@ func (m EigenDAClient) GetBlob(ctx context.Context, BatchHeaderHash []byte, Blob return nil, fmt.Errorf("blob has length zero") } + if !decode { + return data, nil + } + if !m.Config.DisablePointVerificationMode { // we assume the data is already IFFT'd so we FFT it before decoding data, err = FFT(data) @@ -94,6 +104,9 @@ func (m EigenDAClient) GetBlob(ctx context.Context, BatchHeaderHash []byte, Blob return decodedData, nil } +// PutBlob encodes and writes a blob to EigenDA, waiting for it to be finalized +// before returning. This function is resiliant to transient failures and +// timeouts. func (m EigenDAClient) PutBlob(ctx context.Context, data []byte) (*grpcdisperser.BlobInfo, error) { resultChan, errorChan := m.PutBlobAsync(ctx, data) select { // no timeout here because we depend on the configured timeout in PutBlobAsync