Skip to content

Commit c9e2d90

Browse files
author
colinlyguo
committed
add bundle info and fork name
1 parent 0e2af43 commit c9e2d90

File tree

5 files changed

+60
-19
lines changed

5 files changed

+60
-19
lines changed

common/types/message/message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ type BatchTaskDetail struct {
109109
// BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches.
110110
type BundleTaskDetail struct {
111111
// use one of the string of EuclidFork / EuclidV2Fork
112-
ForkName string `json:"fork_name"`
113-
BatchProofs []BatchProof `json:"batch_proofs"`
114-
// TODO: add `bundle_info` field for sanity check
112+
ForkName string `json:"fork_name"`
113+
BatchProofs []BatchProof `json:"batch_proofs"`
114+
BundleInfo *OpenVMBundleInfo `json:"bundle_info,omitempty"`
115115
}
116116

117117
// ChunkInfo is for calculating pi_hash for chunk

coordinator/internal/logic/provertask/batch_prover_task.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (bp *BatchProverTask) formatProverTask(ctx context.Context, task *orm.Prove
229229
chunkInfos = append(chunkInfos, &chunkInfo)
230230
}
231231

232-
taskDetail, err := bp.getBatchTaskDetail(batch, chunkInfos, chunkProofs)
232+
taskDetail, err := bp.getBatchTaskDetail(batch, chunkInfos, chunkProofs, hardForkName)
233233
if err != nil {
234234
return nil, fmt.Errorf("failed to get batch task detail, taskID:%s err:%w", task.TaskID, err)
235235
}
@@ -258,12 +258,18 @@ func (bp *BatchProverTask) recoverActiveAttempts(ctx *gin.Context, batchTask *or
258258
}
259259
}
260260

261-
func (bp *BatchProverTask) getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*message.ChunkInfo, chunkProofs []message.ChunkProof) (*message.BatchTaskDetail, error) {
261+
func (bp *BatchProverTask) getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*message.ChunkInfo, chunkProofs []message.ChunkProof, hardForkName string) (*message.BatchTaskDetail, error) {
262262
taskDetail := &message.BatchTaskDetail{
263263
ChunkInfos: chunkInfos,
264264
ChunkProofs: chunkProofs,
265265
}
266266

267+
if hardForkName == message.EuclidV2Fork {
268+
taskDetail.ForkName = "euclidv2"
269+
} else if hardForkName == message.EuclidFork {
270+
taskDetail.ForkName = "euclidv1"
271+
}
272+
267273
dbBatchCodecVersion := encoding.CodecVersion(dbBatch.CodecVersion)
268274
switch dbBatchCodecVersion {
269275
case encoding.CodecV3, encoding.CodecV4, encoding.CodecV6, encoding.CodecV7:

coordinator/internal/logic/provertask/bundle_prover_task.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/gin-gonic/gin"
1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/prometheus/client_golang/prometheus/promauto"
12+
"github.com/scroll-tech/go-ethereum/common"
1213
"github.com/scroll-tech/go-ethereum/log"
1314
"github.com/scroll-tech/go-ethereum/params"
1415
"gorm.io/gorm"
@@ -194,6 +195,11 @@ func (bp *BundleProverTask) formatProverTask(ctx context.Context, task *orm.Prov
194195
return nil, fmt.Errorf("failed to get batch proofs for bundle task id:%s, no batch found", task.TaskID)
195196
}
196197

198+
parentBatch, err := bp.batchOrm.GetBatchByHash(ctx, batches[0].ParentBatchHash)
199+
if err != nil {
200+
return nil, fmt.Errorf("failed to get parent batch for batch task id:%s err:%w", task.TaskID, err)
201+
}
202+
197203
var batchProofs []message.BatchProof
198204
for _, batch := range batches {
199205
proof := message.NewBatchProof(hardForkName)
@@ -207,6 +213,26 @@ func (bp *BundleProverTask) formatProverTask(ctx context.Context, task *orm.Prov
207213
BatchProofs: batchProofs,
208214
}
209215

216+
if hardForkName == message.EuclidV2Fork {
217+
taskDetail.ForkName = "euclidv2"
218+
} else if hardForkName == message.EuclidFork {
219+
taskDetail.ForkName = "euclidv1"
220+
}
221+
222+
taskDetail.BundleInfo = &message.OpenVMBundleInfo{
223+
ChainID: bp.cfg.L2.ChainID,
224+
PrevStateRoot: common.HexToHash(parentBatch.StateRoot),
225+
PostStateRoot: common.HexToHash(batches[len(batches)-1].StateRoot),
226+
WithdrawRoot: common.HexToHash(batches[len(batches)-1].WithdrawRoot),
227+
NumBatches: uint32(len(batches)),
228+
PrevBatchHash: common.HexToHash(batches[0].ParentBatchHash),
229+
BatchHash: common.HexToHash(batches[len(batches)-1].Hash),
230+
}
231+
232+
if hardForkName == message.EuclidV2Fork {
233+
taskDetail.BundleInfo.MsgQueueHash = common.HexToHash(batches[len(batches)-1].PostL1MessageQueueHash)
234+
}
235+
210236
batchProofsBytes, err := json.Marshal(taskDetail)
211237
if err != nil {
212238
return nil, fmt.Errorf("failed to marshal batch proofs, taskID:%s err:%w", task.TaskID, err)

coordinator/internal/logic/provertask/chunk_prover_task.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.Prove
192192
BlockHashes: blockHashes,
193193
PrevMsgQueueHash: common.HexToHash(chunk.PrevL1MessageQueueHash),
194194
}
195+
196+
if hardForkName == message.EuclidV2Fork {
197+
taskDetail.ForkName = "euclidv2"
198+
} else if hardForkName == message.EuclidFork {
199+
taskDetail.ForkName = "euclidv1"
200+
}
201+
195202
var err error
196203
taskDetailBytes, err = json.Marshal(taskDetail)
197204
if err != nil {

coordinator/internal/orm/batch.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ type Batch struct {
1919
db *gorm.DB `gorm:"column:-"`
2020

2121
// batch
22-
Index uint64 `json:"index" gorm:"column:index"`
23-
Hash string `json:"hash" gorm:"column:hash"`
24-
DataHash string `json:"data_hash" gorm:"column:data_hash"`
25-
StartChunkIndex uint64 `json:"start_chunk_index" gorm:"column:start_chunk_index"`
26-
StartChunkHash string `json:"start_chunk_hash" gorm:"column:start_chunk_hash"`
27-
EndChunkIndex uint64 `json:"end_chunk_index" gorm:"column:end_chunk_index"`
28-
EndChunkHash string `json:"end_chunk_hash" gorm:"column:end_chunk_hash"`
29-
StateRoot string `json:"state_root" gorm:"column:state_root"`
30-
WithdrawRoot string `json:"withdraw_root" gorm:"column:withdraw_root"`
31-
ParentBatchHash string `json:"parent_batch_hash" gorm:"column:parent_batch_hash"`
32-
BatchHeader []byte `json:"batch_header" gorm:"column:batch_header"`
33-
CodecVersion int16 `json:"codec_version" gorm:"column:codec_version"`
34-
EnableCompress bool `json:"enable_compress" gorm:"column:enable_compress"`
35-
BlobBytes []byte `json:"blob_bytes" gorm:"column:blob_bytes"`
22+
Index uint64 `json:"index" gorm:"column:index"`
23+
Hash string `json:"hash" gorm:"column:hash"`
24+
DataHash string `json:"data_hash" gorm:"column:data_hash"`
25+
StartChunkIndex uint64 `json:"start_chunk_index" gorm:"column:start_chunk_index"`
26+
StartChunkHash string `json:"start_chunk_hash" gorm:"column:start_chunk_hash"`
27+
EndChunkIndex uint64 `json:"end_chunk_index" gorm:"column:end_chunk_index"`
28+
EndChunkHash string `json:"end_chunk_hash" gorm:"column:end_chunk_hash"`
29+
StateRoot string `json:"state_root" gorm:"column:state_root"`
30+
WithdrawRoot string `json:"withdraw_root" gorm:"column:withdraw_root"`
31+
ParentBatchHash string `json:"parent_batch_hash" gorm:"column:parent_batch_hash"`
32+
BatchHeader []byte `json:"batch_header" gorm:"column:batch_header"`
33+
CodecVersion int16 `json:"codec_version" gorm:"column:codec_version"`
34+
PrevL1MessageQueueHash string `json:"prev_l1_message_queue_hash" gorm:"column:prev_l1_message_queue_hash"`
35+
PostL1MessageQueueHash string `json:"post_l1_message_queue_hash" gorm:"column:post_l1_message_queue_hash"`
36+
EnableCompress bool `json:"enable_compress" gorm:"column:enable_compress"`
37+
BlobBytes []byte `json:"blob_bytes" gorm:"column:blob_bytes"`
3638

3739
// proof
3840
ChunkProofsStatus int16 `json:"chunk_proofs_status" gorm:"column:chunk_proofs_status;default:1"`

0 commit comments

Comments
 (0)