Skip to content

Commit

Permalink
use switch case when finalizing
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Oct 10, 2024
1 parent 5584d47 commit ea92b96
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,17 @@ func (r *Layer2Relayer) finalizeBatch(dbBatch *orm.Batch, withProof bool) error

var calldata []byte
codecVersion := encoding.GetCodecVersion(r.chainCfg, dbChunks[0].StartBlockNumber, dbChunks[0].StartBlockTime)
if codecVersion == encoding.CodecV0 {
log.Info("Start to roll up zk proof", "batch hash", dbBatch.Hash)

switch codecVersion {
case encoding.CodecV0:
log.Info("Start to roll up zk proof", "batch hash", dbBatch.Hash)
calldata, err = r.constructFinalizeBatchPayloadCodecV0(dbBatch, dbParentBatch, aggProof)
if err != nil {
return fmt.Errorf("failed to construct finalizeBatch payload codecv0, index: %v, err: %w", dbBatch.Index, err)
}
} else if codecVersion == encoding.CodecV1 || codecVersion == encoding.CodecV2 {
log.Info("Start to roll up zk proof", "batch hash", dbBatch.Hash)

case encoding.CodecV1, encoding.CodecV2:
log.Info("Start to roll up zk proof", "batch hash", dbBatch.Hash)
chunks := make([]*encoding.Chunk, len(dbChunks))
for i, c := range dbChunks {
blocks, dbErr := r.l2BlockOrm.GetL2BlocksInRange(r.ctx, c.StartBlockNumber, c.EndBlockNumber)
Expand All @@ -632,14 +633,17 @@ func (r *Layer2Relayer) finalizeBatch(dbBatch *orm.Batch, withProof bool) error
}
chunks[i] = &encoding.Chunk{Blocks: blocks}
}

calldata, err = r.constructFinalizeBatchPayloadCodecV1AndV2(dbBatch, dbParentBatch, dbChunks, chunks, aggProof)
if err != nil {
return fmt.Errorf("failed to construct finalizeBatch payload codecv1, index: %v, err: %w", dbBatch.Index, err)
}
} else { // >= codecv3
log.Debug("encoding is codecv3, using finalizeBundle instead", "index", dbBatch.Index)

case encoding.CodecV3, encoding.CodecV4:
log.Debug("using finalizeBundle instead", "index", dbBatch.Index, "codec version", codecVersion)
return nil

default:
return fmt.Errorf("unsupported codec version: %v", codecVersion)
}

txHash, err := r.finalizeSender.SendTransaction(dbBatch.Hash, &r.cfg.RollupContractAddress, calldata, nil, 0)
Expand Down

0 comments on commit ea92b96

Please sign in to comment.