Skip to content

Commit 826357a

Browse files
authored
fix(rollup-relayer): update commit status logic (#1656)
1 parent d26381c commit 826357a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.5.7"
8+
var tag = "v4.5.8"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

rollup/internal/orm/batch.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ func (o *Batch) UpdateRollupStatus(ctx context.Context, hash string, status type
386386
func (o *Batch) UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash string, commitTxHash string, status types.RollupStatus, dbTX ...*gorm.DB) error {
387387
updateFields := make(map[string]interface{})
388388
updateFields["commit_tx_hash"] = commitTxHash
389-
updateFields["rollup_status"] = int(status)
389+
updateFields["rollup_status"] = gorm.Expr(
390+
`CASE
391+
WHEN rollup_status NOT IN (?, ?) THEN ?
392+
ELSE rollup_status
393+
END`,
394+
types.RollupFinalizing, types.RollupFinalized, int(status))
390395
if status == types.RollupCommitted {
391396
updateFields["committed_at"] = utils.NowUTC()
392397
}
@@ -397,15 +402,6 @@ func (o *Batch) UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash stri
397402
}
398403
db = db.WithContext(ctx)
399404

400-
var currentBatch Batch
401-
if err := db.Where("hash", hash).First(&currentBatch).Error; err != nil {
402-
return fmt.Errorf("Batch.UpdateCommitTxHashAndRollupStatus error when querying current status: %w, batch hash: %v", err, hash)
403-
}
404-
405-
if types.RollupStatus(currentBatch.RollupStatus) == types.RollupFinalizing || types.RollupStatus(currentBatch.RollupStatus) == types.RollupFinalized {
406-
return nil
407-
}
408-
409405
db = db.Model(&Batch{})
410406
db = db.Where("hash", hash)
411407

rollup/internal/orm/orm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func TestBatchOrm(t *testing.T) {
314314
updatedBatch, err = batchOrm.GetLatestBatch(context.Background())
315315
assert.NoError(t, err)
316316
assert.NotNil(t, updatedBatch)
317-
assert.Equal(t, "", updatedBatch.CommitTxHash)
317+
assert.Equal(t, "commitTxHash", updatedBatch.CommitTxHash)
318318
assert.Equal(t, types.RollupFinalized, types.RollupStatus(updatedBatch.RollupStatus))
319319

320320
err = batchOrm.UpdateFinalizeTxHashAndRollupStatus(context.Background(), batchHash2, "finalizeTxHash", types.RollupFinalizeFailed)

0 commit comments

Comments
 (0)