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

Relay rate limits #906

Merged
merged 15 commits into from
Nov 19, 2024
Prev Previous commit
Made suggested changes.
Signed-off-by: Cody Littley <cody@eigenlabs.org>
  • Loading branch information
cody-littley committed Nov 19, 2024
commit f2c10e4949cf080a9be80f199bae71b265a3aa93
3 changes: 3 additions & 0 deletions relay/metadata_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigenda/relay/cache"
"github.com/Layr-Labs/eigensdk-go/logging"
"sync/atomic"
Expand Down Expand Up @@ -155,8 +156,10 @@ func (m *metadataProvider) fetchMetadata(key v2.BlobKey) (*blobMetadata, error)
}
}

// TODO(cody-littley): blob size is not correct https://github.com/Layr-Labs/eigenda/pull/906#discussion_r1847396530
blobSize := uint32(cert.BlobHeader.BlobCommitments.Length)
Copy link
Contributor

Choose a reason for hiding this comment

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

cert.BlobHeader.BlobCommitments.Length gives you the blob length in symbols.
I think what we want is here cert.BlobHeader.BlobSize (size of raw blob data in bytes) instead

Copy link
Contributor Author

@cody-littley cody-littley Nov 19, 2024

Choose a reason for hiding this comment

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

There is currently no such field in BlobHeader. Is that something that is going to be added?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah my bad. I meant BlobMetadata. Otherwise, we can also multiply Length by BYTES_PER_SYMBOL, but this will overestimate the size

chunkSize, err := v2.GetChunkLength(cert.BlobHeader.BlobVersion, blobSize)
ian-shim marked this conversation as resolved.
Show resolved Hide resolved
chunkSize *= encoding.BYTES_PER_SYMBOL
if err != nil {
return nil, fmt.Errorf("error getting chunk length: %w", err)
}
Expand Down
22 changes: 15 additions & 7 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func NewServer(
// GetBlob retrieves a blob stored by the relay.
func (s *Server) GetBlob(ctx context.Context, request *pb.GetBlobRequest) (*pb.GetBlobReply, error) {

// Future work:
// TODO(cody-littley):
// - timeouts

err := s.blobRateLimiter.BeginGetBlobOperation(time.Now())
ian-shim marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -188,7 +188,7 @@ func (s *Server) GetBlob(ctx context.Context, request *pb.GetBlobRequest) (*pb.G
// GetChunks retrieves chunks from blobs stored by the relay.
func (s *Server) GetChunks(ctx context.Context, request *pb.GetChunksRequest) (*pb.GetChunksReply, error) {

// Future work:
// TODO(cody-littley):
// - authentication
// - timeouts

Expand Down Expand Up @@ -219,7 +219,10 @@ func (s *Server) GetChunks(ctx context.Context, request *pb.GetChunksRequest) (*
"error fetching metadata for blob, check if blob exists and is assigned to this relay: %w", err)
}

requiredBandwidth := computeChunkRequestRequiredBandwidth(request, mMap)
requiredBandwidth, err := computeChunkRequestRequiredBandwidth(request, mMap)
if err != nil {
return nil, fmt.Errorf("error computing required bandwidth: %w", err)
}
err = s.chunkRateLimiter.RequestGetChunkBandwidth(time.Now(), clientID, requiredBandwidth)
if err != nil {
return nil, err
Expand Down Expand Up @@ -324,26 +327,31 @@ func gatherChunkDataToSend(
}

// computeChunkRequestRequiredBandwidth computes the bandwidth required to fulfill a GetChunks request.
func computeChunkRequestRequiredBandwidth(request *pb.GetChunksRequest, mMap metadataMap) int {
func computeChunkRequestRequiredBandwidth(request *pb.GetChunksRequest, mMap metadataMap) (int, error) {
requiredBandwidth := 0
for _, req := range request.ChunkRequests {
var metadata *blobMetadata
var key v2.BlobKey
var requestedChunks int

if req.GetByIndex() != nil {
key := v2.BlobKey(req.GetByIndex().GetBlobKey())
key = v2.BlobKey(req.GetByIndex().GetBlobKey())
metadata = mMap[key]
Copy link
Contributor

Choose a reason for hiding this comment

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

check if the key exists in the map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not be possible, since process will fail before this point if there is missing metadata. But it's a useful safety check, so I don't mind adding it.

requestedChunks = len(req.GetByIndex().ChunkIndices)
} else {
key := v2.BlobKey(req.GetByRange().GetBlobKey())
key = v2.BlobKey(req.GetByRange().GetBlobKey())
metadata = mMap[key]
requestedChunks = int(req.GetByRange().EndIndex - req.GetByRange().StartIndex)
}

if metadata == nil {
return 0, fmt.Errorf("metadata not found for key %s", key.Hex())
}

requiredBandwidth += requestedChunks * int(metadata.chunkSizeBytes)
ian-shim marked this conversation as resolved.
Show resolved Hide resolved
}

return requiredBandwidth
return requiredBandwidth, nil

}

Expand Down
Loading