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(prover-stats-api): add prover stats API #635

Merged
merged 77 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
a596511
add miner api
Jul 11, 2023
7e780ec
add ci
Jul 11, 2023
38f32b2
add service
Jul 11, 2023
4898884
add makefile
Jul 11, 2023
2cc77ad
swag doc
Jul 11, 2023
aa4df0e
import swag
Jul 11, 2023
4df562b
add test and config
Jul 11, 2023
598ccc3
make test
Jul 11, 2023
f6f3d0b
Merge branch 'develop' into miners
Lawliet-Chan Jul 11, 2023
e2fe308
gitignore
Jul 11, 2023
5eddde0
fix
Jul 11, 2023
c04883e
fix
Jul 11, 2023
a2dfc39
fix makefile
Jul 11, 2023
fcaa1ea
fix
Jul 11, 2023
dc22675
fix
Jul 11, 2023
18b332a
add orm test
Jul 11, 2023
b443aa9
fix
Jul 11, 2023
f294cdc
some modify
Jul 11, 2023
a8b31bb
try fix
Jul 11, 2023
2ef214c
try fix
Jul 11, 2023
a3daec8
Merge branch 'develop' into miners
Lawliet-Chan Jul 11, 2023
23db3bf
port
Jul 11, 2023
cd807da
service tests
Jul 12, 2023
2c8f4f3
.taskID
Jul 12, 2023
97d6c27
desc
Jul 12, 2023
4c86e2f
try fix
Jul 12, 2023
9e8215c
Merge branch 'develop' into miners
Lawliet-Chan Jul 12, 2023
78ee952
big.Int
Jul 12, 2023
e0679b2
ignore go mod tidy
Jul 12, 2023
b472f30
change port
Jul 12, 2023
6d3e15c
fix ci
Jul 12, 2023
9d22a49
Revert "fix ci"
Jul 12, 2023
e642c91
trigger ci
Jul 12, 2023
ed75791
Merge branch 'develop' into miners
Lawliet-Chan Jul 13, 2023
8588d4d
rename to prover_stats_api
Jul 13, 2023
9bbf0f6
modify ci
Jul 13, 2023
e47e020
tidy layout
Jul 13, 2023
08d4ee2
fix test path
Jul 13, 2023
cbe66b8
rename to logic
Jul 13, 2023
e67448c
fix ci name
Jul 13, 2023
a5c50ad
add jwt
Jul 13, 2023
c1bf3c1
fix skip paths
Jul 13, 2023
30171c2
debug
Jul 13, 2023
10ab92a
trigger ci
Jul 13, 2023
60f0ed9
fix tests
Jul 13, 2023
4f5c968
Merge branch 'develop' into miners
Lawliet-Chan Jul 13, 2023
c8ef6a1
add metrics
Jul 13, 2023
28d61aa
fix go mod tidy
Jul 14, 2023
1f7b698
fix
Jul 14, 2023
b5195b7
fix
Jul 14, 2023
c850e77
fix test
Jul 14, 2023
3332ef3
fix lint
Jul 14, 2023
c4abe27
Merge branch 'develop' into miners
Lawliet-Chan Jul 14, 2023
a7b3c07
wrap resp
Jul 17, 2023
21f924e
Merge branch 'develop' into miners
Lawliet-Chan Jul 17, 2023
7d2d922
fix test
Jul 17, 2023
d3af1cd
statusOK
Jul 17, 2023
56399ad
feat: update prover stats api some files
georgehao Jul 18, 2023
274d5fa
feat: update readme
georgehao Jul 18, 2023
27d6098
fix lint
Jul 18, 2023
35ffa73
fix test
Jul 18, 2023
5d40552
some fix
Jul 18, 2023
f33b4b0
some fix
Jul 18, 2023
2c3cce3
change field
Jul 19, 2023
bf0f52d
Merge branch 'develop' into miners
Lawliet-Chan Jul 19, 2023
502a8a7
feat: add empty line
georgehao Jul 19, 2023
32ef144
feat: add empty line
georgehao Jul 19, 2023
821fac8
feat: rename variable name
georgehao Jul 19, 2023
c6e2b7e
feat: comment tidy
georgehao Jul 19, 2023
256e126
feat: format import
georgehao Jul 19, 2023
94ac36e
fix test and lint
Jul 19, 2023
11f167b
fix ci
Jul 19, 2023
a8f6d83
fix lint
Jul 19, 2023
383d067
check pubkey exists
Jul 19, 2023
f85e39a
fix
Jul 19, 2023
8ca10f6
Update version.go
HAOYUatHZ Jul 20, 2023
fc2ec7f
Merge branch 'develop' into miners
HAOYUatHZ Jul 20, 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
80 changes: 80 additions & 0 deletions .github/workflows/prover_stats_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: ProverStatsAPI

on:
push:
branches:
- main
- staging
- develop
- alpha
paths:
- 'prover-stats-api/**'
- '.github/workflows/prover_stats_api.yml'
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
paths:
- 'prover-stats-api/**'
- '.github/workflows/prover_stats_api.yml'

defaults:
run:
working-directory: 'prover-stats-api'

jobs:
# check:
# if: github.event.pull_request.draft == false
# runs-on: ubuntu-latest
# steps:
# - name: Install Go
# uses: actions/setup-go@v2
# with:
# go-version: 1.19.x
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Lint
Lawliet-Chan marked this conversation as resolved.
Show resolved Hide resolved
# run: |
# rm -rf $HOME/.cache/golangci-lint
# make lint
test:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: |
make test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: prover-stats-api
goimports-lint:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.19.x
- name: Checkout code
uses: actions/checkout@v2
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports
- run: goimports -local scroll-tech/prover-stats-api/ -w .
- run: go mod tidy
# If there are any diffs from goimports or go mod tidy, fail.
- name: Verify no changes from goimports and go mod tidy
run: |
if [ -n "$(git status --porcelain)" ]; then
exit 1
fi
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ use (
./database
./roller
./tests/integration-test
./prover-stats-api
)
87 changes: 46 additions & 41 deletions go.work.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions prover-stats-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/bin
13 changes: 13 additions & 0 deletions prover-stats-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: clean build test

build:
GOBIN=$(PWD)/build/bin go build -o $(PWD)/build/bin/prover-stats-api ./cmd

clean: ## Empty out the bin folder
@rm -rf build/bin

swag:
swag init -g ./cmd/main.go

test:
go test -v $(PWD)/...
30 changes: 30 additions & 0 deletions prover-stats-api/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# prover-stats-api

## how to get the prover-stats-api docs

### 1. start the prover-stats-api server

```
cd ./prover-stats-api
go build -o prover-stats ./cmd/
./prover-stats --config=./conf/config.json
```

you will get server run log
```
Listening and serving HTTP on :8990
```

### 2. browse the documents

open this documents in your browser
```
http://localhost:8990/swagger/index.html
```

## how to update the prover-stats-api docs

```
cd ./prover-stats-api
make swag
```
96 changes: 96 additions & 0 deletions prover-stats-api/cmd/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package app

import (
"context"
"fmt"
"os"
"os/signal"

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

"scroll-tech/common/database"
"scroll-tech/common/metrics"
"scroll-tech/common/utils"
"scroll-tech/common/version"

"scroll-tech/prover-stats-api/internal/config"
"scroll-tech/prover-stats-api/internal/controller"
"scroll-tech/prover-stats-api/internal/route"
)

var app *cli.App

func init() {
// Set up prover-stats-api info.
app = cli.NewApp()
app.Action = action
app.Name = "Prover Stats API"
app.Usage = "The Scroll L2 ZK Prover Stats API"
app.Version = version.Version
app.Flags = append(app.Flags, utils.CommonFlags...)
app.Flags = append(app.Flags, apiFlags...)
app.Before = func(ctx *cli.Context) error {
return utils.LogSetup(ctx)
}
}

func action(ctx *cli.Context) error {
// Load config file.
cfgFile := ctx.String(utils.ConfigFileFlag.Name)
cfg, err := config.NewConfig(cfgFile)
if err != nil {
log.Crit("failed to load config file", "config file", cfgFile, "error", err)
}

// init db handler
db, err := database.InitDB(cfg.DBConfig)
if err != nil {
log.Crit("failed to init db connection", "err", err)
}
defer func() {
if err = database.CloseDB(db); err != nil {
log.Error("can not close ormFactory", "error", err)
}
}()

subCtx, cancel := context.WithCancel(ctx.Context)
defer func() {
cancel()
}()

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

// init Prover Stats API
port := ctx.String(httpPortFlag.Name)

router := gin.Default()
controller.InitController(db)
route.Route(router, cfg)

go func() {
if runServerErr := router.Run(fmt.Sprintf(":%s", port)); runServerErr != nil {
log.Crit("run http server failure", "error", runServerErr)
}
}()

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

return nil
}

// Run run prover-stats-api.
func Run() {
// RunApp the prover-stats-api.
if err := app.Run(os.Args); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
15 changes: 15 additions & 0 deletions prover-stats-api/cmd/app/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import "github.com/urfave/cli/v2"

var (
apiFlags = []cli.Flag{
&httpPortFlag,
}
// httpPortFlag set http.port.
httpPortFlag = cli.IntFlag{
Name: "http.port",
Usage: "HTTP server listening port",
Value: 8990,
}
)
24 changes: 24 additions & 0 deletions prover-stats-api/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"scroll-tech/prover-stats-api/cmd/app"
_ "scroll-tech/prover-stats-api/docs"
)

// @title Scroll Prover Stats API
// @version 1.0
// @description This is an API server for Provers.

// @contact.name Prover Stats API Support
// @contact.email Be Pending

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host localhost:8990
// @BasePath /api/v1

// @securityDefinitions.basic BasicAuth
func main() {
app.Run()
}
12 changes: 12 additions & 0 deletions prover-stats-api/conf/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"db_config": {
"driver_name": "postgres",
"dsn": "postgres://localhost/scroll?sslmode=disable",
"maxOpenNum": 200,
"maxIdleNum": 20
},
"auth": {
"secret": "prover secret key",
"token_expire_duration": 3600
}
}
Loading
Loading