Skip to content

Commit

Permalink
fix(rollup-relayer): update batch finalizing status and unify db time…
Browse files Browse the repository at this point in the history
…stamp utc
  • Loading branch information
colinlyguo committed Dec 27, 2024
1 parent 45b23ed commit 0c95a80
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.83"
var tag = "v4.4.84"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
18 changes: 16 additions & 2 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,22 @@ func (r *Layer2Relayer) finalizeBundle(bundle *orm.Bundle, withProof bool) error
log.Info("finalizeBundle in layer1", "with proof", withProof, "index", bundle.Index, "start batch index", bundle.StartBatchIndex, "end batch index", bundle.EndBatchIndex, "tx hash", txHash.String())

// Updating rollup status in database.
if err := r.bundleOrm.UpdateFinalizeTxHashAndRollupStatus(r.ctx, bundle.Hash, txHash.String(), types.RollupFinalizing); err != nil {
log.Error("UpdateFinalizeTxHashAndRollupStatus failed", "index", bundle.Index, "bundle hash", bundle.Hash, "tx hash", txHash.String(), "err", err)
err = r.db.Transaction(func(dbTX *gorm.DB) error {
if err = r.batchOrm.UpdateFinalizeTxHashAndRollupStatusByBundleHash(r.ctx, bundle.Hash, txHash.String(), types.RollupFinalizing, dbTX); err != nil {
log.Warn("UpdateFinalizeTxHashAndRollupStatusByBundleHash failed", "bundle hash", bundle.Hash, "tx hash", txHash.String(), "err", err)
return err
}

if err = r.bundleOrm.UpdateFinalizeTxHashAndRollupStatus(r.ctx, bundle.Hash, txHash.String(), types.RollupFinalizing, dbTX); err != nil {
log.Warn("UpdateFinalizeTxHashAndRollupStatus failed", "bundle hash", bundle.Hash, "tx hash", txHash.String(), "err", err)
return err
}

return nil
})

if err != nil {
log.Warn("failed to update rollup status of bundle and batches", "err", err)
return err
}

Expand Down
25 changes: 12 additions & 13 deletions rollup/internal/orm/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (

"scroll-tech/common/types"
"scroll-tech/common/types/message"
"scroll-tech/common/utils"

rutils "scroll-tech/rollup/internal/utils"
"scroll-tech/rollup/internal/utils"
)

// Batch represents a batch of chunks.
Expand Down Expand Up @@ -250,7 +249,7 @@ func (o *Batch) GetBatchByIndex(ctx context.Context, index uint64) (*Batch, erro
}

// InsertBatch inserts a new batch into the database.
func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVersion encoding.CodecVersion, metrics rutils.BatchMetrics, dbTX ...*gorm.DB) (*Batch, error) {
func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVersion encoding.CodecVersion, metrics utils.BatchMetrics, dbTX ...*gorm.DB) (*Batch, error) {
if batch == nil {
return nil, errors.New("invalid args: batch is nil")
}
Expand All @@ -271,7 +270,7 @@ func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVer
startChunkIndex = parentBatch.EndChunkIndex + 1
}

batchMeta, err := rutils.GetBatchMetadata(batch, codecVersion)
batchMeta, err := utils.GetBatchMetadata(batch, codecVersion)
if err != nil {
log.Error("failed to get batch metadata", "index", batch.Index, "total l1 message popped before", batch.TotalL1MessagePoppedBefore,
"parent hash", batch.ParentBatchHash.Hex(), "number of chunks", numChunks, "err", err)
Expand Down Expand Up @@ -347,11 +346,11 @@ func (o *Batch) UpdateProvingStatus(ctx context.Context, hash string, status typ

switch status {
case types.ProvingTaskAssigned:
updateFields["prover_assigned_at"] = time.Now()
updateFields["prover_assigned_at"] = time.Now().UTC()
case types.ProvingTaskUnassigned:
updateFields["prover_assigned_at"] = nil
case types.ProvingTaskVerified:
updateFields["proved_at"] = time.Now()
updateFields["proved_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -375,9 +374,9 @@ func (o *Batch) UpdateRollupStatus(ctx context.Context, hash string, status type

switch status {
case types.RollupCommitted:
updateFields["committed_at"] = utils.NowUTC()
updateFields["committed_at"] = time.Now().UTC()
case types.RollupFinalized:
updateFields["finalized_at"] = utils.NowUTC()
updateFields["finalized_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -400,7 +399,7 @@ func (o *Batch) UpdateCommitTxHashAndRollupStatus(ctx context.Context, hash stri
updateFields["commit_tx_hash"] = commitTxHash
updateFields["rollup_status"] = int(status)
if status == types.RollupCommitted {
updateFields["committed_at"] = utils.NowUTC()
updateFields["committed_at"] = time.Now().UTC()
}

db := o.db.WithContext(ctx)
Expand All @@ -419,7 +418,7 @@ func (o *Batch) UpdateFinalizeTxHashAndRollupStatus(ctx context.Context, hash st
updateFields["finalize_tx_hash"] = finalizeTxHash
updateFields["rollup_status"] = int(status)
if status == types.RollupFinalized {
updateFields["finalized_at"] = time.Now()
updateFields["finalized_at"] = time.Now().UTC()
}

db := o.db.WithContext(ctx)
Expand Down Expand Up @@ -478,11 +477,11 @@ func (o *Batch) UpdateProvingStatusByBundleHash(ctx context.Context, bundleHash

switch status {
case types.ProvingTaskAssigned:
updateFields["prover_assigned_at"] = time.Now()
updateFields["prover_assigned_at"] = time.Now().UTC()
case types.ProvingTaskUnassigned:
updateFields["prover_assigned_at"] = nil
case types.ProvingTaskVerified:
updateFields["proved_at"] = time.Now()
updateFields["proved_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -507,7 +506,7 @@ func (o *Batch) UpdateFinalizeTxHashAndRollupStatusByBundleHash(ctx context.Cont

switch status {
case types.RollupFinalized:
updateFields["finalized_at"] = utils.NowUTC()
updateFields["finalized_at"] = time.Now().UTC()
}

db := o.db
Expand Down
9 changes: 4 additions & 5 deletions rollup/internal/orm/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"scroll-tech/common/types"
"scroll-tech/common/types/message"
"scroll-tech/common/utils"
)

// Bundle represents a bundle of batches.
Expand Down Expand Up @@ -194,7 +193,7 @@ func (o *Bundle) UpdateFinalizeTxHashAndRollupStatus(ctx context.Context, hash s
updateFields["finalize_tx_hash"] = finalizeTxHash
updateFields["rollup_status"] = int(status)
if status == types.RollupFinalized {
updateFields["finalized_at"] = time.Now()
updateFields["finalized_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -218,7 +217,7 @@ func (o *Bundle) UpdateProvingStatus(ctx context.Context, hash string, status ty

switch status {
case types.ProvingTaskVerified:
updateFields["proved_at"] = time.Now()
updateFields["proved_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -241,7 +240,7 @@ func (o *Bundle) UpdateRollupStatus(ctx context.Context, hash string, status typ
updateFields := make(map[string]interface{})
updateFields["rollup_status"] = int(status)
if status == types.RollupFinalized {
updateFields["finalized_at"] = time.Now()
updateFields["finalized_at"] = time.Now().UTC()
}

db := o.db.WithContext(ctx)
Expand Down Expand Up @@ -271,7 +270,7 @@ func (o *Bundle) UpdateProofAndProvingStatusByHash(ctx context.Context, hash str
updateFields["proof"] = proofBytes
updateFields["proving_status"] = provingStatus
updateFields["proof_time_sec"] = proofTimeSec
updateFields["proved_at"] = utils.NowUTC()
updateFields["proved_at"] = time.Now().UTC()

db = db.WithContext(ctx)
db = db.Model(&Bundle{})
Expand Down
8 changes: 4 additions & 4 deletions rollup/internal/orm/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ func (o *Chunk) UpdateProvingStatus(ctx context.Context, hash string, status typ

switch status {
case types.ProvingTaskAssigned:
updateFields["prover_assigned_at"] = time.Now()
updateFields["prover_assigned_at"] = time.Now().UTC()
case types.ProvingTaskUnassigned:
updateFields["prover_assigned_at"] = nil
case types.ProvingTaskVerified:
updateFields["proved_at"] = time.Now()
updateFields["proved_at"] = time.Now().UTC()
}

db := o.db
Expand All @@ -289,11 +289,11 @@ func (o *Chunk) UpdateProvingStatusByBatchHash(ctx context.Context, batchHash st

switch status {
case types.ProvingTaskAssigned:
updateFields["prover_assigned_at"] = time.Now()
updateFields["prover_assigned_at"] = time.Now().UTC()
case types.ProvingTaskUnassigned:
updateFields["prover_assigned_at"] = nil
case types.ProvingTaskVerified:
updateFields["proved_at"] = time.Now()
updateFields["proved_at"] = time.Now().UTC()
}

db := o.db
Expand Down

0 comments on commit 0c95a80

Please sign in to comment.