Skip to content

Commit

Permalink
Combine codec files
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <[email protected]>
  • Loading branch information
litt3 committed Jan 15, 2025
1 parent 12cb664 commit 908c518
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 165 deletions.
77 changes: 0 additions & 77 deletions api/clients/codecs/blob_codec.go

This file was deleted.

49 changes: 0 additions & 49 deletions api/clients/codecs/blob_codec_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions api/clients/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Layr-Labs/eigenda/api/clients/codecs"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
)

type EigenDAClientConfig struct {
Expand Down Expand Up @@ -64,7 +64,7 @@ type EigenDAClientConfig struct {
DisableTLS bool

// The blob encoding version to use when writing blobs from the high level interface.
PutBlobEncodingVersion codecs.BlobEncodingVersion
PutBlobEncodingVersion codec.BlobEncodingVersion

// Point verification mode does an IFFT on data before it is written, and does an FFT on data after it is read.
// This makes it possible to open points on the KZG commitment to prove that the field elements correspond to
Expand Down
30 changes: 15 additions & 15 deletions api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"net"
"time"

"github.com/Layr-Labs/eigenda/encoding/utils/codec"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"

"github.com/Layr-Labs/eigenda/api"
"github.com/Layr-Labs/eigenda/api/clients/codecs"
grpcdisperser "github.com/Layr-Labs/eigenda/api/grpc/disperser"
edasm "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
"github.com/Layr-Labs/eigenda/core"
Expand All @@ -28,7 +28,7 @@ import (
type IEigenDAClient interface {
GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32) ([]byte, error)
PutBlob(ctx context.Context, txData []byte) (*grpcdisperser.BlobInfo, error)
GetPolynomialForm() codecs.PolynomialForm
GetPolynomialForm() codec.PolynomialForm
Close() error
}

Expand All @@ -44,7 +44,7 @@ type EigenDAClient struct {
Client DisperserClient
ethClient *ethclient.Client
edasmCaller *edasm.ContractEigenDAServiceManagerCaller
PolynomialForm codecs.PolynomialForm
PolynomialForm codec.PolynomialForm
}

var _ IEigenDAClient = &EigenDAClient{}
Expand Down Expand Up @@ -115,11 +115,11 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien
return nil, fmt.Errorf("new disperser-client: %w", err)
}

var polynomialForm codecs.PolynomialForm
var polynomialForm codec.PolynomialForm
if config.DisablePointVerificationMode {
polynomialForm = codecs.Eval
polynomialForm = codec.Eval
} else {
polynomialForm = codecs.Coeff
polynomialForm = codec.Coeff
}

return &EigenDAClient{
Expand All @@ -136,7 +136,7 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien
//
// The polynomial form indicates how blobs must be constructed before dispersal, and how received blobs ought to be
// interpreted.
func (m *EigenDAClient) GetPolynomialForm() codecs.PolynomialForm {
func (m *EigenDAClient) GetPolynomialForm() codec.PolynomialForm {
return m.PolynomialForm
}

Expand All @@ -163,7 +163,7 @@ func (m *EigenDAClient) GetBlob(ctx context.Context, batchHeaderHash []byte, blo
return nil, fmt.Errorf("blob to encoded payload: %w", err)
}

decodedPayload, err := codecs.DecodePayload(encodedPayload)
decodedPayload, err := codec.DecodePayload(encodedPayload)
if err != nil {
return nil, fmt.Errorf("error decoding payload: %w", err)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func (m *EigenDAClient) PutBlobAsync(ctx context.Context, data []byte) (resultCh
func (m *EigenDAClient) putBlob(ctxFinality context.Context, rawData []byte, resultChan chan *grpcdisperser.BlobInfo, errChan chan error) {
m.Log.Info("Attempting to disperse blob to EigenDA")

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

if err != nil {
Expand Down Expand Up @@ -417,10 +417,10 @@ func (m *EigenDAClient) batchIdConfirmedAtDepth(ctx context.Context, batchId uin
// 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:
case codec.Eval:
return blob, nil
case codecs.Coeff:
encodedPayload, err := codecs.FFT(blob)
case codec.Coeff:
encodedPayload, err := codec.FFT(blob)
if err != nil {
return nil, fmt.Errorf("fft: %w", err)
}
Expand All @@ -437,10 +437,10 @@ func (m *EigenDAClient) blobToEncodedPayload(blob []byte) ([]byte, error) {
// 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:
case codec.Eval:
return encodedPayload, nil
case codecs.Coeff:
coeffPolynomial, err := codecs.IFFT(encodedPayload)
case codec.Coeff:
coeffPolynomial, err := codec.IFFT(encodedPayload)
if err != nil {
return nil, fmt.Errorf("ifft: %w", err)
}
Expand Down
38 changes: 19 additions & 19 deletions api/clients/eigenda_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"time"

"github.com/Layr-Labs/eigenda/api/clients"
"github.com/Layr-Labs/eigenda/api/clients/codecs"
clientsmock "github.com/Layr-Labs/eigenda/api/clients/mock"
"github.com/Layr-Labs/eigenda/api/grpc/common"
grpcdisperser "github.com/Layr-Labs/eigenda/api/grpc/disperser"
"github.com/Layr-Labs/eigenda/disperser"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -66,12 +66,12 @@ func TestPutRetrieveBlobIFFTSuccess(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
DisablePointVerificationMode: false,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
Expand Down Expand Up @@ -132,12 +132,12 @@ func TestPutRetrieveBlobNoIFFTSuccess(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
DisablePointVerificationMode: true,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Eval,
PolynomialForm: codec.Eval,
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
Expand Down Expand Up @@ -165,11 +165,11 @@ func TestPutBlobFailDispersal(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -198,11 +198,11 @@ func TestPutBlobFailureInsufficentSignatures(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -231,11 +231,11 @@ func TestPutBlobFailureGeneral(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -264,11 +264,11 @@ func TestPutBlobFailureUnknown(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -299,11 +299,11 @@ func TestPutBlobFinalizationTimeout(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -359,11 +359,11 @@ func TestPutBlobIndividualRequestTimeout(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

Expand Down Expand Up @@ -422,11 +422,11 @@ func TestPutBlobTotalTimeout(t *testing.T) {
CustomQuorumIDs: []uint{},
SignerPrivateKeyHex: "75f9e29cac7f5774d106adb355ef294987ce39b7863b75bb3f2ea42ca160926d",
DisableTLS: false,
PutBlobEncodingVersion: codecs.BlobEncodingVersion0,
PutBlobEncodingVersion: codec.BlobEncodingVersion0,
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
PolynomialForm: codec.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

Expand Down
Loading

0 comments on commit 908c518

Please sign in to comment.