Skip to content

Commit

Permalink
Add high-level client endpoint for retrieving encoded data
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyknox committed May 30, 2024
1 parent 5aecf5c commit 251d19a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 251d19a

Please sign in to comment.