mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
address comments
This commit is contained in:
@@ -33,7 +33,7 @@ func NewCoordinatorClient(cfg *config.CoordinatorConfig) (*CoordinatorClient, er
|
||||
}
|
||||
|
||||
// Login sends login request to the coordinator.
|
||||
func (c *CoordinatorClient) Login(ctx context.Context, req *ProverLoginRequest) (*ProverLoginResponse, error) {
|
||||
func (c *CoordinatorClient) Login(ctx context.Context, req *ProverLoginRequest) error {
|
||||
resp, err := c.client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(req).
|
||||
@@ -41,38 +41,42 @@ func (c *CoordinatorClient) Login(ctx context.Context, req *ProverLoginRequest)
|
||||
Post("/api/login")
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("login failed: %v", err)
|
||||
return fmt.Errorf("login failed: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode() != 200 {
|
||||
return fmt.Errorf("failed to login, status code: %v", resp.StatusCode())
|
||||
}
|
||||
|
||||
result := resp.Result().(*ProverLoginResponse)
|
||||
|
||||
if result.ErrCode != 200 {
|
||||
return fmt.Errorf("failed to login, error code: %v, error message: %v", result.ErrCode, result.ErrMsg)
|
||||
}
|
||||
|
||||
// store JWT token for future requests
|
||||
c.client.SetAuthToken(result.Data.Token)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTask sends a request to the coordinator to get prover task.
|
||||
func (c *CoordinatorClient) GetTask(ctx context.Context, req *GetTaskRequest) (*GetTaskResponse, error) {
|
||||
resp, err := c.client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(req).
|
||||
SetResult(&GetTaskResponse{}).
|
||||
Post("/api/prover_tasks")
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request for GetTask failed: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode() != 200 {
|
||||
return nil, fmt.Errorf("failed to login, status code: %v", resp.StatusCode())
|
||||
}
|
||||
|
||||
result := resp.Result().(*ProverLoginResponse)
|
||||
|
||||
if result.ErrCode != 200 {
|
||||
return nil, fmt.Errorf("failed to login, error code: %v, error message: %v", result.ErrCode, result.ErrMsg)
|
||||
}
|
||||
|
||||
// store JWT token for future requests
|
||||
c.client.SetAuthToken(result.Data.Token)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ProverTasks sends a request to the coordinator to get prover tasks.
|
||||
func (c *CoordinatorClient) ProverTasks(ctx context.Context, req *ProverTasksRequest) (*ProverTasksResponse, error) {
|
||||
resp, err := c.client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(req).
|
||||
SetResult(&ProverTasksResponse{}).
|
||||
Post("/api/prover_tasks")
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request for ProverTasks failed: %v", err)
|
||||
}
|
||||
|
||||
result := resp.Result().(*ProverTasksResponse)
|
||||
result := resp.Result().(*GetTaskResponse)
|
||||
|
||||
if result.ErrCode != 200 {
|
||||
return nil, fmt.Errorf("error code: %v, error message: %v", result.ErrCode, result.ErrMsg)
|
||||
|
||||
@@ -20,20 +20,20 @@ type ProverLoginResponse struct {
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
// ProverTasksRequest defines the request structure for ProverTasks API
|
||||
type ProverTasksRequest struct {
|
||||
// GetTaskRequest defines the request structure for GetTask API
|
||||
type GetTaskRequest struct {
|
||||
ProverVersion string `json:"prover_version"`
|
||||
ProverHeight uint64 `json:"prover_height"`
|
||||
ProofType message.ProofType `json:"proof_type"`
|
||||
TaskType message.ProofType `json:"task_type"`
|
||||
}
|
||||
|
||||
// ProverTasksResponse defines the response structure for ProverTasks API
|
||||
type ProverTasksResponse struct {
|
||||
// GetTaskResponse defines the response structure for GetTask API
|
||||
type GetTaskResponse struct {
|
||||
ErrCode int `json:"errcode,omitempty"`
|
||||
ErrMsg string `json:"errmsg,omitempty"`
|
||||
Data *struct {
|
||||
TaskID string `json:"task_id"`
|
||||
ProofType message.ProofType `json:"proof_type"`
|
||||
TaskType message.ProofType `json:"task_type"`
|
||||
ProofData string `json:"proof_data"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
@@ -43,7 +43,7 @@ type SubmitProofRequest struct {
|
||||
TaskID string `json:"task_id"`
|
||||
Status message.RespStatus `json:"status"`
|
||||
Error string `json:"error"`
|
||||
ProofType message.ProofType `json:"proof_type"`
|
||||
TaskType message.ProofType `json:"task_type"`
|
||||
Signature string `json:"signature"`
|
||||
Proof string `json:"proof"`
|
||||
}
|
||||
@@ -52,4 +52,5 @@ type SubmitProofRequest struct {
|
||||
type SubmitProofResponse struct {
|
||||
ErrCode int `json:"errcode,omitempty"`
|
||||
ErrMsg string `json:"errmsg,omitempty"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (r *Prover) PublicKey() string {
|
||||
// Start runs Prover.
|
||||
func (r *Prover) Start() {
|
||||
log.Info("start to login to coordinator")
|
||||
if _, err := r.coordinatorClient.Login(r.ctx, &client.ProverLoginRequest{
|
||||
if err := r.coordinatorClient.Login(r.ctx, &client.ProverLoginRequest{
|
||||
PublicKey: r.PublicKey(),
|
||||
ProverName: r.cfg.ProverName,
|
||||
}); err != nil {
|
||||
@@ -184,14 +184,14 @@ func (r *Prover) fetchTaskFromServer() (*store.ProvingTask, error) {
|
||||
}
|
||||
|
||||
// prepare the request
|
||||
req := &client.ProverTasksRequest{
|
||||
req := &client.GetTaskRequest{
|
||||
ProverVersion: version.Version,
|
||||
ProverHeight: latestBlockNumber,
|
||||
ProofType: r.Type(),
|
||||
TaskType: r.Type(),
|
||||
}
|
||||
|
||||
// send the request
|
||||
resp, err := r.coordinatorClient.ProverTasks(r.ctx, req)
|
||||
resp, err := r.coordinatorClient.GetTask(r.ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -204,12 +204,12 @@ func (r *Prover) fetchTaskFromServer() (*store.ProvingTask, error) {
|
||||
provingTask := &store.ProvingTask{
|
||||
Task: &message.TaskMsg{
|
||||
ID: resp.Data.TaskID,
|
||||
Type: resp.Data.ProofType,
|
||||
Type: resp.Data.TaskType,
|
||||
},
|
||||
Times: 0,
|
||||
}
|
||||
|
||||
switch resp.Data.ProofType {
|
||||
switch resp.Data.TaskType {
|
||||
case message.ProofTypeChunk:
|
||||
err := json.Unmarshal([]byte(resp.Data.ProofData), &provingTask.Task.ChunkTaskDetail)
|
||||
if err != nil {
|
||||
@@ -221,7 +221,7 @@ func (r *Prover) fetchTaskFromServer() (*store.ProvingTask, error) {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown proof type: %d", resp.Data.ProofType)
|
||||
return nil, fmt.Errorf("unknown proof type: %d", resp.Data.TaskType)
|
||||
}
|
||||
|
||||
return provingTask, nil
|
||||
@@ -305,7 +305,7 @@ func (r *Prover) signAndSubmitProof(msg *message.ProofDetail) error {
|
||||
TaskID: authZkProof.ProofDetail.ID,
|
||||
Status: authZkProof.ProofDetail.Status,
|
||||
Error: authZkProof.ProofDetail.Error,
|
||||
ProofType: authZkProof.ProofDetail.Type,
|
||||
TaskType: authZkProof.ProofDetail.Type,
|
||||
Signature: authZkProof.Signature,
|
||||
Proof: string(proofJSON),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user