From dfaad0578f8d162a78d76e77cf80d9d442a8893c Mon Sep 17 00:00:00 2001 From: Mengran Lan Date: Mon, 1 Jul 2024 15:13:52 +0800 Subject: [PATCH] fix bug --- .../internal/orm/batch_event.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bridge-history-api/internal/orm/batch_event.go b/bridge-history-api/internal/orm/batch_event.go index f41040c33e..02e214cb2a 100644 --- a/bridge-history-api/internal/orm/batch_event.go +++ b/bridge-history-api/internal/orm/batch_event.go @@ -112,20 +112,20 @@ func (c *BatchEvent) InsertOrUpdateBatchEvents(ctx context.Context, l1BatchEvent return fmt.Errorf("failed to soft delete batch event, error: %w", err) } } - if containsFinalizedEvent { - db := c.db - db = db.WithContext(ctx) - db = db.Model(&BatchEvent{}) - updateFields := make(map[string]interface{}) - // After darwin, FinalizeBatch event signals a range of batches are finalized, - // thus losing the batch hash info. Meanwhile, only batch_index is enough to update finalized batches. - db = db.Where("batch_index <= ?", maxFinalizedBatchIndex) - db = db.Where("batch_status != ?", btypes.BatchStatusTypeFinalized) - updateFields["batch_status"] = btypes.BatchStatusTypeFinalized - updateFields["l1_block_number"] = maxL1BlockNumber - if err := db.Updates(updateFields).Error; err != nil { - return fmt.Errorf("failed to update batch event, error: %w", err) - } + } + if containsFinalizedEvent { + db := c.db + db = db.WithContext(ctx) + db = db.Model(&BatchEvent{}) + updateFields := make(map[string]interface{}) + // After darwin, FinalizeBatch event signals a range of batches are finalized, + // thus losing the batch hash info. Meanwhile, only batch_index is enough to update finalized batches. + db = db.Where("batch_index <= ?", maxFinalizedBatchIndex) + db = db.Where("batch_status != ?", btypes.BatchStatusTypeFinalized) + updateFields["batch_status"] = btypes.BatchStatusTypeFinalized + updateFields["l1_block_number"] = maxL1BlockNumber + if err := db.Updates(updateFields).Error; err != nil { + return fmt.Errorf("failed to update batch event, error: %w", err) } } return nil