Skip to content

Commit

Permalink
add corner cases handling
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Jul 8, 2024
1 parent d03ddbc commit e7ee85e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bridge-history-api/internal/logic/event_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ func (b *EventUpdateLogic) UpdateL2WithdrawMessageProofs(ctx context.Context, he
return err
}

if len(finalizedBatches) == 0 {
log.Warn("no finalized batches to update", "lastUpdatedFinalizedBlockHeight", lastUpdatedFinalizedBlockHeight)
return nil
}

if finalizedBatches[0].EndBlockNumber <= lastUpdatedFinalizedBlockHeight {
log.Warn("no finalized batches to update", "lastUpdatedFinalizedBlockHeight", lastUpdatedFinalizedBlockHeight, "endBlockNumber", finalizedBatches[0].EndBlockNumber)
return nil
}

for _, finalizedBatch := range finalizedBatches {
log.Info("update finalized batch info of L2 withdrawals", "index", finalizedBatch.BatchIndex, "lastlockHeight", lastUpdatedFinalizedBlockHeight, "start", finalizedBatch.StartBlockNumber, "end", finalizedBatch.EndBlockNumber)
// This method is compatible with both "finalize by batch" and "finalize by bundle" modes:
Expand Down
1 change: 1 addition & 0 deletions bridge-history-api/internal/orm/batch_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *BatchEvent) GetUpdatedFinalizedBlockHeight(ctx context.Context) (uint64
db = db.Order("batch_index desc")
if err := db.First(&batch).Error; err != nil {
if err == gorm.ErrRecordNotFound {
// No finalized batch found, return genesis batch's end block number.
return 0, nil
}
return 0, fmt.Errorf("failed to get latest processed finalized batch, error: %w", err)
Expand Down

0 comments on commit e7ee85e

Please sign in to comment.