Skip to content

Commit e7fd02c

Browse files
author
colinlyguo
committed
fix(rollup-relayer): update finalize status atomically
1 parent bc8f9db commit e7fd02c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
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.4.70"
8+
var tag = "v4.4.71"
99

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

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,12 @@ func (r *Layer2Relayer) handleConfirmation(cfm *sender.Confirmation) {
885885
}
886886

887887
err := r.db.Transaction(func(dbTX *gorm.DB) error {
888-
if err := r.batchOrm.UpdateFinalizeTxHashAndRollupStatusByBundleHash(r.ctx, bundleHash, cfm.TxHash.String(), status); err != nil {
888+
if err := r.batchOrm.UpdateFinalizeTxHashAndRollupStatusByBundleHash(r.ctx, bundleHash, cfm.TxHash.String(), status, dbTX); err != nil {
889889
log.Warn("UpdateFinalizeTxHashAndRollupStatusByBundleHash failed", "confirmation", cfm, "err", err)
890890
return err
891891
}
892892

893-
if err := r.bundleOrm.UpdateFinalizeTxHashAndRollupStatus(r.ctx, bundleHash, cfm.TxHash.String(), status); err != nil {
893+
if err := r.bundleOrm.UpdateFinalizeTxHashAndRollupStatus(r.ctx, bundleHash, cfm.TxHash.String(), status, dbTX); err != nil {
894894
log.Warn("UpdateFinalizeTxHashAndRollupStatus failed", "confirmation", cfm, "err", err)
895895
return err
896896
}

rollup/internal/orm/bundle.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,19 @@ func (o *Bundle) InsertBundle(ctx context.Context, batches []*Batch, codecVersio
189189
}
190190

191191
// UpdateFinalizeTxHashAndRollupStatus updates the finalize transaction hash and rollup status for a bundle.
192-
func (o *Bundle) UpdateFinalizeTxHashAndRollupStatus(ctx context.Context, hash string, finalizeTxHash string, status types.RollupStatus) error {
192+
func (o *Bundle) UpdateFinalizeTxHashAndRollupStatus(ctx context.Context, hash string, finalizeTxHash string, status types.RollupStatus, dbTX ...*gorm.DB) error {
193193
updateFields := make(map[string]interface{})
194194
updateFields["finalize_tx_hash"] = finalizeTxHash
195195
updateFields["rollup_status"] = int(status)
196196
if status == types.RollupFinalized {
197197
updateFields["finalized_at"] = time.Now()
198198
}
199199

200-
db := o.db.WithContext(ctx)
200+
db := o.db
201+
if len(dbTX) > 0 && dbTX[0] != nil {
202+
db = dbTX[0]
203+
}
204+
db = db.WithContext(ctx)
201205
db = db.Model(&Bundle{})
202206
db = db.Where("hash", hash)
203207

0 commit comments

Comments
 (0)