Skip to content

Commit

Permalink
fix: Don't mark blob as confirmed if already confirmed (Layr-Labs#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Feb 19, 2024
1 parent 3340da9 commit 1395860
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions disperser/batcher/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ func TestBatcherIterations(t *testing.T) {
count, size = components.encodingStreamer.EncodedBlobstore.GetEncodedResultSize()
assert.Equal(t, 0, count)
assert.Equal(t, uint64(0), size)

// confirmed metadata should be immutable and not be updated
existingBlobIndex := meta1.ConfirmationInfo.BlobIndex
meta1, err = blobStore.MarkBlobConfirmed(ctx, meta1, &disperser.ConfirmationInfo{
BlobIndex: existingBlobIndex + 1,
})
assert.NoError(t, err)
// check confirmation info isn't updated
assert.Equal(t, existingBlobIndex, meta1.ConfirmationInfo.BlobIndex)
assert.Equal(t, disperser.Confirmed, meta1.BlobStatus)
}

func TestBlobFailures(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions disperser/common/blobstore/shared_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ func (s *SharedBlobStore) getBlobContentParallel(ctx context.Context, blobKey di
}

func (s *SharedBlobStore) MarkBlobConfirmed(ctx context.Context, existingMetadata *disperser.BlobMetadata, confirmationInfo *disperser.ConfirmationInfo) (*disperser.BlobMetadata, error) {
// TODO (ian-shim): remove this check once we are sure that the metadata is never overwritten
refreshedMetadata, err := s.GetBlobMetadata(ctx, existingMetadata.GetBlobKey())
if err != nil {
s.logger.Error("[MarkBlobConfirmed] error getting blob metadata", "err", err)
return nil, err
}
alreadyConfirmed, _ := refreshedMetadata.IsConfirmed()
if alreadyConfirmed {
s.logger.Warn("[MarkBlobConfirmed] trying to confirm blob already marked as confirmed", "blobKey", existingMetadata.GetBlobKey().String())
return refreshedMetadata, nil
}
newMetadata := *existingMetadata
// Update the TTL if needed
ttlFromNow := time.Now().Add(s.blobMetadataStore.ttl)
Expand Down
9 changes: 9 additions & 0 deletions disperser/common/inmem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ func (q *BlobStore) GetBlobContent(ctx context.Context, blobHash disperser.BlobH
}

func (q *BlobStore) MarkBlobConfirmed(ctx context.Context, existingMetadata *disperser.BlobMetadata, confirmationInfo *disperser.ConfirmationInfo) (*disperser.BlobMetadata, error) {
// TODO (ian-shim): remove this check once we are sure that the metadata is never overwritten
refreshedMetadata, err := q.GetBlobMetadata(ctx, existingMetadata.GetBlobKey())
if err != nil {
return nil, err
}
alreadyConfirmed, _ := refreshedMetadata.IsConfirmed()
if alreadyConfirmed {
return refreshedMetadata, nil
}
blobKey := existingMetadata.GetBlobKey()
if _, ok := q.Metadata[blobKey]; !ok {
return nil, disperser.ErrBlobNotFound
Expand Down

0 comments on commit 1395860

Please sign in to comment.