Skip to content

Commit

Permalink
fix: Return 400 when blobs exceed max limit (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask authored Sep 20, 2024
1 parent 39a9758 commit 71989c8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions e2e/server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package e2e_test

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

require.True(t, oversizedError)
require.Contains(t, err.Error(), fmt.Sprint(http.StatusBadRequest))

}

Expand Down
8 changes: 8 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ func (svr *Server) HandlePut(w http.ResponseWriter, r *http.Request) (commitment
commitment, err := svr.router.Put(r.Context(), meta.Mode, comm, input)
if err != nil {
err = fmt.Errorf("put request failed with commitment %v (commitment mode %v): %w", comm, meta.Mode, err)

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
}

svr.WriteInternalError(w, err)
return commitments.CommitmentMeta{}, MetaError{
Err: 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("encoded blob is larger than max blob size: blob length %d, max blob size %d", 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("blob is larger than max blob size: blob length %d, max blob size %d", 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
6 changes: 6 additions & 0 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,6 +17,11 @@ const (
Unknown
)

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

func (b BackendType) String() string {
switch b {
case EigenDA:
Expand Down

0 comments on commit 71989c8

Please sign in to comment.