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

[v2] Encoding manager #846

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Conversation

ian-shim
Copy link
Contributor

Why are these changes needed?

  • Adds EncodingManager component
  • Adds conditional updates for blob status
  • Adds interface for encoding client v2

Checks

  • I've made sure the lint is passing in this PR.
  • 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 :(

@ian-shim
Copy link
Contributor Author

To be merged on top of #844

// NumEncodingRetries defines how many times the encoding will be retried
NumEncodingRetries int
// NumRelayAssignment defines how many relays will be assigned to a blob
NumRelayAssignment uint16
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: seems like this should be plural

relayKeys := availableRelays
// shuffle relay keys
for i := len(relayKeys) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be cryptographically secure randomness? If so crypto/rand should be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. It just has to be random enough. Performance is probably more important than security

@ian-shim ian-shim marked this pull request as ready for review October 30, 2024 01:31
e.pool.Submit(func() {
for i := 0; i < e.NumEncodingRetries+1; i++ {
encodingCtx, cancel := context.WithTimeout(ctx, e.EncodingRequestTimeout)
fragmentInfo, err := e.encodeBlob(encodingCtx, blobKey, blob)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for adding metadata for how to retrieve from the S3 bucket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah current thinking is that encoder returns the size of the chunks and the number of fragments (files stored), and controller stores them in metadata. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I see, it makes sense to me now since we are writing the chunks through the S3 client with the new fragmenting logic.

@ian-shim ian-shim force-pushed the v2-encoding-manager branch from 02cc5ff to 1d25e75 Compare October 30, 2024 16:30
@ian-shim ian-shim requested a review from anupsv October 30, 2024 21:00

// Encode the blobs
e.pool.Submit(func() {
for i := 0; i < e.NumEncodingRetries+1; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really love how this all uses one retry loop. If we are just failing to update dynamo on the last step, do we really need to reencode the blob?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plan was to keep encoder request idempotent (i.e. encoder checks if the blob has been encoded and returns immediately in that case). Then the extra encoding request is trivial

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, ok 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

In order to keep the encoder request idempotent that means we do something like ListObject on s3 and make sure stuff exists there?

cc: @cody-littley we were discussing this part in the morning.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, that could be pretty slow. This seems a bit unideal. @ian-shim , do you have thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have to list whole bucket. Since we already know the object names, we can check if those objects exist right?

}

storeCtx, cancel = context.WithTimeout(ctx, e.StoreTimeout)
err = e.blobMetadataStore.MarkBlobEncoded(storeCtx, blobKey, fragmentInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we updating the blob record with the fragmentInfo instead of just pushing it next to the BlobCert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nicer to put it in BlobCert. I'm not sure if it belongs there though. Is it something that should go onchain?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't we just store a wrapper at this stage which contains both the BlobCert and this additional metadata? I agree it should not be in the actual canonical BlobCert structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My worry is that now there are two different data structures representing BlobCert (one used in disperser & relay, and another one in node). I'd rather keep one consistent struct across. Is updating the blob metadata that bad?

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, ignore that. I ended up marshaling/unmarshaling them separately and putting them in BlobCertificate: e76e3a6

@ian-shim ian-shim force-pushed the v2-encoding-manager branch 2 times, most recently from 8825f41 to 59fbc1c Compare October 31, 2024 20:20
@ian-shim ian-shim force-pushed the v2-encoding-manager branch from 59fbc1c to f1bd032 Compare October 31, 2024 21:51
@ian-shim ian-shim merged commit c63dd61 into Layr-Labs:master Nov 4, 2024
6 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.

4 participants