Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return 400 when blobs exceed max limit #140

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -185,6 +187,7 @@ func TestProxyServerWithOversizedBlob(t *testing.T) {
}

require.True(t, oversizedError)
require.Contains(t, err.Error(), fmt.Sprint(http.StatusBadRequest))
epociask marked this conversation as resolved.
Show resolved Hide resolved

}

Expand Down
7 changes: 7 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 @@ -218,6 +219,12 @@ 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 utils.ErrorMessageContainsAny(err, store.OversizedEigenDAError, store.OversizedProxyError) {
samlaf marked this conversation as resolved.
Show resolved Hide resolved
svr.WriteBadRequest(w, err)
epociask marked this conversation as resolved.
Show resolved Hide resolved
return meta, err
}

svr.WriteInternalError(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("encoded blob is larger than max blob size: blob length %d, max blob size %d", len(value), e.cfg.MaxBlobSizeBytes)
return nil, fmt.Errorf("%s: blob length %d, max blob size %d", OversizedProxyError, 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("%s: blob length %d, max blob size %d", OversizedProxyError, len(value), e.config.MaxBlobSizeBytes)
samlaf marked this conversation as resolved.
Show resolved Hide resolved
}

e.Lock()
Expand Down
5 changes: 5 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const (
Unknown
)

const (
OversizedProxyError = "encoded blob is larger than max blob size"
OversizedEigenDAError = "blob size cannot exceed"
)

func (b BackendType) String() string {
switch b {
case EigenDA:
Expand Down
15 changes: 15 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ 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) {
samlaf marked this conversation as resolved.
Show resolved Hide resolved
return true
}
}

return false
}

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