Skip to content

Commit

Permalink
Remove cert concept in favor of BlobInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyknox committed May 22, 2024
1 parent 4e59c15 commit a8b6239
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 99 deletions.
13 changes: 0 additions & 13 deletions api/clients/cert.go

This file was deleted.

36 changes: 0 additions & 36 deletions api/clients/cert_test.go

This file was deleted.

24 changes: 6 additions & 18 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)
PutBlob(ctx context.Context, txData []byte) (*Cert, error)
PutBlob(ctx context.Context, txData []byte) (*grpcdisperser.BlobInfo, error)
}

type EigenDAClient struct {
Expand Down Expand Up @@ -80,7 +80,7 @@ func (m EigenDAClient) GetBlob(ctx context.Context, BatchHeaderHash []byte, Blob
return rawData, nil
}

func (m EigenDAClient) PutBlob(ctx context.Context, data []byte) (*Cert, error) {
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
case result := <-resultChan:
Expand All @@ -90,14 +90,14 @@ func (m EigenDAClient) PutBlob(ctx context.Context, data []byte) (*Cert, error)
}
}

func (m EigenDAClient) PutBlobAsync(ctx context.Context, data []byte) (resultChan chan *Cert, errChan chan error) {
resultChan = make(chan *Cert, 1)
func (m EigenDAClient) PutBlobAsync(ctx context.Context, data []byte) (resultChan chan *grpcdisperser.BlobInfo, errChan chan error) {
resultChan = make(chan *grpcdisperser.BlobInfo, 1)
errChan = make(chan error, 1)
go m.putBlob(ctx, data, resultChan, errChan)
return
}

func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan chan *Cert, errChan chan error) {
func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan chan *grpcdisperser.BlobInfo, errChan chan error) {
m.Log.Info("Attempting to disperse blob to EigenDA")

// encode blob
Expand Down Expand Up @@ -164,19 +164,7 @@ func (m EigenDAClient) putBlob(ctx context.Context, rawData []byte, resultChan c
case grpcdisperser.BlobStatus_FINALIZED:
batchHeaderHashHex := fmt.Sprintf("0x%s", hex.EncodeToString(statusRes.Info.BlobVerificationProof.BatchMetadata.BatchHeaderHash))
m.Log.Info("Successfully dispersed blob to EigenDA", "requestID", base64RequestID, "batchHeaderHash", batchHeaderHashHex)
blobInfo := statusRes.Info
quorumIDs := make([]uint32, len(blobInfo.BlobHeader.BlobQuorumParams))
for i := range quorumIDs {
quorumIDs[i] = blobInfo.BlobHeader.BlobQuorumParams[i].QuorumNumber
}
cert := &Cert{
BatchHeaderHash: blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash,
BlobIndex: blobInfo.BlobVerificationProof.BlobIndex,
ReferenceBlockNumber: blobInfo.BlobVerificationProof.BatchMetadata.BatchHeader.ReferenceBlockNumber,
QuorumIDs: quorumIDs,
BlobCommitment: blobInfo.BlobHeader.Commitment,
}
resultChan <- cert
resultChan <- statusRes.Info
return
default:
errChan <- fmt.Errorf("EigenDA blob dispersal failed in processing with reply status %d", statusRes.Status)
Expand Down
48 changes: 18 additions & 30 deletions api/clients/eigenda_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ func TestPutRetrieveBlobSuccess(t *testing.T) {
PutCodec: clients.DefaultBlobEncodingCodec{},
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
cert, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
require.NoError(t, err)
require.NotNil(t, cert)
assert.Equal(t, &clients.Cert{
BatchHeaderHash: []byte("mock-batch-header-hash"),
BlobIndex: 100,
ReferenceBlockNumber: 200,
QuorumIDs: []uint32{0, 1},
BlobCommitment: &common.G1Commitment{X: []byte{0x00, 0x00, 0x00, 0x00}, Y: []byte{0x01, 0x00, 0x00, 0x00}},
}, cert)
require.NotNil(t, blobInfo)
assert.Equal(t, finalizedBlobInfo, blobInfo)

resultBlob, err := eigendaClient.GetBlob(context.Background(), []byte("mock-batch-header-hash"), 100)
require.NoError(t, err)
Expand All @@ -107,9 +101,9 @@ func TestPutBlobFailDispersal(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}

func TestPutBlobFailureInsufficentSignatures(t *testing.T) {
Expand Down Expand Up @@ -139,9 +133,9 @@ func TestPutBlobFailureInsufficentSignatures(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}

func TestPutBlobFailureGeneral(t *testing.T) {
Expand Down Expand Up @@ -171,9 +165,9 @@ func TestPutBlobFailureGeneral(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}

func TestPutBlobFailureUnknown(t *testing.T) {
Expand Down Expand Up @@ -203,9 +197,9 @@ func TestPutBlobFailureUnknown(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}

func TestPutBlobFinalizationTimeout(t *testing.T) {
Expand Down Expand Up @@ -237,9 +231,9 @@ func TestPutBlobFinalizationTimeout(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}

func TestPutBlobIndividualRequestTimeout(t *testing.T) {
Expand Down Expand Up @@ -296,18 +290,12 @@ func TestPutBlobIndividualRequestTimeout(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

// despite initial timeout it should succeed
require.NoError(t, err)
require.NotNil(t, cert)
assert.Equal(t, &clients.Cert{
BatchHeaderHash: []byte("mock-batch-header-hash"),
BlobIndex: 100,
ReferenceBlockNumber: 200,
QuorumIDs: []uint32{0, 1},
BlobCommitment: &common.G1Commitment{X: []byte{0x00, 0x00, 0x00, 0x00}, Y: []byte{0x01, 0x00, 0x00, 0x00}},
}, cert)
require.NotNil(t, blobInfo)
assert.Equal(t, finalizedBlobInfo, blobInfo)
}

func TestPutBlobTotalTimeout(t *testing.T) {
Expand Down Expand Up @@ -364,9 +352,9 @@ func TestPutBlobTotalTimeout(t *testing.T) {
Client: disperserClient,
PutCodec: clients.DefaultBlobEncodingCodec{},
}
cert, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

// should timeout even though it would have finalized eventually
require.Error(t, err)
require.Nil(t, cert)
require.Nil(t, blobInfo)
}
6 changes: 4 additions & 2 deletions api/clients/eigenda_client_testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func TestClientUsingTestnet(t *testing.T) {
})
data := "hello world!"
assert.NoError(t, err)
cert, err := client.PutBlob(context.Background(), []byte(data))
blobInfo, err := client.PutBlob(context.Background(), []byte(data))
assert.NoError(t, err)
blob, err := client.GetBlob(context.Background(), cert.BatchHeaderHash, cert.BlobIndex)
batchHeaderHash := blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash
blobIndex := blobInfo.BlobVerificationProof.BlobIndex
blob, err := client.GetBlob(context.Background(), batchHeaderHash, blobIndex)
assert.NoError(t, err)
assert.Equal(t, data, string(blob))
}

0 comments on commit a8b6239

Please sign in to comment.