Skip to content

Commit

Permalink
use utils.NowUTC()
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Dec 27, 2024
1 parent 0c95a80 commit 5993aa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
25 changes: 13 additions & 12 deletions rollup/internal/orm/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (

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

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

// Batch represents a batch of chunks.
Expand Down Expand Up @@ -249,7 +250,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 utils.BatchMetrics, dbTX ...*gorm.DB) (*Batch, error) {
func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVersion encoding.CodecVersion, metrics rutils.BatchMetrics, dbTX ...*gorm.DB) (*Batch, error) {
if batch == nil {
return nil, errors.New("invalid args: batch is nil")
}
Expand All @@ -270,7 +271,7 @@ func (o *Batch) InsertBatch(ctx context.Context, batch *encoding.Batch, codecVer
startChunkIndex = parentBatch.EndChunkIndex + 1
}

batchMeta, err := utils.GetBatchMetadata(batch, codecVersion)
batchMeta, err := rutils.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 @@ -346,11 +347,11 @@ func (o *Batch) UpdateProvingStatus(ctx context.Context, hash string, status typ

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

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

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

db := o.db
Expand All @@ -399,7 +400,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"] = time.Now().UTC()
updateFields["committed_at"] = utils.NowUTC()
}

db := o.db.WithContext(ctx)
Expand All @@ -418,7 +419,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().UTC()
updateFields["finalized_at"] = utils.NowUTC()
}

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

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

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

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

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

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

// Bundle represents a bundle of batches.
Expand Down Expand Up @@ -193,7 +194,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().UTC()
updateFields["finalized_at"] = utils.NowUTC()
}

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

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

db := o.db
Expand All @@ -240,7 +241,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().UTC()
updateFields["finalized_at"] = utils.NowUTC()
}

db := o.db.WithContext(ctx)
Expand Down Expand Up @@ -270,7 +271,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"] = time.Now().UTC()
updateFields["proved_at"] = utils.NowUTC()

db = db.WithContext(ctx)
db = db.Model(&Bundle{})
Expand Down
15 changes: 8 additions & 7 deletions rollup/internal/orm/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"gorm.io/gorm"

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

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

// Chunk represents a chunk of blocks in the database.
Expand Down Expand Up @@ -177,7 +178,7 @@ func (o *Chunk) GetChunksByBatchHash(ctx context.Context, batchHash string) ([]*
}

// InsertChunk inserts a new chunk into the database.
func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVersion encoding.CodecVersion, metrics utils.ChunkMetrics, dbTX ...*gorm.DB) (*Chunk, error) {
func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVersion encoding.CodecVersion, metrics rutils.ChunkMetrics, dbTX ...*gorm.DB) (*Chunk, error) {
if chunk == nil || len(chunk.Blocks) == 0 {
return nil, errors.New("invalid args")
}
Expand All @@ -202,7 +203,7 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer
parentChunkStateRoot = parentChunk.StateRoot
}

chunkHash, err := utils.GetChunkHash(chunk, totalL1MessagePoppedBefore, codecVersion)
chunkHash, err := rutils.GetChunkHash(chunk, totalL1MessagePoppedBefore, codecVersion)
if err != nil {
log.Error("failed to get chunk hash", "err", err)
return nil, fmt.Errorf("Chunk.InsertChunk error: %w", err)
Expand Down Expand Up @@ -261,11 +262,11 @@ func (o *Chunk) UpdateProvingStatus(ctx context.Context, hash string, status typ

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

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

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

db := o.db
Expand Down

0 comments on commit 5993aa5

Please sign in to comment.