diff --git a/e2e/server_test.go b/e2e/server_test.go index 0b014fc8..bccd6592 100644 --- a/e2e/server_test.go +++ b/e2e/server_test.go @@ -1,8 +1,6 @@ package e2e_test import ( - "fmt" - "net/http" "strings" "testing" "time" @@ -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) } diff --git a/server/server.go b/server/server.go index 99193ba5..b374db7f 100644 --- a/server/server.go +++ b/server/server.go @@ -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" @@ -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 } diff --git a/store/eigenda.go b/store/eigenda.go index 428f25d9..624b8ce5 100644 --- a/store/eigenda.go +++ b/store/eigenda.go @@ -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() diff --git a/store/memory.go b/store/memory.go index a5ee8457..03b80f70 100644 --- a/store/memory.go +++ b/store/memory.go @@ -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() diff --git a/store/store.go b/store/store.go index 98d7a3f8..c48c89d7 100644 --- a/store/store.go +++ b/store/store.go @@ -2,6 +2,7 @@ package store import ( "context" + "fmt" "strings" ) @@ -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 { diff --git a/utils/utils.go b/utils/utils.go index ab9b4cfe..aa83aa95 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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 {