Skip to content

Commit

Permalink
feat(handlers): postShared returns 429 when disperser rate limited cl…
Browse files Browse the repository at this point in the history
…ient
  • Loading branch information
samlaf committed Oct 29, 2024
1 parent 32aeb17 commit 8dbc072
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/Layr-Labs/eigenda-proxy/commitments"
"github.com/Layr-Labs/eigenda-proxy/store"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// MetaError includes both an error and commitment metadata
Expand Down Expand Up @@ -35,3 +37,10 @@ func is400(err error) bool {
// for the 400s returned by the disperser server (currently only INVALID_ARGUMENT).
return errors.Is(err, store.ErrProxyOversizedBlob)
}

func is429(err error) bool {
// grpc RESOURCE_EXHAUSTED is returned by the disperser server when the client has sent too many requests
// in a short period of time. This is a client-side issue, so we should return the 429 to the client.
st, isGRPCError := status.FromError(err)
return isGRPCError && st.Code() == codes.ResourceExhausted
}
2 changes: 2 additions & 0 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func (svr *Server) handlePostShared(w http.ResponseWriter, r *http.Request, comm
switch {
case is400(err):
http.Error(w, err.Error(), http.StatusBadRequest)
case is429(err):
http.Error(w, err.Error(), http.StatusTooManyRequests)
case errors.Is(err, &api.ErrorFailover{}):
// this tells the caller (batcher) to failover to ethda b/c eigenda is temporarily down
http.Error(w, err.Error(), http.StatusServiceUnavailable)
Expand Down

0 comments on commit 8dbc072

Please sign in to comment.