Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Oct 15, 2024
1 parent c1257a0 commit e174353
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion coordinator/internal/logic/provertask/batch_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (bp *BatchProverTask) getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*

codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion))
if err != nil {
return nil, fmt.Errorf("failed to get codec from version %d: %w", dbBatch.CodecVersion, err)
return nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err)
}

batchHeader, decodeErr := codec.NewDABatchFromBytes(dbBatch.BatchHeader)
Expand Down
6 changes: 3 additions & 3 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ func (r *Layer2Relayer) handleL2RollupRelayerConfirmLoop(ctx context.Context) {
func (r *Layer2Relayer) constructCommitBatchPayloadCodecV0AndV1AndV2(dbBatch *orm.Batch, dbParentBatch *orm.Batch, dbChunks []*orm.Chunk, chunks []*encoding.Chunk) ([]byte, *kzg4844.Blob, error) {
codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion))
if err != nil {
return nil, nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err)
}

batch := &encoding.Batch{
Expand Down Expand Up @@ -1011,7 +1011,7 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV3AndV4(dbBatch *orm.Bat

codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion))
if err != nil {
return nil, nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err)
}

daBatch, createErr := codec.NewDABatch(batch)
Expand Down Expand Up @@ -1083,7 +1083,7 @@ func (r *Layer2Relayer) constructFinalizeBatchPayloadCodecV1AndV2(dbBatch *orm.B

codec, err := encoding.CodecFromVersion(encoding.CodecVersion(dbBatch.CodecVersion))
if err != nil {
return nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, fmt.Errorf("failed to get codec from version %d, err: %w", dbBatch.CodecVersion, err)
}

daBatch, createErr := codec.NewDABatch(batch)
Expand Down
12 changes: 5 additions & 7 deletions rollup/internal/controller/watcher/batch_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,14 @@ func (p *BatchProposer) proposeBatch() error {
return err
}

codecVersion := encoding.GetCodecVersion(p.chainCfg, firstUnbatchedChunk.StartBlockNumber, firstUnbatchedChunk.StartBlockTime)

var batch encoding.Batch
batch.Index = dbParentBatch.Index + 1
batch.ParentBatchHash = common.HexToHash(dbParentBatch.Hash)
batch.TotalL1MessagePoppedBefore = firstUnbatchedChunk.TotalL1MessagesPoppedBefore

for i, chunk := range daChunks {
batch.Chunks = append(batch.Chunks, chunk)
metrics, calcErr := utils.CalculateBatchMetrics(&batch, codecVersion)
metrics, calcErr := utils.CalculateBatchMetrics(&batch, codec.Version())
if calcErr != nil {
return fmt.Errorf("failed to calculate batch metrics: %w", calcErr)
}
Expand Down Expand Up @@ -316,17 +314,17 @@ func (p *BatchProposer) proposeBatch() error {

batch.Chunks = batch.Chunks[:len(batch.Chunks)-1]

metrics, err := utils.CalculateBatchMetrics(&batch, codecVersion)
metrics, err := utils.CalculateBatchMetrics(&batch, codec.Version())
if err != nil {
return fmt.Errorf("failed to calculate batch metrics: %w", err)
}

p.recordAllBatchMetrics(metrics)
return p.updateDBBatchInfo(&batch, codecVersion, metrics)
return p.updateDBBatchInfo(&batch, codec.Version(), metrics)
}
}

metrics, calcErr := utils.CalculateBatchMetrics(&batch, codecVersion)
metrics, calcErr := utils.CalculateBatchMetrics(&batch, codec.Version())
if calcErr != nil {
return fmt.Errorf("failed to calculate batch metrics: %w", calcErr)
}
Expand All @@ -340,7 +338,7 @@ func (p *BatchProposer) proposeBatch() error {

p.batchFirstBlockTimeoutReached.Inc()
p.recordAllBatchMetrics(metrics)
return p.updateDBBatchInfo(&batch, codecVersion, metrics)
return p.updateDBBatchInfo(&batch, codec.Version(), metrics)
}

log.Debug("pending chunks do not reach one of the constraints or contain a timeout block")
Expand Down
2 changes: 1 addition & 1 deletion rollup/internal/orm/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (o *Chunk) InsertChunk(ctx context.Context, chunk *encoding.Chunk, codecVer

enableCompress, err := encoding.GetChunkEnableCompression(codecVersion, chunk)
if err != nil {
log.Error("failed to get chunk enable compression", "err", err)
log.Error("failed to get chunk enable compression", "version", codecVersion, "err", err)
return nil, fmt.Errorf("Chunk.InsertChunk error: %w", err)
}

Expand Down
10 changes: 5 additions & 5 deletions rollup/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func CalculateChunkMetrics(chunk *encoding.Chunk, codecVersion encoding.CodecVer

codec, err := encoding.CodecFromVersion(codecVersion)
if err != nil {
return nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err)
}

start := time.Now()
Expand Down Expand Up @@ -104,7 +104,7 @@ func CalculateBatchMetrics(batch *encoding.Batch, codecVersion encoding.CodecVer

codec, err := encoding.CodecFromVersion(codecVersion)
if err != nil {
return nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err)
}

start := time.Now()
Expand Down Expand Up @@ -133,7 +133,7 @@ func CalculateBatchMetrics(batch *encoding.Batch, codecVersion encoding.CodecVer
func GetChunkHash(chunk *encoding.Chunk, totalL1MessagePoppedBefore uint64, codecVersion encoding.CodecVersion) (common.Hash, error) {
codec, err := encoding.CodecFromVersion(codecVersion)
if err != nil {
return common.Hash{}, fmt.Errorf("failed to get codec from version: %w", err)
return common.Hash{}, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err)
}

daChunk, err := codec.NewDAChunk(chunk, totalL1MessagePoppedBefore)
Expand Down Expand Up @@ -164,7 +164,7 @@ type BatchMetadata struct {
func GetBatchMetadata(batch *encoding.Batch, codecVersion encoding.CodecVersion) (*BatchMetadata, error) {
codec, err := encoding.CodecFromVersion(codecVersion)
if err != nil {
return nil, fmt.Errorf("failed to get codec from version: %w", err)
return nil, fmt.Errorf("failed to get codec from version: %v, err: %w", codecVersion, err)
}

daBatch, err := codec.NewDABatch(batch)
Expand All @@ -174,7 +174,7 @@ func GetBatchMetadata(batch *encoding.Batch, codecVersion encoding.CodecVersion)

batchMeta := &BatchMetadata{
BatchHash: daBatch.Hash(),
BatchDataHash: common.Hash{}, // Assuming DataHash is not directly accessible from DABatch interface
BatchDataHash: daBatch.DataHash(),
BatchBytes: daBatch.Encode(),
BlobBytes: daBatch.BlobBytes(),
}
Expand Down

0 comments on commit e174353

Please sign in to comment.