Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix coordiantor assign task strategy #1495

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: fmt dev_docker build_test_docker run_test_docker clean update

L2GETH_TAG=scroll-v5.5.1
L2GETH_TAG=scroll-v5.6.3

help: ## Display this help message
@grep -h \
Expand Down Expand Up @@ -40,8 +40,8 @@ fmt: ## Format the code

dev_docker: ## Build docker images for development/testing usages
docker pull postgres
docker build -t scroll_l1geth ./common/testcontainers/docker/l1geth/
docker build -t scroll_l2geth ./common/testcontainers/docker/l2geth/
docker build -t scroll_l1geth --platform linux/amd64 ./common/testcontainers/docker/l1geth/
docker build -t scroll_l2geth --platform linux/amd64 ./common/testcontainers/docker/l2geth/

clean: ## Empty out the bin folder
@rm -rf build/bin
2 changes: 1 addition & 1 deletion common/forks/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetHardforkName(config *params.ChainConfig, blockHeight, blockTimestamp uin
} else if !config.IsDarwinV2(blockTimestamp) {
return "darwin"
} else {
return "darwinv2"
return "darwinV2"
}
}

Expand Down
20 changes: 16 additions & 4 deletions coordinator/cmd/api/app/mock_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,25 @@ func (c *CoordinatorApp) MockConfig(store bool) error {
}
// Reset prover manager config for manager test cases.
cfg.ProverManager = &coordinatorConfig.ProverManager{
ProversPerSession: 1,
Verifier: &coordinatorConfig.VerifierConfig{MockMode: true},
ProversPerSession: 1,
Verifier: &coordinatorConfig.VerifierConfig{
MockMode: true,
LowVersionCircuit: &coordinatorConfig.CircuitConfig{
ParamsPath: "",
AssetsPath: "",
ForkName: "darwin",
MinProverVersion: "v4.2.0",
},
HighVersionCircuit: &coordinatorConfig.CircuitConfig{
ParamsPath: "",
AssetsPath: "",
ForkName: "darwinV2",
MinProverVersion: "v4.3.0",
},
},
BatchCollectionTimeSec: 60,
ChunkCollectionTimeSec: 60,
SessionAttempts: 10,
MaxVerifierWorkers: 4,
MinProverVersion: "v1.0.0",
}
endpoint, err := c.testApps.GetDBEndPoint()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions coordinator/conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"low_version_circuit": {
"params_path": "params",
"assets_path": "assets",
"fork_name": ""
"fork_name": "darwin",
"min_prover_version": "v4.4.43-37af5ef5-38a68e2-1c5093c"
},
"high_version_circuit": {
"params_path": "params",
"assets_path": "assets",
"fork_name": ""
"fork_name": "darwinV2",
"min_prover_version": "v4.4.45"
}
},
"max_verifier_workers": 4,
"min_prover_version": "v1.0.0"
}
},
"db": {
"driver_name": "postgres",
Expand Down
11 changes: 4 additions & 7 deletions coordinator/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ type ProverManager struct {
ChunkCollectionTimeSec int `json:"chunk_collection_time_sec"`
// BundleCollectionTimeSec bundle Proof collection time (in seconds).
BundleCollectionTimeSec int `json:"bundle_collection_time_sec"`
// Max number of workers in verifier worker pool
MaxVerifierWorkers int `json:"max_verifier_workers"`
// MinProverVersion is the minimum version of the prover that is required.
MinProverVersion string `json:"min_prover_version"`
}

// L2 loads l2geth configuration items.
Expand All @@ -52,9 +48,10 @@ type Config struct {

// CircuitConfig circuit items.
type CircuitConfig struct {
ParamsPath string `json:"params_path"`
AssetsPath string `json:"assets_path"`
ForkName string `json:"fork_name"`
ParamsPath string `json:"params_path"`
AssetsPath string `json:"assets_path"`
ForkName string `json:"fork_name"`
MinProverVersion string `json:"min_prover_version"`
}

// VerifierConfig load zk verifier config.
Expand Down
35 changes: 20 additions & 15 deletions coordinator/internal/controller/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"github.com/scroll-tech/go-ethereum/log"
"gorm.io/gorm"

"scroll-tech/coordinator/internal/config"
Expand Down Expand Up @@ -45,33 +44,34 @@ 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)
if err != nil {
return "", fmt.Errorf("prover hard name failure:%w", err)
}

// check the challenge is used, if used, return failure
if err := a.loginLogic.InsertChallengeString(c, login.Message.Challenge); err != nil {
return "", fmt.Errorf("login insert challenge string failure:%w", err)
}
return login, nil

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

return returnData, nil
}

// PayloadFunc returns jwt.MapClaims with {public key, prover name}.
func (a *AuthController) PayloadFunc(data interface{}) jwt.MapClaims {
v, ok := data.(types.LoginParameter)
v, ok := data.(types.LoginParameterWithHardForkName)
if !ok {
return jwt.MapClaims{}
}

publicKey := v.PublicKey
if publicKey == "" {
var err error
publicKey, err = v.RecoverPublicKeyFromSignature()
if err != nil {
// do not handle error here since already called v.Verify() beforehands so there should be no error
// add log just in case some error happens
log.Error("impossible path: failed to recover public key from signature", "error", err.Error())
}
}

return jwt.MapClaims{
types.PublicKey: publicKey,
types.HardForkName: v.HardForkName,
types.PublicKey: v.PublicKey,
types.ProverName: v.Message.ProverName,
types.ProverVersion: v.Message.ProverVersion,
}
Expand All @@ -91,5 +91,10 @@ func (a *AuthController) IdentityHandler(c *gin.Context) interface{} {
if proverVersion, ok := claims[types.ProverVersion]; ok {
c.Set(types.ProverVersion, proverVersion)
}

if hardForkName, ok := claims[types.HardForkName]; ok {
c.Set(types.HardForkName, hardForkName)
}

return nil
}
4 changes: 0 additions & 4 deletions coordinator/internal/controller/api/get_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ func (ptc *GetTaskController) GetTasks(ctx *gin.Context) {

func (ptc *GetTaskController) proofType(para *coordinatorType.GetTaskParameter) message.ProofType {
var proofTypes []message.ProofType
if para.TaskType != 0 {
proofTypes = append(proofTypes, message.ProofType(para.TaskType))
}

for _, proofType := range para.TaskTypes {
proofTypes = append(proofTypes, message.ProofType(proofType))
}
Expand Down
48 changes: 34 additions & 14 deletions coordinator/internal/logic/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ type LoginLogic struct {
chunkVks map[string]struct{}
batchVKs map[string]struct{}
bundleVks map[string]struct{}

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)
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

return &LoginLogic{
cfg: cfg,
chunkVks: vf.ChunkVKMap,
batchVKs: vf.BatchVKMap,
bundleVks: vf.BundleVkMap,
challengeOrm: orm.NewChallenge(db),
cfg: cfg,
chunkVks: vf.ChunkVKMap,
batchVKs: vf.BatchVKMap,
bundleVks: vf.BundleVkMap,
challengeOrm: orm.NewChallenge(db),
proverVersionHardForkMap: proverVersionHardForkMap,
}
}

Expand All @@ -42,18 +56,16 @@ func (l *LoginLogic) InsertChallengeString(ctx *gin.Context, challenge string) e
}

func (l *LoginLogic) Check(login *types.LoginParameter) error {
if login.PublicKey != "" {
verify, err := login.Verify()
if err != nil || !verify {
log.Error("auth message verify failure", "prover_name", login.Message.ProverName,
"prover_version", login.Message.ProverVersion, "message", login.Message)
return errors.New("auth message verify failure")
}
verify, err := login.Verify()
if err != nil || !verify {
log.Error("auth message verify failure", "prover_name", login.Message.ProverName,
"prover_version", login.Message.ProverVersion, "message", login.Message)
return errors.New("auth message verify failure")
}

if !version.CheckScrollRepoVersion(login.Message.ProverVersion, l.cfg.ProverManager.MinProverVersion) {
if !version.CheckScrollRepoVersion(login.Message.ProverVersion, l.cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion) {
return fmt.Errorf("incompatible prover version. please upgrade your prover, minimum allowed version: %s, actual version: %s",
l.cfg.ProverManager.MinProverVersion, login.Message.ProverVersion)
l.cfg.ProverManager.Verifier.LowVersionCircuit.MinProverVersion, login.Message.ProverVersion)
}

if len(login.Message.ProverTypes) > 0 {
Expand Down Expand Up @@ -91,3 +103,11 @@ func (l *LoginLogic) Check(login *types.LoginParameter) error {
}
return nil
}

// ProverHardforkName retrieves hard fork name which prover belongs to
func (l *LoginLogic) ProverHardforkName(login *types.LoginParameter) (string, error) {
if _, ok := l.proverVersionHardForkMap[login.Message.ProverVersion]; ok {
return l.proverVersionHardForkMap[login.Message.ProverVersion], nil
}
return "", fmt.Errorf("invalid prover prover_version:%s", login.Message.ProverVersion)
}
7 changes: 7 additions & 0 deletions coordinator/internal/logic/provertask/batch_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func (bp *BatchProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
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)
return nil, ErrCoordinatorInternalFailure
}

proverTask := orm.ProverTask{
TaskID: batchTask.Hash,
ProverPublicKey: taskCtx.PublicKey,
Expand Down
7 changes: 7 additions & 0 deletions coordinator/internal/logic/provertask/bundle_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
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)
return nil, ErrCoordinatorInternalFailure
}

proverTask := orm.ProverTask{
TaskID: bundleTask.Hash,
ProverPublicKey: taskCtx.PublicKey,
Expand Down
7 changes: 7 additions & 0 deletions coordinator/internal/logic/provertask/chunk_prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
return nil, ErrCoordinatorInternalFailure
}

if hardForkName != taskCtx.HardForkName {
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)
return nil, ErrCoordinatorInternalFailure
}

proverTask := orm.ProverTask{
TaskID: chunkTask.Hash,
ProverPublicKey: taskCtx.PublicKey,
Expand Down
7 changes: 7 additions & 0 deletions coordinator/internal/logic/provertask/prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type proverTaskContext struct {
PublicKey string
ProverName string
ProverVersion string
HardForkName string
}

// checkParameter check the prover task parameter illegal
Expand All @@ -73,6 +74,12 @@ func (b *BaseProverTask) checkParameter(ctx *gin.Context) (*proverTaskContext, e
}
ptc.ProverVersion = proverVersion.(string)

hardForkName, hardForkNameExist := ctx.Get(coordinatorType.HardForkName)
if !hardForkNameExist {
return nil, errors.New("get hard fork name from context failed")
}
ptc.HardForkName = hardForkName.(string)

isBlocked, err := b.proverBlockListOrm.IsPublicKeyBlocked(ctx.Copy(), publicKey.(string))
if err != nil {
return nil, fmt.Errorf("failed to check whether the public key %s is blocked before assigning a chunk task, err: %w, proverName: %s, proverVersion: %s", publicKey, err, proverName, proverVersion)
Expand Down
19 changes: 0 additions & 19 deletions coordinator/internal/orm/prover_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@ func (o *ProverTask) GetProverTasksByHashes(ctx context.Context, taskType messag
return proverTasks, nil
}

// GetAssignedProverTaskByTaskIDAndProver get prover task taskID and public key
// TODO: when prover all upgrade need DEPRECATED this function
func (o *ProverTask) GetAssignedProverTaskByTaskIDAndProver(ctx context.Context, taskType message.ProofType, taskID, proverPublicKey, proverVersion string) (*ProverTask, error) {
db := o.db.WithContext(ctx)
db = db.Model(&ProverTask{})
db = db.Where("task_type", int(taskType))
db = db.Where("task_id", taskID)
db = db.Where("prover_public_key", proverPublicKey)
db = db.Where("prover_version", proverVersion)
db = db.Where("proving_status", types.ProverAssigned)

var proverTask ProverTask
err := db.First(&proverTask).Error
if err != nil {
return nil, fmt.Errorf("ProverTask.GetProverTaskByTaskIDAndProver err:%w, taskID:%s, pubkey:%s, prover_version:%s", err, taskID, proverPublicKey, proverVersion)
}
return &proverTask, nil
}

// GetProverTaskByUUIDAndPublicKey get prover task taskID by uuid and public key
func (o *ProverTask) GetProverTaskByUUIDAndPublicKey(ctx context.Context, uuid, publicKey string) (*ProverTask, error) {
db := o.db.WithContext(ctx)
Expand Down
Loading
Loading