Skip to content

Commit

Permalink
feat: Fault Testing Support - update client to not rely on Optimism d…
Browse files Browse the repository at this point in the history
…ependencies
  • Loading branch information
epociask committed Jul 2, 2024
1 parent 714a86b commit 3beaae8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 58 deletions.
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/Layr-Labs/eigenda-proxy/server"
"github.com/Layr-Labs/eigenda-proxy/common"
)

// TODO: Add support for custom http client option
Expand All @@ -19,7 +19,7 @@ type Config struct {
// ProxyClient is an interface for communicating with the EigenDA proxy server
type ProxyClient interface {
Health() error
GetData(ctx context.Context, cert []byte, domain server.DomainType) ([]byte, error)
GetData(ctx context.Context, cert []byte, domain common.DomainType) ([]byte, error)
SetData(ctx context.Context, b []byte) ([]byte, error)
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *client) Health() error {
}

// GetData fetches blob data associated with a DA certificate
func (c *client) GetData(ctx context.Context, comm []byte, domain server.DomainType) ([]byte, error) {
func (c *client) GetData(ctx context.Context, comm []byte, domain common.DomainType) ([]byte, error) {
url := fmt.Sprintf("%s/get/0x%x?domain=%s&commitment_mode=simple", c.cfg.URL, comm, domain.String())

if c.cfg.Actor != "" {
Expand Down
39 changes: 39 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package common

import "fmt"

var (
ErrInvalidDomainType = fmt.Errorf("invalid domain type")
)

// DomainType is a enumeration type for the different data domains for which a
// blob can exist between
type DomainType uint8

const (
BinaryDomain DomainType = iota
PolyDomain
UnknownDomain
)

func (d DomainType) String() string {
switch d {
case BinaryDomain:
return "binary"
case PolyDomain:
return "polynomial"
default:
return "unknown"
}
}

func StrToDomainType(s string) DomainType {
switch s {
case "binary":
return BinaryDomain
case "polynomial":
return PolyDomain
default:
return UnknownDomain
}
}
10 changes: 5 additions & 5 deletions e2e/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"time"

"github.com/Layr-Labs/eigenda-proxy/client"
"github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/fault"
"github.com/Layr-Labs/eigenda-proxy/server"

"github.com/Layr-Labs/eigenda-proxy/e2e"
"github.com/Layr-Labs/eigenda/api/clients/codecs"
Expand Down Expand Up @@ -86,12 +86,12 @@ func TestProxyClient(t *testing.T) {

// 2 - fetch data from EigenDA for generated commitment key
t.Log("Getting input data from proxy server...")
preimage, err := daClient.GetData(ts.Ctx, blobInfo, server.BinaryDomain)
preimage, err := daClient.GetData(ts.Ctx, blobInfo, common.BinaryDomain)
require.NoError(t, err)
require.Equal(t, testPreimage, preimage)

// 3 - fetch iFFT representation of preimage
iFFTPreimage, err := daClient.GetData(ts.Ctx, blobInfo, server.PolyDomain)
iFFTPreimage, err := daClient.GetData(ts.Ctx, blobInfo, common.PolyDomain)
require.NoError(t, err)
require.NotEqual(t, preimage, iFFTPreimage)

Expand Down Expand Up @@ -149,12 +149,12 @@ func TestProxyClientWithFaultMode(t *testing.T) {

// 2 - fetch data from EigenDA for generated commitment key
t.Log("Getting input data from proxy server...")
preimage, err := sequencerClient.GetData(ts.Ctx, blobInfo, server.BinaryDomain)
preimage, err := sequencerClient.GetData(ts.Ctx, blobInfo, common.BinaryDomain)
require.NoError(t, err)
require.Equal(t, testPreimage, preimage)

// 3 - fetch iFFT representation of preimage
preimage, err = challengerClient.GetData(ts.Ctx, blobInfo, server.PolyDomain)
preimage, err = challengerClient.GetData(ts.Ctx, blobInfo, common.PolyDomain)
require.NoError(t, err)
require.NotEqual(t, testPreimage, preimage)
}
47 changes: 6 additions & 41 deletions server/domain_type.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
package server

import (
"fmt"
"net/http"
)

var (
ErrInvalidDomainType = fmt.Errorf("invalid domain type")
"github.com/Layr-Labs/eigenda-proxy/common"
)

// DomainType is a enumeration type for the different data domains for which a
// blob can exist between
type DomainType uint8

const (
BinaryDomain DomainType = iota
PolyDomain
UnknownDomain
)

func (d DomainType) String() string {
switch d {
case BinaryDomain:
return "binary"
case PolyDomain:
return "polynomial"
default:
return "unknown"
}
}

func StrToDomainType(s string) DomainType {
switch s {
case "binary":
return BinaryDomain
case "polynomial":
return PolyDomain
default:
return UnknownDomain
}
}

func ReadDomainFilter(r *http.Request) (DomainType, error) {
func ReadDomainFilter(r *http.Request) (common.DomainType, error) {
query := r.URL.Query()
key := query.Get(DomainFilterKey)
if key == "" { // default
return BinaryDomain, nil
return common.BinaryDomain, nil
}
dt := StrToDomainType(key)
if dt == UnknownDomain {
return UnknownDomain, ErrInvalidDomainType
dt := common.StrToDomainType(key)
if dt == common.UnknownDomain {
return common.UnknownDomain, common.ErrInvalidDomainType
}

return dt, nil
Expand Down
7 changes: 4 additions & 3 deletions server/eigenda_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

proxy_common "github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/api/clients"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewEigenDAStore(ctx context.Context, client *clients.EigenDAClient, v *veri

// Get fetches a blob from DA using certificate fields and verifies blob
// against commitment to ensure data is valid and non-tampered.
func (e EigenDAStore) Get(ctx context.Context, key []byte, domain DomainType) ([]byte, error) {
func (e EigenDAStore) Get(ctx context.Context, key []byte, domain proxy_common.DomainType) ([]byte, error) {
var cert verify.Certificate
err := rlp.DecodeBytes(key, &cert)
if err != nil {
Expand All @@ -64,9 +65,9 @@ func (e EigenDAStore) Get(ctx context.Context, key []byte, domain DomainType) ([
}

switch domain {
case BinaryDomain:
case proxy_common.BinaryDomain:
return decodedBlob, nil
case PolyDomain:
case proxy_common.PolyDomain:
return encodedBlob, nil
default:
return nil, fmt.Errorf("unexpected domain type: %d", domain)
Expand Down
7 changes: 4 additions & 3 deletions server/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

proxy_common "github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/fault"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (e *MemStore) pruneExpired() {
}

// Get fetches a value from the store.
func (e *MemStore) Get(ctx context.Context, commit []byte, domain DomainType) ([]byte, error) {
func (e *MemStore) Get(ctx context.Context, commit []byte, domain proxy_common.DomainType) ([]byte, error) {
e.reads += 1
e.RLock()
defer e.RUnlock()
Expand All @@ -118,9 +119,9 @@ func (e *MemStore) Get(ctx context.Context, commit []byte, domain DomainType) ([
}

switch domain {
case BinaryDomain:
case proxy_common.BinaryDomain:
return e.codec.DecodeBlob(encodedBlob)
case PolyDomain:
case proxy_common.PolyDomain:
return encodedBlob, nil
default:
return nil, fmt.Errorf("unexpected domain type: %d", domain)
Expand Down
5 changes: 3 additions & 2 deletions server/memory_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

proxy_common "github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestGetSet(t *testing.T) {
key, err := ms.Put(ctx, expected)
assert.NoError(t, err)

actual, err := ms.Get(ctx, key, BinaryDomain)
actual, err := ms.Get(ctx, key, proxy_common.BinaryDomain)
assert.NoError(t, err)
assert.Equal(t, actual, expected)
}
Expand Down Expand Up @@ -98,7 +99,7 @@ func TestExpiration(t *testing.T) {
// sleep 1 second and verify that older blob entries are removed
time.Sleep(time.Second * 1)

_, err = ms.Get(ctx, key, BinaryDomain)
_, err = ms.Get(ctx, key, proxy_common.BinaryDomain)
assert.Error(t, err)

}
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"time"

"github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -33,7 +34,7 @@ const (

type Store interface {
// Get retrieves the given key if it's present in the key-value data store.
Get(ctx context.Context, key []byte, domain DomainType) ([]byte, error)
Get(ctx context.Context, key []byte, domain common.DomainType) ([]byte, error)
// Put inserts the given value into the key-value data store.
Put(ctx context.Context, value []byte) (key []byte, err error)
// Stats returns the current usage metrics of the key-value data store.
Expand Down

0 comments on commit 3beaae8

Please sign in to comment.