Skip to content

Commit

Permalink
handle error outside and add recover to updateblobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth More authored and Siddharth More committed Mar 1, 2024
1 parent 4e8cedb commit 848eaf2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions disperser/batcher/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ func (f *finalizer) FinalizeBlobs(ctx context.Context) error {

totalProcessed := 0
metadatas, exclusiveStartKey, err := f.blobStore.GetBlobMetadataByStatusWithPagination(ctx, disperser.Confirmed, f.numBlobsPerFetch, nil)
if err != nil {
return fmt.Errorf("FinalizeBlobs: error getting blob headers: %w", err)
}

for len(metadatas) > 0 {
if err != nil {
return fmt.Errorf("FinalizeBlobs: error getting blob headers: %w", err)
}
metas := metadatas
f.logger.Info("FinalizeBlobs: finalizing blobs", "numBlobs", len(metas), "finalizedBlockNumber", lastFinalBlock)
pool.Submit(func() {
Expand All @@ -111,8 +112,12 @@ func (f *finalizer) FinalizeBlobs(ctx context.Context) error {
break
}
metadatas, exclusiveStartKey, err = f.blobStore.GetBlobMetadataByStatusWithPagination(ctx, disperser.Confirmed, f.numBlobsPerFetch, exclusiveStartKey)
if err != nil {
return fmt.Errorf("FinalizeBlobs: error getting blob headers on subsequent call: %w", err)
}
}
pool.StopWait()

f.logger.Info("FinalizeBlobs: successfully processed all finalized blobs", "finalizedBlockNumber", lastFinalBlock, "totalProcessed", totalProcessed, "elapsedTime", time.Since(startTime))
f.metrics.UpdateLastSeenFinalizedBlock(lastFinalBlock)
f.metrics.UpdateNumBlobs("processed", totalProcessed)
Expand All @@ -121,6 +126,14 @@ func (f *finalizer) FinalizeBlobs(ctx context.Context) error {
}

func (f *finalizer) updateBlobs(ctx context.Context, metadatas []*disperser.BlobMetadata, lastFinalBlock uint64) {
// Panic recovery
defer func() {
if r := recover(); r != nil {
// Log panic
f.logger.Error("FinalizeBlobs: encountered panic", "recovered", r)
}
}()

for _, m := range metadatas {
// Check if metadata is nil before proceeding
if m == nil {
Expand Down

0 comments on commit 848eaf2

Please sign in to comment.