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

feat(coordinator): add prover rest api #716

Merged
merged 75 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1e16bc2
feat: add restful api for prover
georgehao Aug 1, 2023
cf6c6a5
feat: fix some bug
georgehao Aug 1, 2023
bf98a67
feat: scroll fmt
georgehao Aug 1, 2023
888c162
feat: fix coordinator unit test
georgehao Aug 2, 2023
4f37293
fix: fix conflict
georgehao Aug 2, 2023
26b2bfd
feat: remove unused code
georgehao Aug 2, 2023
adac0c3
feat: scrollfmt
georgehao Aug 2, 2023
298bf0a
feat: format BatchTaskDetail
georgehao Aug 2, 2023
64f3f34
feat: format chunk task detail
georgehao Aug 2, 2023
6be9c45
feat: fix check failure
georgehao Aug 2, 2023
dc57ace
feat: fmt
georgehao Aug 2, 2023
1173a1d
feat: add random
georgehao Aug 3, 2023
8adee22
feat: fix unit test
georgehao Aug 3, 2023
57f3482
feat: scrollfmlt
georgehao Aug 3, 2023
5f5cec1
feat: change api
georgehao Aug 3, 2023
e17830b
feat: update
georgehao Aug 3, 2023
823eff7
feat: resolve conflict
georgehao Aug 3, 2023
3b642ed
feat: update
georgehao Aug 3, 2023
e383729
feat: add check height
georgehao Aug 3, 2023
afb7392
feat: change random to challenge
georgehao Aug 3, 2023
06c49f5
feat: fix conflict
georgehao Aug 3, 2023
ffd2cbd
Merge branch 'pull-model-prover-client' of github.com:scroll-tech/scr…
georgehao Aug 3, 2023
a69ec80
feat: update
georgehao Aug 3, 2023
5bd2f1f
feat: fix message_test
georgehao Aug 3, 2023
0f186e0
feat: update
georgehao Aug 3, 2023
b3864c8
feat: recover coodinator dsn
georgehao Aug 3, 2023
2c47eaf
feat: ignore G404
georgehao Aug 3, 2023
dbe459e
feat: fix unused code
georgehao Aug 3, 2023
fad9c5d
feat: fix api test failure
georgehao Aug 3, 2023
7e22053
feat: fix api test failure
georgehao Aug 3, 2023
1c0880d
feat: fix conflict
georgehao Aug 3, 2023
71d8e08
feat: recover rand
georgehao Aug 3, 2023
2ae13ec
change ws port to http port in integration-test
colinlyguo Aug 3, 2023
77b762e
feat: clear time duration unit
georgehao Aug 3, 2023
d05b0df
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 3, 2023
ed46ee1
fix login
colinlyguo Aug 3, 2023
0c4809f
trigger ci
colinlyguo Aug 3, 2023
437047a
add get empty prover task check
colinlyguo Aug 3, 2023
f74bdaf
feat: fix coordinator api test
georgehao Aug 4, 2023
ea84a0a
feat: fix concurrence get task
georgehao Aug 4, 2023
114157b
feat: fix conflict
georgehao Aug 4, 2023
eecc770
feat: update
georgehao Aug 4, 2023
1d2d6c8
feat: fix jwt token don't have the keyword
georgehao Aug 4, 2023
cadb7bb
feat: fix prover error check
georgehao Aug 4, 2023
7609c2c
fix login
colinlyguo Aug 4, 2023
c8874a1
feat: add graceful to gin server
georgehao Aug 4, 2023
27339bf
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 4, 2023
cc94652
Merge branch 'develop' of github.com:scroll-tech/scroll into feat/res…
georgehao Aug 4, 2023
4e537e3
feat: fix conflict
georgehao Aug 4, 2023
54f5f7c
feat: update
georgehao Aug 4, 2023
7658128
feat: address comments
georgehao Aug 4, 2023
096abf6
feat: recover coordinator config.json
georgehao Aug 4, 2023
aec761a
Merge branch 'pull-model-prover-client' of github.com:scroll-tech/scr…
georgehao Aug 4, 2023
cc8aa69
feat: rename prover task controller to get task controller
georgehao Aug 4, 2023
7d56822
add chunk prover and batch prover login tests and submit empty task t…
colinlyguo Aug 4, 2023
e0ed73d
feat: recover coordinator server response struct tag
georgehao Aug 4, 2023
acc38a1
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 4, 2023
602895d
feat: remove prover_height required tag
georgehao Aug 4, 2023
371d25d
feat: recover prover height valiate
georgehao Aug 4, 2023
9fb8c7c
omit to prove task of the genesis block
colinlyguo Aug 4, 2023
b500b88
feat: recover CollectionTimeSec 1 min to 60s
georgehao Aug 4, 2023
c5a05ed
Merge branch 'develop' of github.com:scroll-tech/scroll into feat/res…
georgehao Aug 4, 2023
63da9f2
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 4, 2023
620c194
Merge branch 'pull-model-prover-client' of github.com:scroll-tech/scr…
georgehao Aug 4, 2023
96cdaf1
feat: change coordinator config name
georgehao Aug 4, 2023
a2b2696
feat: get_task rename ProofData to TaskData
georgehao Aug 4, 2023
48c9b14
feat: rename collect to assign
georgehao Aug 4, 2023
71b1159
feat: change route health_check to healthz
georgehao Aug 4, 2023
9cb23bb
adding TestCoordinatorProverInteractionWithData sketch
colinlyguo Aug 4, 2023
61da31b
feat: fix chunk check prover height
georgehao Aug 4, 2023
18f4729
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 4, 2023
02480c2
small tweaks
colinlyguo Aug 4, 2023
898c4b1
feat: update
georgehao Aug 4, 2023
3dd6472
Merge branch 'feat/restful-api-for-prover1' of github.com:scroll-tech…
georgehao Aug 4, 2023
644299c
debugging temp commit
colinlyguo Aug 4, 2023
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
2 changes: 1 addition & 1 deletion common/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *Cmd) Write(data []byte) (int, error) {
out := string(data)
if verbose || c.openLog {
fmt.Printf("%s:\n\t%v", c.name, out)
} else if strings.Contains(out, "error") || strings.Contains(out, "warning") {
} else if strings.Contains(strings.ToLower(out), "error") || strings.Contains(strings.ToLower(out), "warning") {
fmt.Printf("%s:\n\t%v", c.name, out)
}
go c.checkFuncs.IterCb(func(_ string, value interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion common/types/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type AuthMsg struct {

// Identity contains all the fields to be signed by the prover.
type Identity struct {
// Prover name
// ProverName the prover name
ProverName string `json:"prover_name"`
// Challenge unique challenge generated by manager
Challenge string `json:"challenge"`
Expand Down
14 changes: 6 additions & 8 deletions common/types/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func TestAuthMessageSignAndVerify(t *testing.T) {

authMsg := &AuthMsg{
Identity: &Identity{
Name: "testName",
Version: "testVersion",
Token: "testToken",
Challenge: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTEwMzgxNzUsIm9yaWdfaWF0IjoxNjkxMDM0NTc1fQ.HybBMsEJFhyZqtIa2iVcHUP7CEFttf708jmTMAImAWA",
ProverName: "test",
},
}
assert.NoError(t, authMsg.SignWithKey(privkey))
Expand Down Expand Up @@ -46,15 +45,14 @@ func TestGenerateToken(t *testing.T) {

func TestIdentityHash(t *testing.T) {
identity := &Identity{
Name: "testName",
ProverType: ProofTypeChunk,
Version: "testVersion",
Token: "testToken",
Challenge: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTEwMzM0MTksIm9yaWdfaWF0IjoxNjkxMDI5ODE5fQ.EhkLZsj__rNPVC3ZDYBtvdh0nB8mmM_Hl82hObaIWOs",
ProverName: "test",
}

hash, err := identity.Hash()
assert.NoError(t, err)

expectedHash := "c0411a19531fb8c6133b2bae91f361c14e65f2d318aef72b83519e6061cad001"
expectedHash := "7373bb57ab7c01307d86fec55e088e00c526d82d9d1303fa4a189ff6ea95fbe2"
assert.Equal(t, expectedHash, hex.EncodeToString(hash))
}

Expand Down
51 changes: 0 additions & 51 deletions coordinator/client/client.go

This file was deleted.

57 changes: 29 additions & 28 deletions coordinator/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package app

import (
"context"
"errors"
"fmt"
"net/http"
"os"
"os/signal"
"time"

// enable the pprof
_ "net/http/pprof"

"github.com/gin-gonic/gin"
"github.com/scroll-tech/go-ethereum/log"
"github.com/urfave/cli/v2"

Expand All @@ -20,7 +24,7 @@ import (
"scroll-tech/coordinator/internal/config"
"scroll-tech/coordinator/internal/controller/api"
"scroll-tech/coordinator/internal/controller/cron"
"scroll-tech/coordinator/internal/logic/provermanager"
"scroll-tech/coordinator/internal/route"
)

var app *cli.App
Expand Down Expand Up @@ -55,9 +59,6 @@ func action(ctx *cli.Context) error {
}

proofCollector := cron.NewCollector(subCtx, db, cfg)

provermanager.InitProverManager(db)

defer func() {
proofCollector.Stop()
cancel()
Expand All @@ -66,42 +67,42 @@ func action(ctx *cli.Context) error {
}
}()

router := gin.Default()
api.InitController(cfg, db)
route.Route(router, cfg)
port := ctx.String(httpPortFlag.Name)
srv := &http.Server{
Addr: fmt.Sprintf(":%s", port),
Handler: router,
ReadHeaderTimeout: time.Minute,
}

// Start metrics server.
metrics.Serve(subCtx, ctx)

apis := api.RegisterAPIs(cfg, db)
// Register api and start rpc service.
if ctx.Bool(httpEnabledFlag.Name) {
handler, addr, err := utils.StartHTTPEndpoint(fmt.Sprintf("%s:%d", ctx.String(httpListenAddrFlag.Name), ctx.Int(httpPortFlag.Name)), apis)
if err != nil {
log.Crit("Could not start RPC api", "error", err)
}
defer func() {
_ = handler.Shutdown(ctx.Context)
log.Info("HTTP endpoint closed", "url", fmt.Sprintf("http://%v/", addr))
}()
log.Info("HTTP endpoint opened", "url", fmt.Sprintf("http://%v/", addr))
}
// Register api and start ws service.
if ctx.Bool(wsEnabledFlag.Name) {
handler, addr, err := utils.StartWSEndpoint(fmt.Sprintf("%s:%d", ctx.String(wsListenAddrFlag.Name), ctx.Int(wsPortFlag.Name)), apis, cfg.ProverManagerConfig.CompressionLevel)
if err != nil {
log.Crit("Could not start WS api", "error", err)
go func() {
if runServerErr := srv.ListenAndServe(); err != nil && !errors.Is(runServerErr, http.ErrServerClosed) {
log.Crit("run coordinator http server failure", "error", runServerErr)
}
defer func() {
_ = handler.Shutdown(ctx.Context)
log.Info("WS endpoint closed", "url", fmt.Sprintf("ws://%v/", addr))
}()
log.Info("WS endpoint opened", "url", fmt.Sprintf("ws://%v/", addr))
}
}()

// Catch CTRL-C to ensure a graceful shutdown.
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

// Wait until the interrupt signal is received from an OS signal.
<-interrupt
log.Info("start shutdown coordinator server ...")

closeCtx, cancelExit := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelExit()
if err = srv.Shutdown(closeCtx); err != nil {
log.Warn("shutdown coordinator server failure", "error", err)
return nil
}

<-closeCtx.Done()
log.Info("coordinator server exiting success")
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions coordinator/cmd/app/mock_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

var (
wsStartPort int64 = 40000
httpStartPort int64 = 40000
)

// CoordinatorApp coordinator-test client manager.
Expand All @@ -29,7 +29,7 @@ type CoordinatorApp struct {

originFile string
coordinatorFile string
WSPort int64
HTTPPort int64

args []string
docker.AppAPI
Expand All @@ -39,13 +39,13 @@ type CoordinatorApp struct {
func NewCoordinatorApp(base *docker.App, file string) *CoordinatorApp {
coordinatorFile := fmt.Sprintf("/tmp/%d_coordinator-config.json", base.Timestamp)
port, _ := rand.Int(rand.Reader, big.NewInt(2000))
wsPort := port.Int64() + wsStartPort
httpPort := port.Int64() + httpStartPort
coordinatorApp := &CoordinatorApp{
base: base,
originFile: file,
coordinatorFile: coordinatorFile,
WSPort: wsPort,
args: []string{"--log.debug", "--config", coordinatorFile, "--ws", "--ws.port", strconv.Itoa(int(wsPort))},
HTTPPort: httpPort,
args: []string{"--log.debug", "--config", coordinatorFile, "--http", "--http.port", strconv.Itoa(int(httpPort))},
}
if err := coordinatorApp.MockConfig(true); err != nil {
panic(err)
Expand All @@ -67,9 +67,9 @@ func (c *CoordinatorApp) Free() {
_ = os.Remove(c.coordinatorFile)
}

// WSEndpoint returns ws endpoint.
func (c *CoordinatorApp) WSEndpoint() string {
return fmt.Sprintf("ws://localhost:%d", c.WSPort)
// HTTPEndpoint returns ws endpoint.
func (c *CoordinatorApp) HTTPEndpoint() string {
return fmt.Sprintf("http://localhost:%d", c.HTTPPort)
}

// MockConfig creates a new coordinator config.
Expand All @@ -83,7 +83,7 @@ func (c *CoordinatorApp) MockConfig(store bool) error {
cfg.ProverManagerConfig = &coordinatorConfig.ProverManagerConfig{
ProversPerSession: 1,
Verifier: &coordinatorConfig.VerifierConfig{MockMode: true},
CollectionTime: 1,
CollectionTimeSec: 1,
0xmountaintop marked this conversation as resolved.
Show resolved Hide resolved
TokenTimeToLive: 1,
}
cfg.DBConfig.DSN = base.DBImg.Endpoint()
Expand Down
7 changes: 6 additions & 1 deletion coordinator/conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compression_level": 9,
"provers_per_session": 1,
"session_attempts": 2,
"collection_time": 180,
"collection_time_sec": 180,
"token_time_to_live": 60,
"verifier": {
"mock_mode": true,
Expand All @@ -21,5 +21,10 @@
},
"l2_config": {
"chain_id": 111
},
"auth": {
"secret": "prover secret key",
"challenge_expire_duration_sec": 3600,
"login_expire_duration_sec": 3600
}
}
39 changes: 27 additions & 12 deletions coordinator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,67 @@ module scroll-tech/coordinator
go 1.19

require (
github.com/agiledragon/gomonkey/v2 v2.9.0
github.com/orcaman/concurrent-map v1.0.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/appleboy/gin-jwt/v2 v2.9.1
github.com/gin-gonic/gin v1.9.1
github.com/go-resty/resty/v2 v2.7.0
github.com/mitchellh/mapstructure v1.5.0
github.com/scroll-tech/go-ethereum v1.10.14-0.20230804022247-26eeb40ea3ca
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.3
github.com/urfave/cli/v2 v2.25.7
golang.org/x/sync v0.3.0
gorm.io/gorm v1.25.2
)

require (
github.com/bytedance/sonic v1.9.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

require (
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/iden3/go-iden3-crypto v0.0.15 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/scroll-tech/zktrie v0.6.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/smartystreets/assertions v1.13.1 // indirect
github.com/smartystreets/goconvey v1.8.0
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading