-
Notifications
You must be signed in to change notification settings - Fork 198
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
Chunk store #848
Merged
Merged
Chunk store #848
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a804cbb
Added chunk store.
cody-littley 92feb04
Merge branch 'master' into chunk-store
cody-littley 8cab35e
Finish test for uploading/downloading proofs
cody-littley 24cb43e
Add ability to upload/download coefficients.
cody-littley 5bf0a48
Made suggested changes.
cody-littley 76628c1
Merge branch 'master' into chunk-store
cody-littley 728a7fb
Merge branch 'master' into chunk-store
cody-littley d3e2de9
Incremental progress.
cody-littley c4f6b19
Fix unit test.
cody-littley 7af8882
Make suggested changes.
cody-littley 3fb0c1d
Merge branch 'master' into chunk-store
cody-littley dd6cde1
Enable fragmented upload/download of chunks.
cody-littley 9b605f8
Use correct type of blob key.
cody-littley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package chunkstore | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Layr-Labs/eigenda/common/aws/s3" | ||
"github.com/Layr-Labs/eigenda/disperser" | ||
"github.com/Layr-Labs/eigenda/disperser/common/blobstore" | ||
"github.com/Layr-Labs/eigenda/encoding" | ||
"github.com/Layr-Labs/eigenda/encoding/rs" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
"github.com/consensys/gnark-crypto/ecc/bn254" | ||
) | ||
|
||
// ChunkReader reads chunks written by ChunkWriter. | ||
type ChunkReader interface { | ||
// GetChunkProofs reads a slice of proofs from the chunk store. | ||
GetChunkProofs(ctx context.Context, blobKey disperser.BlobKey) ([]*encoding.Proof, error) | ||
// GetChunkCoefficients reads a slice of frames from the chunk store. The metadata parameter | ||
// should match the metadata returned by PutChunkCoefficients. | ||
GetChunkCoefficients( | ||
ctx context.Context, | ||
blobKey disperser.BlobKey) ([]*rs.Frame, error) | ||
} | ||
|
||
var _ ChunkReader = (*chunkReader)(nil) | ||
|
||
type chunkReader struct { | ||
logger logging.Logger | ||
metadataStore *blobstore.BlobMetadataStore | ||
client s3.Client | ||
bucket string | ||
shards []uint32 | ||
} | ||
|
||
// NewChunkReader creates a new ChunkReader. | ||
// | ||
// This chunk reader will only return data for the shards specified in the shards parameter. | ||
// If empty, it will return data for all shards. (Note: shard feature is not yet implemented.) | ||
func NewChunkReader( | ||
logger logging.Logger, | ||
metadataStore *blobstore.BlobMetadataStore, | ||
s3Client s3.Client, | ||
bucketName string, | ||
shards []uint32) ChunkReader { | ||
|
||
return &chunkReader{ | ||
logger: logger, | ||
metadataStore: metadataStore, | ||
client: s3Client, | ||
bucket: bucketName, | ||
shards: shards, | ||
} | ||
} | ||
|
||
func (r *chunkReader) GetChunkProofs( | ||
ctx context.Context, | ||
blobKey disperser.BlobKey) ([]*encoding.Proof, error) { | ||
|
||
s3Key := blobKey.String() | ||
|
||
bytes, err := r.client.DownloadObject(ctx, r.bucket, s3Key) | ||
if err != nil { | ||
r.logger.Error("Failed to download chunks from S3: %v", err) | ||
return nil, fmt.Errorf("failed to download chunks from S3: %w", err) | ||
} | ||
|
||
if len(bytes)%bn254.SizeOfG1AffineCompressed != 0 { | ||
r.logger.Error("Invalid proof size") | ||
return nil, fmt.Errorf("invalid proof size: %w", err) | ||
} | ||
|
||
proofCount := len(bytes) / bn254.SizeOfG1AffineCompressed | ||
proofs := make([]*encoding.Proof, proofCount) | ||
|
||
for i := 0; i < proofCount; i++ { | ||
proof := encoding.Proof{} | ||
err := proof.Unmarshal(bytes[i*bn254.SizeOfG1AffineCompressed:]) | ||
if err != nil { | ||
r.logger.Error("Failed to unmarshal proof: %v", err) | ||
return nil, fmt.Errorf("failed to unmarshal proof: %w", err) | ||
} | ||
proofs[i] = &proof | ||
} | ||
|
||
return proofs, nil | ||
} | ||
|
||
func (r *chunkReader) GetChunkCoefficients( | ||
ctx context.Context, | ||
blobKey disperser.BlobKey) ([]*rs.Frame, error) { | ||
|
||
s3Key := blobKey.String() | ||
|
||
bytes, err := r.client.DownloadObject(ctx, r.bucket, s3Key) | ||
// TODO: Implement fragmented download | ||
//bytes, err := r.client.FragmentedDownloadObject(ctx, r.bucket, s3Key, metadata.DataSize, metadata.FragmentSize) | ||
if err != nil { | ||
r.logger.Error("Failed to download chunks from S3: %v", err) | ||
return nil, fmt.Errorf("failed to download chunks from S3: %w", err) | ||
} | ||
|
||
frames, err := rs.GnarkDecodeFrames(bytes) | ||
if err != nil { | ||
r.logger.Error("Failed to decode frames: %v", err) | ||
return nil, fmt.Errorf("failed to decode frames: %w", err) | ||
} | ||
|
||
return frames, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this blobkey references the v1 blob key. In StoreBlob for V2 we use blobKey.Hex() = string
eigenda/disperser/common/v2/blobstore/s3_blob_store.go
Line 27 in c63dd61
V2 blob key:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also when we fetch for proofs vs coefficients don't we need a different S3 key to differentiate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been assuming we'd use different buckets. Started a slack conversation to discuss. Will circle back on this prior to merging once we decide how we want to handle buckets and namespacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've switched over to using
v2.BlobKey
as recommended by @ian-shim.