Skip to content

Commit afe1a77

Browse files
committed
fix coordiantor assign bug
1 parent 228cba4 commit afe1a77

File tree

3 files changed

+75
-54
lines changed

3 files changed

+75
-54
lines changed

coordinator/internal/logic/provertask/batch_prover_task.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provertask
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -55,6 +56,20 @@ func NewBatchProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go
5556
return bp
5657
}
5758

59+
// proverHardForkSanityCheck check the prover task's hard-fork name
60+
// and prover-task's hard-fork name is the same
61+
func (bp *BatchProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, batchTask *orm.Batch) (string, error) {
62+
hardForkName, getHardForkErr := bp.hardForkName(ctx, batchTask)
63+
if getHardForkErr != nil {
64+
return "", getHardForkErr
65+
}
66+
67+
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
68+
return "", errors.New("hard-fork name is not the same as the batch's hard-fork name")
69+
}
70+
return hardForkName, nil
71+
}
72+
5873
// Assign load and assign batch tasks
5974
func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) {
6075
taskCtx, err := bp.checkParameter(ctx)
@@ -77,6 +92,7 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
7792
}
7893

7994
var batchTask *orm.Batch
95+
var hardForkName string
8096
for i := 0; i < 5; i++ {
8197
var getTaskError error
8298
var tmpBatchTask *orm.Batch
@@ -101,10 +117,17 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
101117
return nil, nil
102118
}
103119

120+
var checkErr error
121+
hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBatchTask)
122+
if checkErr != nil {
123+
log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr)
124+
return nil, nil
125+
}
126+
104127
// Don't dispatch the same failing job to the same prover
105-
proverTasks, getTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBatch, tmpBatchTask.Hash, 2)
106-
if getTaskError != nil {
107-
log.Error("failed to get prover tasks", "proof type", message.ProofTypeBatch.String(), "task ID", tmpBatchTask.Hash, "error", getTaskError)
128+
proverTasks, getFailedTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBatch, tmpBatchTask.Hash, 2)
129+
if getFailedTaskError != nil {
130+
log.Error("failed to get prover tasks", "proof type", message.ProofTypeBatch.String(), "task ID", tmpBatchTask.Hash, "error", getFailedTaskError)
108131
return nil, ErrCoordinatorInternalFailure
109132
}
110133
for i := 0; i < len(proverTasks); i++ {
@@ -135,22 +158,6 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
135158
return nil, nil
136159
}
137160

138-
hardForkName, getHardForkErr := bp.hardForkName(ctx, batchTask)
139-
if getHardForkErr != nil {
140-
bp.recoverActiveAttempts(ctx, batchTask)
141-
log.Error("retrieve hard fork name by batch failed", "task_id", batchTask.Hash, "err", getHardForkErr)
142-
return nil, ErrCoordinatorInternalFailure
143-
}
144-
145-
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
146-
bp.recoverActiveAttempts(ctx, batchTask)
147-
log.Debug("incompatible prover version",
148-
"requisite hard fork name", hardForkName,
149-
"prover hard fork name", taskCtx.HardForkNames,
150-
"task_id", batchTask.Hash)
151-
return nil, nil
152-
}
153-
154161
log.Info("start batch proof generation session", "task_id", batchTask.Hash, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName)
155162
proverTask := orm.ProverTask{
156163
TaskID: batchTask.Hash,

coordinator/internal/logic/provertask/bundle_prover_task.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provertask
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -55,6 +56,20 @@ func NewBundleProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *g
5556
return bp
5657
}
5758

59+
// proverHardForkSanityCheck check the prover task's hard-fork name
60+
// and prover-task's hard-fork name is the same
61+
func (bp *BundleProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, bundleTask *orm.Bundle) (string, error) {
62+
hardForkName, getHardForkErr := bp.hardForkName(ctx, bundleTask)
63+
if getHardForkErr != nil {
64+
return "", getHardForkErr
65+
}
66+
67+
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
68+
return "", errors.New("prover task's hard-fork name is not the same as the bundle's hard-fork name")
69+
}
70+
return hardForkName, nil
71+
}
72+
5873
// Assign load and assign batch tasks
5974
func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) {
6075
taskCtx, err := bp.checkParameter(ctx)
@@ -77,6 +92,7 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
7792
}
7893

7994
var bundleTask *orm.Bundle
95+
var hardForkName string
8096
for i := 0; i < 5; i++ {
8197
var getTaskError error
8298
var tmpBundleTask *orm.Bundle
@@ -101,6 +117,13 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
101117
return nil, nil
102118
}
103119

120+
var checkErr error
121+
hardForkName, checkErr = bp.hardForkSanityCheck(ctx, taskCtx, tmpBundleTask)
122+
if checkErr != nil {
123+
log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr)
124+
return nil, nil
125+
}
126+
104127
// Don't dispatch the same failing job to the same prover
105128
proverTasks, getTaskError := bp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeBundle, tmpBundleTask.Hash, 2)
106129
if getTaskError != nil {
@@ -135,22 +158,6 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
135158
return nil, nil
136159
}
137160

138-
hardForkName, getHardForkErr := bp.hardForkName(ctx, bundleTask)
139-
if getHardForkErr != nil {
140-
bp.recoverActiveAttempts(ctx, bundleTask)
141-
log.Error("retrieve hard fork name by bundle failed", "task_id", bundleTask.Hash, "err", getHardForkErr)
142-
return nil, ErrCoordinatorInternalFailure
143-
}
144-
145-
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
146-
bp.recoverActiveAttempts(ctx, bundleTask)
147-
log.Debug("incompatible prover version",
148-
"requisite hard fork name", hardForkName,
149-
"prover hard fork name", taskCtx.HardForkNames,
150-
"task_id", bundleTask.Hash)
151-
return nil, nil
152-
}
153-
154161
log.Info("start bundle proof generation session", "task index", bundleTask.Index, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName)
155162
proverTask := orm.ProverTask{
156163
TaskID: bundleTask.Hash,

coordinator/internal/logic/provertask/chunk_prover_task.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provertask
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -53,6 +54,20 @@ func NewChunkProverTask(cfg *config.Config, chainCfg *params.ChainConfig, db *go
5354
return cp
5455
}
5556

57+
// proverHardForkSanityCheck check the prover task's hard-fork name
58+
// and prover-task's hard-fork name is the same
59+
func (cp *ChunkProverTask) hardForkSanityCheck(ctx *gin.Context, taskCtx *proverTaskContext, chunkTask *orm.Chunk) (string, error) {
60+
hardForkName, getHardForkErr := cp.hardForkName(ctx, chunkTask)
61+
if getHardForkErr != nil {
62+
return "", getHardForkErr
63+
}
64+
65+
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
66+
return "", errors.New("prover task's hard-fork name is not the same as the chunk's hard-fork name")
67+
}
68+
return hardForkName, nil
69+
}
70+
5671
// Assign the chunk proof which need to prove
5772
func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinatorType.GetTaskParameter) (*coordinatorType.GetTaskSchema, error) {
5873
taskCtx, err := cp.checkParameter(ctx)
@@ -75,6 +90,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
7590
}
7691

7792
var chunkTask *orm.Chunk
93+
var hardForkName string
7894
for i := 0; i < 5; i++ {
7995
var getTaskError error
8096
var tmpChunkTask *orm.Chunk
@@ -99,10 +115,17 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
99115
return nil, nil
100116
}
101117

118+
var checkErr error
119+
hardForkName, checkErr = cp.hardForkSanityCheck(ctx, taskCtx, tmpChunkTask)
120+
if checkErr != nil {
121+
log.Debug("hard fork sanity check failed", "height", getTaskParameter.ProverHeight, "err", checkErr)
122+
return nil, nil
123+
}
124+
102125
// Don't dispatch the same failing job to the same prover
103-
proverTasks, getTaskError := cp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeChunk, tmpChunkTask.Hash, 2)
104-
if getTaskError != nil {
105-
log.Error("failed to get prover tasks", "proof type", message.ProofTypeChunk.String(), "task ID", tmpChunkTask.Hash, "error", getTaskError)
126+
proverTasks, getFailedTaskError := cp.proverTaskOrm.GetFailedProverTasksByHash(ctx.Copy(), message.ProofTypeChunk, tmpChunkTask.Hash, 2)
127+
if getFailedTaskError != nil {
128+
log.Error("failed to get prover tasks", "proof type", message.ProofTypeChunk.String(), "task ID", tmpChunkTask.Hash, "error", getFailedTaskError)
106129
return nil, ErrCoordinatorInternalFailure
107130
}
108131
for i := 0; i < len(proverTasks); i++ {
@@ -133,22 +156,6 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
133156
return nil, nil
134157
}
135158

136-
hardForkName, getHardForkErr := cp.hardForkName(ctx, chunkTask)
137-
if getHardForkErr != nil {
138-
cp.recoverActiveAttempts(ctx, chunkTask)
139-
log.Error("retrieve hard fork name by chunk failed", "task_id", chunkTask.Hash, "err", getHardForkErr)
140-
return nil, ErrCoordinatorInternalFailure
141-
}
142-
143-
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
144-
cp.recoverActiveAttempts(ctx, chunkTask)
145-
log.Debug("incompatible prover version",
146-
"requisite hard fork name", hardForkName,
147-
"prover hard fork name", taskCtx.HardForkNames,
148-
"task_id", chunkTask.Hash)
149-
return nil, nil
150-
}
151-
152159
log.Info("start chunk generation session", "task_id", chunkTask.Hash, "public key", taskCtx.PublicKey, "prover name", taskCtx.ProverName)
153160
proverTask := orm.ProverTask{
154161
TaskID: chunkTask.Hash,

0 commit comments

Comments
 (0)