diff --git a/common/version/version.go b/common/version/version.go index d01945d4bd..263fbf49c3 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.5.7" +var tag = "v4.5.8" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/rollup/internal/orm/batch.go b/rollup/internal/orm/batch.go index 2d83c4791d..95f5a7bf82 100644 --- a/rollup/internal/orm/batch.go +++ b/rollup/internal/orm/batch.go @@ -386,7 +386,12 @@ func (o *Batch) UpdateRollupStatus(ctx context.Context, hash string, status type func (o *Batch) UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash string, commitTxHash string, status types.RollupStatus, dbTX ...*gorm.DB) error { updateFields := make(map[string]interface{}) updateFields["commit_tx_hash"] = commitTxHash - updateFields["rollup_status"] = int(status) + updateFields["rollup_status"] = gorm.Expr( + `CASE + WHEN rollup_status NOT IN (?, ?) THEN ? + ELSE rollup_status + END`, + types.RollupFinalizing, types.RollupFinalized, int(status)) if status == types.RollupCommitted { updateFields["committed_at"] = utils.NowUTC() } @@ -397,15 +402,6 @@ func (o *Batch) UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash stri } db = db.WithContext(ctx) - var currentBatch Batch - if err := db.Where("hash", hash).First(¤tBatch).Error; err != nil { - return fmt.Errorf("Batch.UpdateCommitTxHashAndRollupStatus error when querying current status: %w, batch hash: %v", err, hash) - } - - if types.RollupStatus(currentBatch.RollupStatus) == types.RollupFinalizing || types.RollupStatus(currentBatch.RollupStatus) == types.RollupFinalized { - return nil - } - db = db.Model(&Batch{}) db = db.Where("hash", hash) diff --git a/rollup/internal/orm/orm_test.go b/rollup/internal/orm/orm_test.go index b53299bd3b..7b6f9496a5 100644 --- a/rollup/internal/orm/orm_test.go +++ b/rollup/internal/orm/orm_test.go @@ -314,7 +314,7 @@ func TestBatchOrm(t *testing.T) { updatedBatch, err = batchOrm.GetLatestBatch(context.Background()) assert.NoError(t, err) assert.NotNil(t, updatedBatch) - assert.Equal(t, "", updatedBatch.CommitTxHash) + assert.Equal(t, "commitTxHash", updatedBatch.CommitTxHash) assert.Equal(t, types.RollupFinalized, types.RollupStatus(updatedBatch.RollupStatus)) err = batchOrm.UpdateFinalizeTxHashAndRollupStatus(context.Background(), batchHash2, "finalizeTxHash", types.RollupFinalizeFailed)