Skip to content

Commit

Permalink
Merge pull request #191 from mantlenetworkio/feature/eigenda_GetBlobE…
Browse files Browse the repository at this point in the history
…xtraInfo

add method GetBlobExtraInfo
  • Loading branch information
adam-xu-mantle authored Jan 16, 2025
2 parents c77cb6e + 275af8d commit 20ec53d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions op-service/eigenda/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type IEigenDA interface {
RetrieveBlobWithCommitment(ctx context.Context, commitment []byte) ([]byte, error)
DisperseBlob(ctx context.Context, txData []byte) (*disperser.BlobInfo, error)
GetBlobStatus(ctx context.Context, requestID []byte) (*disperser.BlobStatusReply, error)
GetBlobExtraInfo(ctx context.Context, commitment []byte) (map[string]interface{}, error)
}
44 changes: 44 additions & 0 deletions op-service/eigenda/da_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/tls"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -195,6 +196,49 @@ func (c *EigenDAClient) GetBlobStatus(ctx context.Context, requestID []byte) (*d
return statusRes, nil
}

// GetBlobExtraInfo returns the extra data for the given encoded commitment bytes.
// Currently, it only returns request_id.
func (c *EigenDAClient) GetBlobExtraInfo(ctx context.Context, commitment []byte) (map[string]interface{}, error) {
c.log.Info("Attempting to retrieve blob extra info with commitment", "commitment", hex.EncodeToString(commitment))
blobInfo, err := DecodeCommitment(commitment)
if err != nil {
return nil, fmt.Errorf("failed to decode commitment: %w", err)
}
c.log.Info("Blob info", "BatchHeaderHash", hex.EncodeToString(blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash), "blobIndex", blobInfo.BlobVerificationProof.BlobIndex)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/get_extra/0x%x", c.proxyUrl, commitment), nil)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
done := c.recordInterval("GetBlobExtraInfo")
resp, err := c.retrieveClient.Do(req)
err = func() error {
if err != nil {
return err
}
if resp.StatusCode == http.StatusNotFound {
return ErrNotFound
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to get extra info: %v", resp.StatusCode)
}
return nil
}()
done(err)
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

output := make(map[string]interface{})
json.Unmarshal(data, &output)

return output, nil
}

func (m *EigenDAClient) recordInterval(method string) func(error) {
if m.metricer == nil {
return func(err error) {}
Expand Down
60 changes: 60 additions & 0 deletions op-service/eigenda/da_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import (
"fmt"
"reflect"
"testing"
"time"

"github.com/Layr-Labs/eigenda/api/grpc/common"
"github.com/Layr-Labs/eigenda/api/grpc/disperser"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)

type mockMetrics struct{}

func (m *mockMetrics) RecordInterval(method string) func(error) {
return func(error) {}
}

func TestNewEigenDAProxy_RetrieveBlob(t *testing.T) {
requestId := make([]byte, 189)
_, _ = base64.StdEncoding.Decode(requestId, []byte("YTU3NWE0ZWY5MGY5NTU5ZWVlYTg2Nzg5NzJkNTAxMzllODBjNDExNjBlMGQ1NmU2ZTc3MWJkNjdmZmMxMzQxMy0zMTM3MzIzNzM2MzAzMzMwMzUzNTM0MzgzMTM5MzEzMDM2MzIzODJmMzEyZjMzMzMyZjMwMmYzMzMzMmZlM2IwYzQ0Mjk4ZmMxYzE0OWFmYmY0Yzg5OTZmYjkyNDI3YWU0MWU0NjQ5YjkzNGNhNDk1OTkxYjc4NTJiODU1"))
Expand Down Expand Up @@ -198,3 +207,54 @@ func TestNewEigenDAProxy_GetBlobStatus(t *testing.T) {
})
}
}

func TestGetBlobExtraInfo(t *testing.T) {
cfg := Config{
ProxyUrl: "http://localhost:3100",
DisperserUrl: "disperser-holesky.eigenda.xyz:443",
DisperseBlobTimeout: 10 * time.Minute,
RetrieveBlobTimeout: 10 * time.Second,
}
logger := log.New()
metrics := &mockMetrics{}
client := NewEigenDAClient(cfg, logger, metrics)

t.Run("GetBlobExtraInfo with valid commitment", func(t *testing.T) {
ctx := context.Background()
// test1: DisperseBlob then GetBlobExtraInfo
blob := []byte("test data")
blobInfo, err := client.DisperseBlob(ctx, blob)
require.NoError(t, err)

commitment, err := EncodeCommitment(blobInfo)
require.NoError(t, err)

extraInfo, err := client.GetBlobExtraInfo(ctx, commitment)
require.NoError(t, err)
require.NotEmpty(t, extraInfo)
})

t.Run("GetBlobExtraInfo with zero commitment", func(t *testing.T) {
ctx := context.Background()
// test1: Encode zero value commitment
zeroBlobInfo := &disperser.BlobInfo{
BlobHeader: &disperser.BlobHeader{
Commitment: &common.G1Commitment{},
},
BlobVerificationProof: &disperser.BlobVerificationProof{
BatchMetadata: &disperser.BatchMetadata{
BatchHeader: &disperser.BatchHeader{},
BatchHeaderHash: make([]byte, 32),
},
BlobIndex: 0,
},
}
commitment, err := EncodeCommitment(zeroBlobInfo)
require.NoError(t, err)
t.Logf("commitment: %x", commitment)
extraInfo, err := client.GetBlobExtraInfo(ctx, commitment)
require.NoError(t, err)
t.Logf("extraInfo: %v", extraInfo)
require.Empty(t, extraInfo)
})
}

0 comments on commit 20ec53d

Please sign in to comment.