Skip to content

Commit

Permalink
fix coordiantor bug (#1513)
Browse files Browse the repository at this point in the history
Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com>
Co-authored-by: georgehao <georgehao@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent bf48417 commit 7b00055
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.54"
var tag = "v4.4.55"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
4 changes: 2 additions & 2 deletions coordinator/internal/controller/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *AuthController) Login(c *gin.Context) (interface{}, error) {
return "", fmt.Errorf("check the login parameter failure: %w", err)
}

hardForkName, err := a.loginLogic.ProverHardForkName(&login)
hardForkNames, err := a.loginLogic.ProverHardForkName(&login)
if err != nil {
return "", fmt.Errorf("prover hard name failure:%w", err)
}
Expand All @@ -55,7 +55,7 @@ func (a *AuthController) Login(c *gin.Context) (interface{}, error) {
}

returnData := types.LoginParameterWithHardForkName{
HardForkName: hardForkName,
HardForkName: hardForkNames,
LoginParameter: login,
}

Expand Down
16 changes: 10 additions & 6 deletions coordinator/internal/logic/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ type LoginLogic struct {
batchVKs map[string]struct{}
bundleVks map[string]struct{}

proverVersionHardForkMap map[string]string
proverVersionHardForkMap map[string][]string
}

// NewLoginLogic new a LoginLogic
func NewLoginLogic(db *gorm.DB, cfg *config.Config, vf *verifier.Verifier) *LoginLogic {
proverVersionHardForkMap := make(map[string]string)
proverVersionHardForkMap := make(map[string][]string)
if version.CheckScrollRepoVersion(cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion, cfg.ProverManager.Verifier.HighVersionCircuit.MinProverVersion) {
log.Error("config file error, low verifier min_prover_version should not more than high verifier min_prover_version",
"low verifier min_prover_version", cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion,
"high verifier min_prover_version", cfg.ProverManager.Verifier.HighVersionCircuit.MinProverVersion)
panic("verifier config file error")
}

proverVersionHardForkMap[cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion] = cfg.ProverManager.Verifier.LowVersionCircuit.ForkName
proverVersionHardForkMap[cfg.ProverManager.Verifier.HighVersionCircuit.MinProverVersion] = cfg.ProverManager.Verifier.HighVersionCircuit.ForkName
var highHardForks []string
highHardForks = append(highHardForks, cfg.ProverManager.Verifier.HighVersionCircuit.ForkName)
highHardForks = append(highHardForks, cfg.ProverManager.Verifier.LowVersionCircuit.ForkName)
proverVersionHardForkMap[cfg.ProverManager.Verifier.HighVersionCircuit.MinProverVersion] = highHardForks

proverVersionHardForkMap[cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion] = []string{cfg.ProverManager.Verifier.LowVersionCircuit.ForkName}

return &LoginLogic{
cfg: cfg,
Expand Down Expand Up @@ -113,8 +117,8 @@ func (l *LoginLogic) ProverHardForkName(login *types.LoginParameter) (string, er
}

proverVersion := proverVersionSplits[0]
if hardForkName, ok := l.proverVersionHardForkMap[proverVersion]; ok {
return hardForkName, nil
if hardForkNames, ok := l.proverVersionHardForkMap[proverVersion]; ok {
return strings.Join(hardForkNames, ","), nil
}

return "", fmt.Errorf("invalid prover prover_version:%s", login.Message.ProverVersion)
Expand Down
8 changes: 5 additions & 3 deletions coordinator/internal/logic/provertask/batch_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
bp.recoverActiveAttempts(ctx, batchTask)
log.Error("incompatible prover version. requisite hard fork name:%s, prover hard fork name:%s, batch task_id:%s",
hardForkName, taskCtx.HardForkName, "task_id", batchTask.Hash)
log.Error("incompatible prover version",
"requisite hard fork name", hardForkName,
"prover hard fork name", taskCtx.HardForkNames,
"task_id", batchTask.Hash)
return nil, ErrCoordinatorInternalFailure
}

Expand Down
8 changes: 5 additions & 3 deletions coordinator/internal/logic/provertask/bundle_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
bp.recoverActiveAttempts(ctx, bundleTask)
log.Error("incompatible prover version. requisite hard fork name:%s, prover hard fork name:%s, bundle task_id:%s",
hardForkName, taskCtx.HardForkName, "task_id", bundleTask.Hash)
log.Error("incompatible prover version",
"requisite hard fork name", hardForkName,
"prover hard fork name", taskCtx.HardForkNames,
"task_id", bundleTask.Hash)
return nil, ErrCoordinatorInternalFailure
}

Expand Down
8 changes: 5 additions & 3 deletions coordinator/internal/logic/provertask/chunk_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
if _, ok := taskCtx.HardForkNames[hardForkName]; !ok {
cp.recoverActiveAttempts(ctx, chunkTask)
log.Error("incompatible prover version. requisite hard fork name:%s, prover hard fork name:%s, chunk task_id:%s",
hardForkName, taskCtx.HardForkName, "task_id", chunkTask.Hash)
log.Error("incompatible prover version",
"requisite hard fork name", hardForkName,
"prover hard fork name", taskCtx.HardForkNames,
"task_id", chunkTask.Hash)
return nil, ErrCoordinatorInternalFailure
}

Expand Down
11 changes: 8 additions & 3 deletions coordinator/internal/logic/provertask/prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provertask
import (
"errors"
"fmt"
"strings"
"sync"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -49,12 +50,13 @@ type proverTaskContext struct {
PublicKey string
ProverName string
ProverVersion string
HardForkName string
HardForkNames map[string]struct{}
}

// checkParameter check the prover task parameter illegal
func (b *BaseProverTask) checkParameter(ctx *gin.Context) (*proverTaskContext, error) {
var ptc proverTaskContext
ptc.HardForkNames = make(map[string]struct{})

publicKey, publicKeyExist := ctx.Get(coordinatorType.PublicKey)
if !publicKeyExist {
Expand All @@ -74,11 +76,14 @@ func (b *BaseProverTask) checkParameter(ctx *gin.Context) (*proverTaskContext, e
}
ptc.ProverVersion = proverVersion.(string)

hardForkName, hardForkNameExist := ctx.Get(coordinatorType.HardForkName)
hardForkNamesStr, hardForkNameExist := ctx.Get(coordinatorType.HardForkName)
if !hardForkNameExist {
return nil, errors.New("get hard fork name from context failed")
}
ptc.HardForkName = hardForkName.(string)
hardForkNames := strings.Split(hardForkNamesStr.(string), ",")
for _, hardForkName := range hardForkNames {
ptc.HardForkNames[hardForkName] = struct{}{}
}

isBlocked, err := b.proverBlockListOrm.IsPublicKeyBlocked(ctx.Copy(), publicKey.(string))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions coordinator/internal/types/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestGenerateSignature(t *testing.T) {
authMsg := LoginParameter{
Message: Message{
ProverName: "test",
ProverVersion: "v4.4.43",
Challenge: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQzODg4MTEsIm9yaWdfaWF0IjoxNzI0Mzg1MjExLCJyYW5kb20iOiItZ2UxTjhRc1NlTzhxRVdBTk5KWWtFVjU3ekhJX1JmTGw5Mjdkb2pMTm5JPSJ9.TmcRyXTyfCAHIk5WXdpShck0qUUesTDmi_0IhD87GmA",
ProverVersion: "v4.4.43-37af5ef5-38a68e2-1c5093c",
Challenge: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQ4MzUyNzksIm9yaWdfaWF0IjoxNzI0ODMxNjc5LCJyYW5kb20iOiJRQ1lqU3g5U2I1RWEzbUM4anFBSndoR3VSUEpTdzFYWW9RUG9VcGxRRjRzPSJ9.92rT5UzGQVQO6Wvpz5fD5vHD1yuo_y1Xd_ExOhAAli0",
ProverTypes: []ProverType{ProverTypeChunk},
VKs: []string{"mock_vk"},
},
Expand Down

0 comments on commit 7b00055

Please sign in to comment.