Skip to content

Commit

Permalink
fix: Return 400 when blobs exceed max limit - address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Sep 20, 2024
1 parent f5d7d8a commit 97c51a0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
4 changes: 1 addition & 3 deletions e2e/server_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2e_test

import (
"fmt"
"net/http"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -187,7 +185,7 @@ func TestProxyServerWithOversizedBlob(t *testing.T) {
}

require.True(t, oversizedError)
require.Contains(t, err.Error(), fmt.Sprint(http.StatusBadRequest))
require.ErrorIs(t, err, store.ErrProxyOversizedBlob, store.ErrEigenDAOversizedBlob)

}

Expand Down
5 changes: 3 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/Layr-Labs/eigenda-proxy/commitments"
"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/utils"
"github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -220,7 +219,9 @@ func (svr *Server) HandlePut(w http.ResponseWriter, r *http.Request) (commitment
if err != nil {
err = fmt.Errorf("put request failed with commitment %v (commitment mode %v): %w", comm, meta.Mode, err)

if utils.ErrorMessageContainsAny(err, store.OversizedEigenDAError, store.OversizedProxyError) {
if errors.Is(err, store.ErrEigenDAOversizedBlob) || errors.Is(err, store.ErrProxyOversizedBlob) {
// we add here any error that should be returned as a 400 instead of a 500.
// currently only includes oversized blob requests
svr.WriteBadRequest(w, err)
return meta, err
}
Expand Down
2 changes: 1 addition & 1 deletion store/eigenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e EigenDAStore) Put(ctx context.Context, value []byte) ([]byte, error) {
return nil, fmt.Errorf("EigenDA client failed to re-encode blob: %w", err)
}
if uint64(len(encodedBlob)) > e.cfg.MaxBlobSizeBytes {
return nil, fmt.Errorf("%s: blob length %d, max blob size %d", OversizedProxyError, len(value), e.cfg.MaxBlobSizeBytes)
return nil, fmt.Errorf("%w: blob length %d, max blob size %d", ErrProxyOversizedBlob, len(value), e.cfg.MaxBlobSizeBytes)
}

dispersalStart := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion store/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (e *MemStore) Get(_ context.Context, commit []byte) ([]byte, error) {
func (e *MemStore) Put(_ context.Context, value []byte) ([]byte, error) {
time.Sleep(e.config.PutLatency)
if uint64(len(value)) > e.config.MaxBlobSizeBytes {
return nil, fmt.Errorf("%s: blob length %d, max blob size %d", OversizedProxyError, len(value), e.config.MaxBlobSizeBytes)
return nil, fmt.Errorf("%w: blob length %d, max blob size %d", ErrProxyOversizedBlob, len(value), e.config.MaxBlobSizeBytes)
}

e.Lock()
Expand Down
7 changes: 4 additions & 3 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package store

import (
"context"
"fmt"
"strings"
)

Expand All @@ -16,9 +17,9 @@ const (
Unknown
)

const (
OversizedProxyError = "encoded blob is larger than max blob size"
OversizedEigenDAError = "blob size cannot exceed"
var (
ErrProxyOversizedBlob = fmt.Errorf("encoded blob is larger than max blob size")
ErrEigenDAOversizedBlob = fmt.Errorf("blob size cannot exceed")
)

func (b BackendType) String() string {
Expand Down
15 changes: 0 additions & 15 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ import (

// Helper utility functions //

func ErrorMessageContainsAny(err error, msgs ...string) bool {
if err == nil {
return false
}

errMsg := err.Error()
for _, str := range msgs {
if strings.Contains(errMsg, str) {
return true
}
}

return false
}

func ContainsDuplicates[P comparable](s []P) bool {
seen := make(map[P]struct{})
for _, v := range s {
Expand Down

0 comments on commit 97c51a0

Please sign in to comment.