Skip to content

Commit

Permalink
update confirmation block number on MarkFinalized
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Jun 5, 2024
1 parent b344eb2 commit a3a2b85
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
3 changes: 1 addition & 2 deletions disperser/batcher/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ func (f *finalizer) updateBlobs(ctx context.Context, metadatas []*disperser.Blob
continue
}

confirmationMetadata.ConfirmationInfo.ConfirmationBlockNumber = uint32(confirmationBlockNumber)
err = f.blobStore.MarkBlobFinalized(ctx, blobKey)
_, err = f.blobStore.MarkBlobFinalized(ctx, confirmationMetadata, confirmationBlockNumber)
if err != nil {
f.logger.Error("error marking blob as finalized", "blobKey", blobKey.String(), "err", err)
f.metrics.IncrementNumBlobs("failed")
Expand Down
20 changes: 17 additions & 3 deletions disperser/common/blobstore/shared_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,28 @@ func (s *SharedBlobStore) MarkBlobDispersing(ctx context.Context, metadataKey di
}

func (s *SharedBlobStore) MarkBlobInsufficientSignatures(ctx context.Context, existingMetadata *disperser.BlobMetadata, confirmationInfo *disperser.ConfirmationInfo) (*disperser.BlobMetadata, error) {
if existingMetadata == nil {
return nil, errors.New("metadata is nil")
}
newMetadata := *existingMetadata
newMetadata.BlobStatus = disperser.InsufficientSignatures
newMetadata.ConfirmationInfo = confirmationInfo
if confirmationInfo != nil {
newMetadata.ConfirmationInfo = confirmationInfo
}
return &newMetadata, s.blobMetadataStore.UpdateBlobMetadata(ctx, existingMetadata.GetBlobKey(), &newMetadata)
}

func (s *SharedBlobStore) MarkBlobFinalized(ctx context.Context, metadataKey disperser.BlobKey) error {
return s.blobMetadataStore.SetBlobStatus(ctx, metadataKey, disperser.Finalized)
func (s *SharedBlobStore) MarkBlobFinalized(ctx context.Context, existingMetadata *disperser.BlobMetadata, confirmationBlockNumber uint64) (*disperser.BlobMetadata, error) {
if existingMetadata == nil {
return nil, errors.New("metadata is nil")
}
newMetadata := *existingMetadata
newMetadata.BlobStatus = disperser.Finalized
if confirmationBlockNumber > 0 {
newMetadata.ConfirmationInfo.ConfirmationBlockNumber = uint32(confirmationBlockNumber)
}

return &newMetadata, s.blobMetadataStore.UpdateBlobMetadata(ctx, existingMetadata.GetBlobKey(), &newMetadata)
}

func (s *SharedBlobStore) MarkBlobProcessing(ctx context.Context, metadataKey disperser.BlobKey) error {
Expand Down
4 changes: 3 additions & 1 deletion disperser/common/blobstore/shared_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ func TestSharedBlobStore(t *testing.T) {
assert.Nil(t, err)
assertMetadata(t, blobKey, blobSize, requestedAt, disperser.Confirmed, metadata1)

err = sharedStorage.MarkBlobFinalized(ctx, blobKey)
updatedMetadata, err = sharedStorage.MarkBlobFinalized(ctx, metadata1, 151)
assert.Nil(t, err)
assert.Equal(t, disperser.Finalized, updatedMetadata.BlobStatus)
assert.Equal(t, 151, updatedMetadata.ConfirmationInfo.ConfirmationBlockNumber)

metadata1, err = sharedStorage.GetBlobMetadata(ctx, blobKey)
assert.Nil(t, err)
Expand Down
12 changes: 8 additions & 4 deletions disperser/common/inmem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ func (q *BlobStore) MarkBlobInsufficientSignatures(ctx context.Context, existing
return &newMetadata, nil
}

func (q *BlobStore) MarkBlobFinalized(ctx context.Context, blobKey disperser.BlobKey) error {
func (q *BlobStore) MarkBlobFinalized(ctx context.Context, existingMetadata *disperser.BlobMetadata, confirmationBlockNumber uint64) (*disperser.BlobMetadata, error) {
q.mu.Lock()
defer q.mu.Unlock()
blobKey := existingMetadata.GetBlobKey()
if _, ok := q.Metadata[blobKey]; !ok {
return disperser.ErrBlobNotFound
return nil, disperser.ErrBlobNotFound
}

q.Metadata[blobKey].BlobStatus = disperser.Finalized
return nil
newMetadata := *existingMetadata
newMetadata.BlobStatus = disperser.Finalized
newMetadata.ConfirmationInfo.ConfirmationBlockNumber = uint32(confirmationBlockNumber)
q.Metadata[blobKey] = &newMetadata
return &newMetadata, nil
}

func (q *BlobStore) MarkBlobProcessing(ctx context.Context, blobKey disperser.BlobKey) error {
Expand Down
2 changes: 1 addition & 1 deletion disperser/disperser.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type BlobStore interface {
// Returns the updated metadata and error
MarkBlobInsufficientSignatures(ctx context.Context, existingMetadata *BlobMetadata, confirmationInfo *ConfirmationInfo) (*BlobMetadata, error)
// MarkBlobFinalized marks a blob as finalized
MarkBlobFinalized(ctx context.Context, blobKey BlobKey) error
MarkBlobFinalized(ctx context.Context, existingMetadata *BlobMetadata, confirmationBlockNumber uint64) (*BlobMetadata, error)
// MarkBlobProcessing marks a blob as processing
MarkBlobProcessing(ctx context.Context, blobKey BlobKey) error
// MarkBlobFailed marks a blob as failed
Expand Down

0 comments on commit a3a2b85

Please sign in to comment.