Skip to content

Commit 3663e51

Browse files
committed
feat: version byte to tasks
1 parent 07ebd01 commit 3663e51

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

coordinator/conf/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"maxIdleNum": 20
2828
},
2929
"l2": {
30+
"validium_mode": false,
3031
"chain_id": 111,
3132
"l2geth": {
3233
"endpoint": "not need to specified for mocking"

coordinator/internal/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type L2Endpoint struct {
3636
// L2 loads l2geth configuration items.
3737
type L2 struct {
3838
// l2geth chain_id.
39-
ChainID uint64 `json:"chain_id"`
40-
Endpoint *L2Endpoint `json:"l2geth"`
39+
ChainID uint64 `json:"chain_id"`
40+
Endpoint *L2Endpoint `json:"l2geth"`
41+
ValidiumMode bool `json:"validium_mode"`
4142
}
4243

4344
// Auth provides the auth coordinator

coordinator/internal/logic/provertask/batch_prover_task.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,14 @@ func (bp *BatchProverTask) recoverActiveAttempts(ctx *gin.Context, batchTask *or
302302
}
303303

304304
func (bp *BatchProverTask) getBatchTaskDetail(dbBatch *orm.Batch, chunkInfos []*message.ChunkInfo, chunkProofs []*message.OpenVMChunkProof, hardForkName string) (*message.BatchTaskDetail, error) {
305+
// Get the version byte.
306+
version, err := bp.version(hardForkName)
307+
if err != nil {
308+
return nil, fmt.Errorf("failed to decode version byte: %w", err)
309+
}
310+
305311
taskDetail := &message.BatchTaskDetail{
312+
Version: version,
306313
ChunkInfos: chunkInfos,
307314
ChunkProofs: chunkProofs,
308315
ForkName: hardForkName,

coordinator/internal/logic/provertask/bundle_prover_task.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ func (bp *BundleProverTask) formatProverTask(ctx context.Context, task *orm.Prov
265265
batchProofs = append(batchProofs, &proof)
266266
}
267267

268+
// Get the version byte.
269+
version, err := bp.version(hardForkName)
270+
if err != nil {
271+
return nil, fmt.Errorf("failed to decode version byte: %w", err)
272+
}
273+
268274
taskDetail := message.BundleTaskDetail{
275+
Version: version,
269276
BatchProofs: batchProofs,
270277
ForkName: hardForkName,
271278
}

coordinator/internal/logic/provertask/chunk_prover_task.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,20 @@ func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.Prove
237237
return nil, fmt.Errorf("failed to fetch block hashes of a chunk, chunk hash:%s err:%v", task.TaskID, dbErr)
238238
}
239239

240+
// Get the version byte.
241+
version, err := cp.version(hardForkName)
242+
if err != nil {
243+
return nil, fmt.Errorf("failed to decode version byte: %w", err)
244+
}
245+
240246
var taskDetailBytes []byte
241247
taskDetail := message.ChunkTaskDetail{
248+
Version: version,
242249
BlockHashes: blockHashes,
243250
PrevMsgQueueHash: common.HexToHash(chunk.PrevL1MessageQueueHash),
244251
ForkName: hardForkName,
245252
}
246253

247-
var err error
248254
taskDetailBytes, err = json.Marshal(taskDetail)
249255
if err != nil {
250256
return nil, fmt.Errorf("failed to marshal block hashes hash:%s, err:%w", task.TaskID, err)

coordinator/internal/logic/provertask/prover_task.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ type proverTaskContext struct {
6565
hasAssignedTask *orm.ProverTask
6666
}
6767

68+
// version get the version for the chain instance
69+
//
70+
// TODO: This is not foolproof and does not cover all scenarios.
71+
func (b *BaseProverTask) version(hardForkName string) (uint8, error) {
72+
var domain, stfVersion uint8
73+
74+
if b.cfg.L2.ValidiumMode {
75+
domain = 1
76+
stfVersion = 1
77+
} else {
78+
domain = 0
79+
stfVersion = 8
80+
if hardForkName != "feynman" {
81+
return 0, errors.New("expected hardfork=feynman")
82+
}
83+
}
84+
85+
return (domain << 6) + stfVersion, nil
86+
}
87+
6888
// hardForkName get the chunk/batch/bundle hard fork name
6989
func (b *BaseProverTask) hardForkName(ctx *gin.Context, taskCtx *proverTaskContext) (string, error) {
7090
switch {

0 commit comments

Comments
 (0)