From afe1a7776dbf78ea90de4dd9341f531af43b226b Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 10:47:30 +0800 Subject: [PATCH 1/8] fix coordiantor assign bug --- .../logic/provertask/batch_prover_task.go | 45 +++++++++++-------- .../logic/provertask/bundle_prover_task.go | 39 +++++++++------- .../logic/provertask/chunk_prover_task.go | 45 +++++++++++-------- 3 files changed, 75 insertions(+), 54 deletions(-) diff --git a/coordinator/internal/logic/provertask/batch_prover_task.go b/coordinator/internal/logic/provertask/batch_prover_task.go index 524f1b3589..bf4603e04c 100644 --- a/coordinator/internal/logic/provertask/batch_prover_task.go +++ b/coordinator/internal/logic/provertask/batch_prover_task.go @@ -3,6 +3,7 @@ package provertask import ( "context" "encoding/json" + "errors" "fmt" "time" @@ -55,6 +56,20 @@ func NewBatchProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go return bp } +// proverHardForkSanityCheck check the prover task's hard-fork name +// and prover-task's hard-fork name is the same +func (bp *BatchProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, batchTask *orm.Batch) (string, error) { + hardForkName, getHardForkErr := bp.hardForkName(ctx, batchTask) + if getHardForkErr != nil { + return "", getHardForkErr + } + + if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { + return "", errors.New("hard-fork name is not the same as the batch's hard-fork name") + } + return hardForkName, nil +} + // Assign load and assign batch tasks func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := bp.checkParameter(ctx) @@ -77,6 +92,7 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato } var batchTask *orm.Batch + var hardForkName string for i := 0; i < 5; i++ { var getTaskError error var tmpBatchTask *orm.Batch @@ -101,10 +117,17 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } + var checkErr error + hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBatchTask) + if checkErr != nil { + log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) + return nil, nil + } + // Don't dispatch the same failing job to the same prover - proverTasks, getTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBatch, tmpBatchTask.Hash, 2) - if getTaskError != nil { - log.Error("failed to get prover tasks", "proof type", message.ProofTypeBatch.String(), "task ID", tmpBatchTask.Hash, "error", getTaskError) + proverTasks, getFailedTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBatch, tmpBatchTask.Hash, 2) + if getFailedTaskError != nil { + log.Error("failed to get prover tasks", "proof type", message.ProofTypeBatch.String(), "task ID", tmpBatchTask.Hash, "error", getFailedTaskError) return nil, ErrCoordinatorInternalFailure } for i := 0; i < len(proverTasks); i++ { @@ -135,22 +158,6 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } - hardForkName, getHardForkErr := bp.hardForkName(ctx, batchTask) - if getHardForkErr != nil { - bp.recoverActiveAttempts(ctx, batchTask) - log.Error("retrieve hard fork name by batch failed", "task_id", batchTask.Hash, "err", getHardForkErr) - return nil, ErrCoordinatorInternalFailure - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - bp.recoverActiveAttempts(ctx, batchTask) - log.Debug("incompatible prover version", - "requisite hard fork name", hardForkName, - "prover hard fork name", taskCtx.HardForkNames, - "task_id", batchTask.Hash) - return nil, nil - } - log.Info("start batch proof generation session", "task_id", batchTask.Hash, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName) proverTask := orm.ProverTask{ TaskID: batchTask.Hash, diff --git a/coordinator/internal/logic/provertask/bundle_prover_task.go b/coordinator/internal/logic/provertask/bundle_prover_task.go index 4dc14264d8..2a998e5b2b 100644 --- a/coordinator/internal/logic/provertask/bundle_prover_task.go +++ b/coordinator/internal/logic/provertask/bundle_prover_task.go @@ -3,6 +3,7 @@ package provertask import ( "context" "encoding/json" + "errors" "fmt" "time" @@ -55,6 +56,20 @@ func NewBundleProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *g return bp } +// proverHardForkSanityCheck check the prover task's hard-fork name +// and prover-task's hard-fork name is the same +func (bp *BundleProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, bundleTask *orm.Bundle) (string, error) { + hardForkName, getHardForkErr := bp.hardForkName(ctx, bundleTask) + if getHardForkErr != nil { + return "", getHardForkErr + } + + if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { + return "", errors.New("prover task's hard-fork name is not the same as the bundle's hard-fork name") + } + return hardForkName, nil +} + // Assign load and assign batch tasks func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := bp.checkParameter(ctx) @@ -77,6 +92,7 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat } var bundleTask *orm.Bundle + var hardForkName string for i := 0; i < 5; i++ { var getTaskError error var tmpBundleTask *orm.Bundle @@ -101,6 +117,13 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat return nil, nil } + var checkErr error + hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBundleTask) + if checkErr != nil { + log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) + return nil, nil + } + // Don't dispatch the same failing job to the same prover proverTasks, getTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBundle, tmpBundleTask.Hash, 2) if getTaskError != nil { @@ -135,22 +158,6 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat return nil, nil } - hardForkName, getHardForkErr := bp.hardForkName(ctx, bundleTask) - if getHardForkErr != nil { - bp.recoverActiveAttempts(ctx, bundleTask) - log.Error("retrieve hard fork name by bundle failed", "task_id", bundleTask.Hash, "err", getHardForkErr) - return nil, ErrCoordinatorInternalFailure - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - bp.recoverActiveAttempts(ctx, bundleTask) - log.Debug("incompatible prover version", - "requisite hard fork name", hardForkName, - "prover hard fork name", taskCtx.HardForkNames, - "task_id", bundleTask.Hash) - return nil, nil - } - log.Info("start bundle proof generation session", "task index", bundleTask.Index, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName) proverTask := orm.ProverTask{ TaskID: bundleTask.Hash, diff --git a/coordinator/internal/logic/provertask/chunk_prover_task.go b/coordinator/internal/logic/provertask/chunk_prover_task.go index 674f478912..5cd82ed313 100644 --- a/coordinator/internal/logic/provertask/chunk_prover_task.go +++ b/coordinator/internal/logic/provertask/chunk_prover_task.go @@ -3,6 +3,7 @@ package provertask import ( "context" "encoding/json" + "errors" "fmt" "time" @@ -53,6 +54,20 @@ func NewChunkProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go return cp } +// proverHardForkSanityCheck check the prover task's hard-fork name +// and prover-task's hard-fork name is the same +func (cp *ChunkProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, chunkTask *orm.Chunk) (string, error) { + hardForkName, getHardForkErr := cp.hardForkName(ctx, chunkTask) + if getHardForkErr != nil { + return "", getHardForkErr + } + + if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { + return "", errors.New("prover task's hard-fork name is not the same as the chunk's hard-fork name") + } + return hardForkName, nil +} + // Assign the chunk proof which need to prove func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := cp.checkParameter(ctx) @@ -75,6 +90,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato } var chunkTask *orm.Chunk + var hardForkName string for i := 0; i < 5; i++ { var getTaskError error var tmpChunkTask *orm.Chunk @@ -99,10 +115,17 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } + var checkErr error + hardForkName, checkErr = cp.hardForkSanityCheck(ctx, taskCtx, tmpChunkTask) + if checkErr != nil { + log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) + return nil, nil + } + // Don't dispatch the same failing job to the same prover - proverTasks, getTaskError := cp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeChunk, tmpChunkTask.Hash, 2) - if getTaskError != nil { - log.Error("failed to get prover tasks", "proof type", message.ProofTypeChunk.String(), "task ID", tmpChunkTask.Hash, "error", getTaskError) + proverTasks, getFailedTaskError := cp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeChunk, tmpChunkTask.Hash, 2) + if getFailedTaskError != nil { + log.Error("failed to get prover tasks", "proof type", message.ProofTypeChunk.String(), "task ID", tmpChunkTask.Hash, "error", getFailedTaskError) return nil, ErrCoordinatorInternalFailure } for i := 0; i < len(proverTasks); i++ { @@ -133,22 +156,6 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } - hardForkName, getHardForkErr := cp.hardForkName(ctx, chunkTask) - if getHardForkErr != nil { - cp.recoverActiveAttempts(ctx, chunkTask) - log.Error("retrieve hard fork name by chunk failed", "task_id", chunkTask.Hash, "err", getHardForkErr) - return nil, ErrCoordinatorInternalFailure - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - cp.recoverActiveAttempts(ctx, chunkTask) - log.Debug("incompatible prover version", - "requisite hard fork name", hardForkName, - "prover hard fork name", taskCtx.HardForkNames, - "task_id", chunkTask.Hash) - return nil, nil - } - log.Info("start chunk generation session", "task_id", chunkTask.Hash, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName) proverTask := orm.ProverTask{ TaskID: chunkTask.Hash, From f637ac803b1fcc72638f506230419775afa6ee0e Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 02:49:51 +0000 Subject: [PATCH 2/8] =?UTF-8?q?chore:=20auto=20version=20bump=E2=80=89[bot?= =?UTF-8?q?]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/version/version.go b/common/version/version.go index 96a807e8d9..62056e6a93 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.4.95" +var tag = "v4.4.96" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { From afe3ae9b5b20307b184089132e389d579b31f853 Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 11:14:06 +0800 Subject: [PATCH 3/8] remove duplicated code --- .../logic/provertask/batch_prover_task.go | 34 ++------- .../logic/provertask/bundle_prover_task.go | 41 ++--------- .../logic/provertask/chunk_prover_task.go | 29 +------- .../internal/logic/provertask/prover_task.go | 72 +++++++++++++++++++ 4 files changed, 83 insertions(+), 93 deletions(-) diff --git a/coordinator/internal/logic/provertask/batch_prover_task.go b/coordinator/internal/logic/provertask/batch_prover_task.go index bf4603e04c..70d7340bb3 100644 --- a/coordinator/internal/logic/provertask/batch_prover_task.go +++ b/coordinator/internal/logic/provertask/batch_prover_task.go @@ -3,7 +3,6 @@ package provertask import ( "context" "encoding/json" - "errors" "fmt" "time" @@ -56,20 +55,6 @@ func NewBatchProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go return bp } -// proverHardForkSanityCheck check the prover task's hard-fork name -// and prover-task's hard-fork name is the same -func (bp *BatchProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, batchTask *orm.Batch) (string, error) { - hardForkName, getHardForkErr := bp.hardForkName(ctx, batchTask) - if getHardForkErr != nil { - return "", getHardForkErr - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - return "", errors.New("hard-fork name is not the same as the batch's hard-fork name") - } - return hardForkName, nil -} - // Assign load and assign batch tasks func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := bp.checkParameter(ctx) @@ -117,8 +102,11 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } + taskCtx.taskType = message.ProofTypeBatch + taskCtx.batchTask = tmpBatchTask + var checkErr error - hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBatchTask) + hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx) if checkErr != nil { log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) return nil, nil @@ -195,20 +183,6 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return taskMsg, nil } -func (bp *BatchProverTask) hardForkName(ctx *gin.Context, batchTask *orm.Batch) (string, error) { - startChunk, getChunkErr := bp.chunkOrm.GetChunkByHash(ctx, batchTask.StartChunkHash) - if getChunkErr != nil { - return "", getChunkErr - } - - l2Block, getBlockErr := bp.blockOrm.GetL2BlockByNumber(ctx.Copy(), startChunk.StartBlockNumber) - if getBlockErr != nil { - return "", getBlockErr - } - hardForkName := encoding.GetHardforkName(bp.chainCfg, l2Block.Number, l2Block.BlockTimestamp) - return hardForkName, nil -} - func (bp *BatchProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, batch *orm.Batch, hardForkName string) (*coordinatorType.GetTaskSchema, error) { // get chunk from db chunks, err := bp.chunkOrm.GetChunksByBatchHash(ctx, task.TaskID) diff --git a/coordinator/internal/logic/provertask/bundle_prover_task.go b/coordinator/internal/logic/provertask/bundle_prover_task.go index 2a998e5b2b..e8b4681ce8 100644 --- a/coordinator/internal/logic/provertask/bundle_prover_task.go +++ b/coordinator/internal/logic/provertask/bundle_prover_task.go @@ -3,14 +3,12 @@ package provertask import ( "context" "encoding/json" - "errors" "fmt" "time" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/params" "gorm.io/gorm" @@ -56,20 +54,6 @@ func NewBundleProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *g return bp } -// proverHardForkSanityCheck check the prover task's hard-fork name -// and prover-task's hard-fork name is the same -func (bp *BundleProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, bundleTask *orm.Bundle) (string, error) { - hardForkName, getHardForkErr := bp.hardForkName(ctx, bundleTask) - if getHardForkErr != nil { - return "", getHardForkErr - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - return "", errors.New("prover task's hard-fork name is not the same as the bundle's hard-fork name") - } - return hardForkName, nil -} - // Assign load and assign batch tasks func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := bp.checkParameter(ctx) @@ -117,8 +101,11 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat return nil, nil } + taskCtx.taskType = message.ProofTypeBundle + taskCtx.bundleTask = tmpBundleTask + var checkErr error - hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBundleTask) + hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx) if checkErr != nil { log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) return nil, nil @@ -195,26 +182,6 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat return taskMsg, nil } -func (bp *BundleProverTask) hardForkName(ctx *gin.Context, bundleTask *orm.Bundle) (string, error) { - startBatch, getBatchErr := bp.batchOrm.GetBatchByHash(ctx, bundleTask.StartBatchHash) - if getBatchErr != nil { - return "", getBatchErr - } - - startChunk, getChunkErr := bp.chunkOrm.GetChunkByHash(ctx, startBatch.StartChunkHash) - if getChunkErr != nil { - return "", getChunkErr - } - - l2Block, getBlockErr := bp.blockOrm.GetL2BlockByNumber(ctx.Copy(), startChunk.StartBlockNumber) - if getBlockErr != nil { - return "", getBlockErr - } - - hardForkName := encoding.GetHardforkName(bp.chainCfg, l2Block.Number, l2Block.BlockTimestamp) - return hardForkName, nil -} - func (bp *BundleProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, hardForkName string) (*coordinatorType.GetTaskSchema, error) { // get bundle from db batches, err := bp.batchOrm.GetBatchesByBundleHash(ctx, task.TaskID) diff --git a/coordinator/internal/logic/provertask/chunk_prover_task.go b/coordinator/internal/logic/provertask/chunk_prover_task.go index 5cd82ed313..406a960b27 100644 --- a/coordinator/internal/logic/provertask/chunk_prover_task.go +++ b/coordinator/internal/logic/provertask/chunk_prover_task.go @@ -3,14 +3,12 @@ package provertask import ( "context" "encoding/json" - "errors" "fmt" "time" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/params" "gorm.io/gorm" @@ -54,20 +52,6 @@ func NewChunkProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go return cp } -// proverHardForkSanityCheck check the prover task's hard-fork name -// and prover-task's hard-fork name is the same -func (cp *ChunkProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, chunkTask *orm.Chunk) (string, error) { - hardForkName, getHardForkErr := cp.hardForkName(ctx, chunkTask) - if getHardForkErr != nil { - return "", getHardForkErr - } - - if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { - return "", errors.New("prover task's hard-fork name is not the same as the chunk's hard-fork name") - } - return hardForkName, nil -} - // Assign the chunk proof which need to prove func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) { taskCtx, err := cp.checkParameter(ctx) @@ -115,8 +99,10 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return nil, nil } + taskCtx.taskType = message.ProofTypeChunk + taskCtx.chunkTask = tmpChunkTask var checkErr error - hardForkName, checkErr = cp.hardForkSanityCheck(ctx, taskCtx, tmpChunkTask) + hardForkName, checkErr = cp.hardForkSanityCheck(ctx, taskCtx) if checkErr != nil { log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr) return nil, nil @@ -192,15 +178,6 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato return taskMsg, nil } -func (cp *ChunkProverTask) hardForkName(ctx *gin.Context, chunkTask *orm.Chunk) (string, error) { - l2Block, getBlockErr := cp.blockOrm.GetL2BlockByNumber(ctx.Copy(), chunkTask.StartBlockNumber) - if getBlockErr != nil { - return "", getBlockErr - } - hardForkName := encoding.GetHardforkName(cp.chainCfg, l2Block.Number, l2Block.BlockTimestamp) - return hardForkName, nil -} - func (cp *ChunkProverTask) formatProverTask(ctx context.Context, task *orm.ProverTask, hardForkName string) (*coordinatorType.GetTaskSchema, error) { // Get block hashes. blockHashes, dbErr := cp.blockOrm.GetL2BlockHashesByChunkHash(ctx, task.TaskID) diff --git a/coordinator/internal/logic/provertask/prover_task.go b/coordinator/internal/logic/provertask/prover_task.go index 2a2b20df8d..8f038b3878 100644 --- a/coordinator/internal/logic/provertask/prover_task.go +++ b/coordinator/internal/logic/provertask/prover_task.go @@ -9,9 +9,11 @@ import ( "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/scroll-tech/da-codec/encoding" "github.com/scroll-tech/go-ethereum/params" "gorm.io/gorm" + "scroll-tech/common/types/message" "scroll-tech/coordinator/internal/config" "scroll-tech/coordinator/internal/orm" coordinatorType "scroll-tech/coordinator/internal/types" @@ -52,6 +54,76 @@ type proverTaskContext struct { ProverVersion string ProverProviderType uint8 HardForkNames map[string]struct{} + + taskType message.ProofType + chunkTask *orm.Chunk + batchTask *orm.Batch + bundleTask *orm.Bundle +} + +// hardForkName get the chunk/batch/bundle hard fork name +func (b *BaseProverTask) hardForkName(ctx *gin.Context, taskCtx *proverTaskContext) (string, error) { + switch { + case taskCtx.taskType == message.ProofTypeChunk: + if taskCtx.chunkTask == nil { + return "", errors.New("chunk task is nil") + } + l2Block, getBlockErr := b.blockOrm.GetL2BlockByNumber(ctx.Copy(), taskCtx.chunkTask.StartBlockNumber) + if getBlockErr != nil { + return "", getBlockErr + } + hardForkName := encoding.GetHardforkName(b.chainCfg, l2Block.Number, l2Block.BlockTimestamp) + return hardForkName, nil + + case taskCtx.taskType == message.ProofTypeBatch: + if taskCtx.batchTask == nil { + return "", errors.New("batch task is nil") + } + startChunk, getChunkErr := b.chunkOrm.GetChunkByHash(ctx, taskCtx.batchTask.StartChunkHash) + if getChunkErr != nil { + return "", getChunkErr + } + l2Block, getBlockErr := b.blockOrm.GetL2BlockByNumber(ctx.Copy(), startChunk.StartBlockNumber) + if getBlockErr != nil { + return "", getBlockErr + } + hardForkName := encoding.GetHardforkName(b.chainCfg, l2Block.Number, l2Block.BlockTimestamp) + return hardForkName, nil + + case taskCtx.taskType == message.ProofTypeBundle: + if taskCtx.bundleTask == nil { + return "", errors.New("bundle task is nil") + } + startBatch, getBatchErr := b.batchOrm.GetBatchByHash(ctx, taskCtx.bundleTask.StartBatchHash) + if getBatchErr != nil { + return "", getBatchErr + } + startChunk, getChunkErr := b.chunkOrm.GetChunkByHash(ctx, startBatch.StartChunkHash) + if getChunkErr != nil { + return "", getChunkErr + } + l2Block, getBlockErr := b.blockOrm.GetL2BlockByNumber(ctx.Copy(), startChunk.StartBlockNumber) + if getBlockErr != nil { + return "", getBlockErr + } + hardForkName := encoding.GetHardforkName(b.chainCfg, l2Block.Number, l2Block.BlockTimestamp) + return hardForkName, nil + default: + return "", errors.New("illegal task type") + } +} + +// and prover-task's hard-fork name is the same +func (b *BaseProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext) (string, error) { + hardForkName, getHardForkErr := b.hardForkName(ctx, taskCtx) + if getHardForkErr != nil { + return "", getHardForkErr + } + + if _, ok := taskCtx.HardForkNames[hardForkName]; !ok { + return "", errors.New("to be assigned prover task's hard-fork name is not the same as prover") + } + return hardForkName, nil } // checkParameter check the prover task parameter illegal From 207d249b5b6b2fc1cd820d7062126d096e1f2613 Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 11:15:45 +0800 Subject: [PATCH 4/8] format chunk prover task code --- coordinator/internal/logic/provertask/chunk_prover_task.go | 1 + 1 file changed, 1 insertion(+) diff --git a/coordinator/internal/logic/provertask/chunk_prover_task.go b/coordinator/internal/logic/provertask/chunk_prover_task.go index 406a960b27..1bd58a7449 100644 --- a/coordinator/internal/logic/provertask/chunk_prover_task.go +++ b/coordinator/internal/logic/provertask/chunk_prover_task.go @@ -101,6 +101,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato taskCtx.taskType = message.ProofTypeChunk taskCtx.chunkTask = tmpChunkTask + var checkErr error hardForkName, checkErr = cp.hardForkSanityCheck(ctx, taskCtx) if checkErr != nil { From fa110ef4206e9b5d4cdf87f17382592439ff0efc Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 11:16:45 +0800 Subject: [PATCH 5/8] add comments --- coordinator/internal/logic/provertask/prover_task.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coordinator/internal/logic/provertask/prover_task.go b/coordinator/internal/logic/provertask/prover_task.go index 8f038b3878..0568bfb433 100644 --- a/coordinator/internal/logic/provertask/prover_task.go +++ b/coordinator/internal/logic/provertask/prover_task.go @@ -74,7 +74,7 @@ func (b *BaseProverTask) hardForkName(ctx *gin.Context, taskCtx *proverTaskConte } hardForkName := encoding.GetHardforkName(b.chainCfg, l2Block.Number, l2Block.BlockTimestamp) return hardForkName, nil - + case taskCtx.taskType == message.ProofTypeBatch: if taskCtx.batchTask == nil { return "", errors.New("batch task is nil") @@ -113,7 +113,7 @@ func (b *BaseProverTask) hardForkName(ctx *gin.Context, taskCtx *proverTaskConte } } -// and prover-task's hard-fork name is the same +// hardForkSanityCheck check the task's hard fork name is the same as prover func (b *BaseProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext) (string, error) { hardForkName, getHardForkErr := b.hardForkName(ctx, taskCtx) if getHardForkErr != nil { From 2ff333b3297da1b0e90d5ac27669c01911623015 Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 14:46:17 +0800 Subject: [PATCH 6/8] fmt --- coordinator/internal/logic/provertask/prover_task.go | 1 + 1 file changed, 1 insertion(+) diff --git a/coordinator/internal/logic/provertask/prover_task.go b/coordinator/internal/logic/provertask/prover_task.go index 0568bfb433..4b9f60bf0d 100644 --- a/coordinator/internal/logic/provertask/prover_task.go +++ b/coordinator/internal/logic/provertask/prover_task.go @@ -14,6 +14,7 @@ import ( "gorm.io/gorm" "scroll-tech/common/types/message" + "scroll-tech/coordinator/internal/config" "scroll-tech/coordinator/internal/orm" coordinatorType "scroll-tech/coordinator/internal/types" From fa989ca00865b34b74ee59eafc173d6380c521bd Mon Sep 17 00:00:00 2001 From: georgehao Date: Wed, 12 Mar 2025 14:55:25 +0800 Subject: [PATCH 7/8] fmt --- Makefile | 12 ++++++------ .../internal/logic/provertask/bundle_prover_task.go | 8 ++++---- coordinator/internal/orm/orm_test.go | 3 ++- coordinator/test/api_test.go | 3 ++- rollup/internal/config/config.go | 3 ++- rollup/internal/controller/sender/sender_test.go | 3 ++- rollup/internal/controller/watcher/watcher_test.go | 3 ++- rollup/internal/orm/orm_test.go | 3 ++- rollup/tests/bridge_test.go | 3 ++- tests/integration-test/integration_test.go | 6 ++++-- 10 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 71edb5e96a..da25f5d335 100644 --- a/Makefile +++ b/Makefile @@ -31,12 +31,12 @@ fmt: ## Format the code cd $(PWD)/rollup/ && go mod tidy cd $(PWD)/tests/integration-test/ && go mod tidy - goimports -local $(PWD)/bridge-history-api/ -w . - goimports -local $(PWD)/common/ -w . - goimports -local $(PWD)/coordinator/ -w . - goimports -local $(PWD)/database/ -w . - goimports -local $(PWD)/rollup/ -w . - goimports -local $(PWD)/tests/integration-test/ -w . + goimports -local scroll-tech/bridge-history-api/ -w . + goimports -local scroll-tech/common/ -w . + goimports -local scroll-tech/coordinator/ -w . + goimports -local scroll-tech/database/ -w . + goimports -local scroll-tech/rollup/ -w . + goimports -local scroll-tech/tests/integration-test/ -w . dev_docker: ## Build docker images for development/testing usages docker pull postgres diff --git a/coordinator/internal/logic/provertask/bundle_prover_task.go b/coordinator/internal/logic/provertask/bundle_prover_task.go index e8b4681ce8..87e7b214fc 100644 --- a/coordinator/internal/logic/provertask/bundle_prover_task.go +++ b/coordinator/internal/logic/provertask/bundle_prover_task.go @@ -13,14 +13,14 @@ import ( "github.com/scroll-tech/go-ethereum/params" "gorm.io/gorm" - "scroll-tech/common/types" - "scroll-tech/common/types/message" - "scroll-tech/common/utils" - "scroll-tech/coordinator/internal/config" "scroll-tech/coordinator/internal/orm" coordinatorType "scroll-tech/coordinator/internal/types" cutils "scroll-tech/coordinator/internal/utils" + + "scroll-tech/common/types" + "scroll-tech/common/types/message" + "scroll-tech/common/utils" ) // BundleProverTask is prover task implement for bundle proof diff --git a/coordinator/internal/orm/orm_test.go b/coordinator/internal/orm/orm_test.go index 0fcc84a2f4..d0006a2bf4 100644 --- a/coordinator/internal/orm/orm_test.go +++ b/coordinator/internal/orm/orm_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/testcontainers" "scroll-tech/common/types" "scroll-tech/common/types/message" "scroll-tech/common/utils" - "scroll-tech/database/migrate" ) var ( diff --git a/coordinator/test/api_test.go b/coordinator/test/api_test.go index f637c88caf..6337fa1f65 100644 --- a/coordinator/test/api_test.go +++ b/coordinator/test/api_test.go @@ -20,11 +20,12 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/testcontainers" "scroll-tech/common/types" "scroll-tech/common/types/message" "scroll-tech/common/version" - "scroll-tech/database/migrate" "scroll-tech/coordinator/internal/config" "scroll-tech/coordinator/internal/controller/api" diff --git a/rollup/internal/config/config.go b/rollup/internal/config/config.go index 725d1e492d..71d57b9101 100644 --- a/rollup/internal/config/config.go +++ b/rollup/internal/config/config.go @@ -3,9 +3,10 @@ package config import ( "fmt" "reflect" - "scroll-tech/common/database" "strings" + "scroll-tech/common/database" + "github.com/mitchellh/mapstructure" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/rpc" diff --git a/rollup/internal/controller/sender/sender_test.go b/rollup/internal/controller/sender/sender_test.go index 50a41d2066..040c98edc8 100644 --- a/rollup/internal/controller/sender/sender_test.go +++ b/rollup/internal/controller/sender/sender_test.go @@ -27,9 +27,10 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/testcontainers" "scroll-tech/common/types" - "scroll-tech/database/migrate" bridgeAbi "scroll-tech/rollup/abi" "scroll-tech/rollup/internal/config" diff --git a/rollup/internal/controller/watcher/watcher_test.go b/rollup/internal/controller/watcher/watcher_test.go index 465b873e33..4787b17767 100644 --- a/rollup/internal/controller/watcher/watcher_test.go +++ b/rollup/internal/controller/watcher/watcher_test.go @@ -11,9 +11,10 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/database" "scroll-tech/common/testcontainers" - "scroll-tech/database/migrate" "scroll-tech/rollup/internal/config" ) diff --git a/rollup/internal/orm/orm_test.go b/rollup/internal/orm/orm_test.go index 83a1df5f8d..baaeb4b5e0 100644 --- a/rollup/internal/orm/orm_test.go +++ b/rollup/internal/orm/orm_test.go @@ -13,10 +13,11 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/testcontainers" "scroll-tech/common/types" "scroll-tech/common/types/message" - "scroll-tech/database/migrate" "scroll-tech/rollup/internal/utils" ) diff --git a/rollup/tests/bridge_test.go b/rollup/tests/bridge_test.go index 96fbc2f2d3..8a8bd9a12d 100644 --- a/rollup/tests/bridge_test.go +++ b/rollup/tests/bridge_test.go @@ -22,10 +22,11 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/database/migrate" + "scroll-tech/common/database" tc "scroll-tech/common/testcontainers" "scroll-tech/common/utils" - "scroll-tech/database/migrate" bcmd "scroll-tech/rollup/cmd" "scroll-tech/rollup/mock_bridge" diff --git a/tests/integration-test/integration_test.go b/tests/integration-test/integration_test.go index af448ecf1b..28527e0247 100644 --- a/tests/integration-test/integration_test.go +++ b/tests/integration-test/integration_test.go @@ -12,11 +12,13 @@ import ( "github.com/stretchr/testify/assert" "gorm.io/gorm" + "scroll-tech/integration-test/orm" + + "scroll-tech/database/migrate" + "scroll-tech/common/testcontainers" "scroll-tech/common/utils" "scroll-tech/common/version" - "scroll-tech/database/migrate" - "scroll-tech/integration-test/orm" capp "scroll-tech/coordinator/cmd/api/app" From 8ecc1b38834e2311b8feb6c31dbbfbf2d0c8e76e Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Wed, 12 Mar 2025 15:00:03 +0800 Subject: [PATCH 8/8] a typo fix --- coordinator/internal/controller/api/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coordinator/internal/controller/api/auth.go b/coordinator/internal/controller/api/auth.go index 7073d123ab..b38f0d827a 100644 --- a/coordinator/internal/controller/api/auth.go +++ b/coordinator/internal/controller/api/auth.go @@ -46,7 +46,7 @@ func (a *AuthController) Login(c *gin.Context) (interface{}, error) { hardForkNames, err := a.loginLogic.ProverHardForkName(&login) if err != nil { - return "", fmt.Errorf("prover hard name failure:%w", err) + return "", fmt.Errorf("prover hard fork name failure:%w", err) } // check the challenge is used, if used, return failure