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

Disperser api audit #1170

Merged
merged 4 commits into from
Jan 28, 2025
Merged

Disperser api audit #1170

merged 4 commits into from
Jan 28, 2025

Conversation

jianoaix
Copy link
Contributor

Why are these changes needed?

A pass of audit of the disperser/apiserver

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@jianoaix jianoaix requested review from anupsv and dmanc January 28, 2025 00:32
@@ -32,6 +33,11 @@ func (s *DispersalServerV2) DisperseBlob(ctx context.Context, req *pb.DisperseBl
return nil, err
}

// Check against payment meter to make sure there is quota remaining
if err := s.checkPaymentMeter(ctx, req); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate out rate limiting checking and place it after the param validation, because this will make external RPC calls

@@ -40,7 +46,7 @@ func (s *DispersalServerV2) DisperseBlob(ctx context.Context, req *pb.DisperseBl
blob := req.GetBlob()
blobHeader, err := corev2.BlobHeaderFromProtobuf(req.GetBlobHeader())
if err != nil {
return nil, api.NewErrorInternal(err.Error())
return nil, api.NewErrorInvalidArg(fmt.Sprintf("failed to parse the blob header proto: %w", err))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't internal error

@@ -20,12 +20,12 @@ func (s *DispersalServerV2) GetBlobStatus(ctx context.Context, req *pb.BlobStatu
}()

if req.GetBlobKey() == nil || len(req.GetBlobKey()) != 32 {
return nil, api.NewErrorInvalidArg("invalid blob key")
return nil, api.NewErrorInvalidArg("blob key must be present and with 32 bytes")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informative error messages here and below

@@ -32,6 +33,11 @@ func (s *DispersalServerV2) DisperseBlob(ctx context.Context, req *pb.DisperseBl
return nil, err
}

// Check against payment meter to make sure there is quota remaining
if err := s.checkPaymentMeter(ctx, req); err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be using api.NewErrorX for this return. Also noticed there are some other areas that aren't doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it already wrapped inside the function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, seems like one level of indirection though. I was thinking the top level would handle that.

Copy link
Contributor Author

@jianoaix jianoaix Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea the implementation here had chosen to let low level functions to classify the errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually like moving it up to have less redundant code. validateDispersalRequest should be homogeneous and all its errors are (and should be) invalid requests.

@jianoaix jianoaix merged commit fd4444f into Layr-Labs:master Jan 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants