Skip to content

Commit

Permalink
Improve client docs and naming
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
  • Loading branch information
litt3 committed Jan 14, 2025
1 parent f5e1731 commit f4bd98c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ func (m *EigenDAClient) GetBlob(ctx context.Context, batchHeaderHash []byte, blo
return nil, fmt.Errorf("blob has length zero - this should not be possible")
}

encodedBlob, err := m.receivePolynomial(data)
encodedPayload, err := m.blobToEncodedPayload(data)
if err != nil {
return nil, fmt.Errorf("receive polynomial: %w", err)
}

decodedData, err := codecs.DecodePayload(encodedBlob)
decodedPayload, err := codecs.DecodePayload(encodedPayload)
if err != nil {
return nil, fmt.Errorf("error decoding blob: %w", err)
return nil, fmt.Errorf("error decoding payload: %w", err)
}

return decodedData, nil
return decodedPayload, nil
}

// PutBlob encodes and writes a blob to EigenDA, waiting for a desired blob status
Expand Down Expand Up @@ -224,7 +224,7 @@ func (m *EigenDAClient) putBlob(
m.Log.Info("Attempting to disperse blob to EigenDA")

encodedPayload := codecs.EncodePayload(rawData)
polynomial, err := m.preparePolynomial(encodedPayload)
blob, err := m.encodedPayloadToBlob(encodedPayload)

if err != nil {
// Encode can only fail if there is something wrong with the data, so we return a 400 error
Expand All @@ -239,7 +239,7 @@ func (m *EigenDAClient) putBlob(
// disperse blob
// TODO: would be nice to add a trace-id key to the context, to be able to follow requests from batcher->proxy->eigenda
// clients with a payment signer setting can disperse paid blobs
_, requestID, err := m.Client.DisperseBlobAuthenticated(ctxFinality, polynomial, customQuorumNumbers)
_, requestID, err := m.Client.DisperseBlobAuthenticated(ctxFinality, blob, customQuorumNumbers)
if err != nil {
// DisperserClient returned error is already a grpc error which can be a 400 (eg rate limited) or 500,
// so we wrap the error such that clients can still use grpc's status.FromError() function to get the status code.
Expand Down Expand Up @@ -478,12 +478,16 @@ func (m EigenDAClient) batchIdConfirmedAtDepth(ctx context.Context, batchId uint
return true, nil
}

func (m EigenDAClient) receivePolynomial(receivedPolynomial []byte) ([]byte, error) {
// blobToEncodedPayload accepts blob bytes and converts them into an encoded payload
//
// If the system is configured to distribute blobs in Eval form, the returned bytes exactly match the blob bytes.
// If the system is configured to distribute blobs in Coeff form, the blob is FFTed before being returned
func (m EigenDAClient) blobToEncodedPayload(blob []byte) ([]byte, error) {
switch m.polynomialForm {
case codecs.Eval:
return receivedPolynomial, nil
return blob, nil
case codecs.Coeff:
encodedPayload, err := codecs.FFT(receivedPolynomial)
encodedPayload, err := codecs.FFT(blob)
if err != nil {
return nil, fmt.Errorf("fft: %w", err)
}
Expand All @@ -494,7 +498,11 @@ func (m EigenDAClient) receivePolynomial(receivedPolynomial []byte) ([]byte, err
}
}

func (m EigenDAClient) preparePolynomial(encodedPayload []byte) ([]byte, error) {
// encodedPayloadToBlob accepts encoded payload bytes and converts them into a blob
//
// If the system is configured to distribute blobs in Eval form, the returned bytes exactly match the input bytes
// If the system is configured to distribute blobs in Coeff form, the encoded payload is IFFTed before being returned
func (m EigenDAClient) encodedPayloadToBlob(encodedPayload []byte) ([]byte, error) {
switch m.polynomialForm {
case codecs.Eval:
return encodedPayload, nil
Expand Down

0 comments on commit f4bd98c

Please sign in to comment.