Skip to content

Commit

Permalink
refactor(API): refactor SubmitProof (scroll-tech#318)
Browse files Browse the repository at this point in the history
Co-authored-by: colin <[email protected]>
Co-authored-by: Lawliet-Chan <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>
Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>
Co-authored-by: Haichen Shen <[email protected]>
  • Loading branch information
7 people authored May 16, 2023
1 parent 046463e commit a70c317
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ pipeline {
slackSend(message: "${JOB_BASE_NAME} ${GIT_COMMIT} #${BUILD_NUMBER} deploy ${currentBuild.result}")
}
}
}
}
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 = "v3.0.17"
var tag = "v3.0.18"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
12 changes: 6 additions & 6 deletions coordinator/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
type RollerAPI interface {
RequestToken(authMsg *message.AuthMsg) (string, error)
Register(ctx context.Context, authMsg *message.AuthMsg) (*rpc.Subscription, error)
SubmitProof(proof *message.ProofMsg) (bool, error)
SubmitProof(proof *message.ProofMsg) error
}

// RequestToken generates and sends back register token for roller
Expand Down Expand Up @@ -102,28 +102,28 @@ func (m *Manager) Register(ctx context.Context, authMsg *message.AuthMsg) (*rpc.
}

// SubmitProof roller pull proof
func (m *Manager) SubmitProof(proof *message.ProofMsg) (bool, error) {
func (m *Manager) SubmitProof(proof *message.ProofMsg) error {
// Verify the signature
if ok, err := proof.Verify(); !ok {
if err != nil {
log.Error("failed to verify proof message", "error", err)
}
return false, errors.New("auth signature verify fail")
return errors.New("auth signature verify fail")
}

pubkey, _ := proof.PublicKey()
// Only allow registered pub-key.
if !m.existTaskIDForRoller(pubkey, proof.ID) {
return false, fmt.Errorf("the roller or session id doesn't exist, pubkey: %s, ID: %s", pubkey, proof.ID)
return fmt.Errorf("the roller or session id doesn't exist, pubkey: %s, ID: %s", pubkey, proof.ID)
}

m.updateMetricRollerProofsLastFinishedTimestampGauge(pubkey)

err := m.handleZkProof(pubkey, proof.ProofDetail)
if err != nil {
return false, err
return err
}
defer m.freeTaskIDForRoller(pubkey, proof.ID)

return true, nil
return nil
}
12 changes: 4 additions & 8 deletions coordinator/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ func TestManager_SubmitProof(t *testing.T) {
return false, errors.New("proof verify error")
})
defer patchGuard.Reset()
isSuccess, err := rollerManager.SubmitProof(proof)
assert.False(t, isSuccess)
err := rollerManager.SubmitProof(proof)
assert.Error(t, err)
})

Expand All @@ -176,8 +175,7 @@ func TestManager_SubmitProof(t *testing.T) {
patchGuard.ApplyMethodFunc(pm, "Verify", func() (bool, error) {
return true, nil
})
isSuccess, err := rollerManager.SubmitProof(proof)
assert.False(t, isSuccess)
err := rollerManager.SubmitProof(proof)
assert.Error(t, err)
})

Expand All @@ -197,9 +195,8 @@ func TestManager_SubmitProof(t *testing.T) {
return errors.New("handle zk proof error")
})

isSuccess, err := rollerManager.SubmitProof(proof)
err := rollerManager.SubmitProof(proof)
assert.Error(t, err)
assert.False(t, isSuccess)
})

convey.Convey("SubmitProof success", t, func() {
Expand All @@ -218,8 +215,7 @@ func TestManager_SubmitProof(t *testing.T) {
return nil
})

isSuccess, err := rollerManager.SubmitProof(proof)
err := rollerManager.SubmitProof(proof)
assert.NoError(t, err)
assert.True(t, isSuccess)
})
}
5 changes: 2 additions & 3 deletions coordinator/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (c *Client) RegisterAndSubscribe(ctx context.Context, taskCh chan *message.
}

// SubmitProof get proof from roller.
func (c *Client) SubmitProof(ctx context.Context, proof *message.ProofMsg) (bool, error) {
var ok bool
return ok, c.client.CallContext(ctx, &ok, "roller_submitProof", proof)
func (c *Client) SubmitProof(ctx context.Context, proof *message.ProofMsg) error {
return c.client.CallContext(ctx, nil, "roller_submitProof", proof)
}
4 changes: 1 addition & 3 deletions coordinator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,7 @@ func (r *mockRoller) loop(t *testing.T, client *client2.Client, proofTime time.D
proof.ProofDetail.Proof.Proof = []byte(verifier.InvalidTestProof)
}
assert.NoError(t, proof.Sign(r.privKey))
ok, err := client.SubmitProof(context.Background(), proof)
assert.NoError(t, err)
assert.Equal(t, true, ok)
assert.NoError(t, client.SubmitProof(context.Background(), proof))
case <-stopCh:
return
}
Expand Down
6 changes: 1 addition & 5 deletions roller/roller.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ func (r *Roller) signAndSubmitProof(msg *message.ProofDetail) {
for atomic.LoadInt64(&r.isDisconnected) == 1 {
time.Sleep(retryWait)
}
ok, serr := r.client.SubmitProof(context.Background(), authZkProof)
if !ok {
log.Error("submit proof to coordinator failed", "task ID", msg.ID)
return
}
serr := r.client.SubmitProof(context.Background(), authZkProof)
if serr == nil {
return
}
Expand Down

0 comments on commit a70c317

Please sign in to comment.