-
Notifications
You must be signed in to change notification settings - Fork 632
[Feat] Support "proxy" arch between coordinator and prover #1701
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
Open
noel2004
wants to merge
67
commits into
develop
Choose a base branch
from
coordinator_proxy
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,703
−108
Open
Changes from 52 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
5dbb5c5
extend api for proxy
noel2004 1f2b857
add proxy_login route
noel2004 9796d16
WIP: update login logic and coordinator client
noel2004 412ad56
extend loginlogic
noel2004 3adb2e0
WIP: controller
noel2004 5c6c225
WIP: config and client controller
noel2004 76ecdf0
add proxy config sample
noel2004 0d238d7
WIP: the structure of client manager
noel2004 7b3a65b
framework for auto login
noel2004 4f878d9
AI step
noel2004 624a7a2
WIP: AI step
noel2004 321dd43
unit test for client
noel2004 64ef0f4
WIP
noel2004 5a07a16
WIP
noel2004 5614ec3
WIP
noel2004 322766f
WIP
noel2004 4725d8a
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 c72ee5d
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 e6be62f
WIP
noel2004 9df6429
wip
noel2004 78dbe6c
controller WIP
noel2004 a04b64d
routes
noel2004 2721503
refining
noel2004 50f3e1a
fix issues from test
noel2004 256c90a
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 92ca7a6
improve get_task proxy
noel2004 c7b83a0
fix issue in test
noel2004 057e220
fix issues
noel2004 b7f23c6
basic tests
noel2004 1d9fa41
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 884b050
Merge branch 'develop' into coordinator_proxy
lispc fa5b113
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 c79ad57
finish binary
noel2004 6ee026f
depress link for libzkp
noel2004 4365aaf
refactor libzkp to be completely mocked out
noel2004 8a15836
add compatibile mode and more logs
noel2004 404c664
fix unittest
noel2004 c992157
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 d9a29cd
fix config issue
noel2004 b1c3a4e
more log for init
noel2004 8f8a537
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 5d41788
+ fix get task behavior
noel2004 7572bf8
fix
noel2004 b6e3345
fix issue
noel2004 17e6c5b
robust prover manager
noel2004 ac0396d
add persistent for running status
noel2004 4b79e63
WIP: some refactors
noel2004 6696aac
WIP
noel2004 4df1dd8
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 20fde41
complete persistent layer and unit test
noel2004 e755165
fix concurrent issue
noel2004 c22d9ec
fix goimport issue
noel2004 51b1e79
add docker action
noel2004 e9470ff
update config template
noel2004 cf9e368
Fix login version issue
noel2004 c938d6c
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 d66d705
fix after merging
noel2004 1944798
fix issues
noel2004 ac4a720
refactoring client
noel2004 9e5579c
cover client reset in test
noel2004 9c2bc02
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 21326c2
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 14e2633
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 2c14342
Merge remote-tracking branch 'origin/develop' into coordinator_proxy
noel2004 3a87171
fix issue
noel2004 b109407
continue fixing
noel2004 feeac8f
fix for edge cases
noel2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "time" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/scroll-tech/go-ethereum/log" | ||
| "github.com/urfave/cli/v2" | ||
| "gorm.io/gorm" | ||
|
|
||
| "scroll-tech/common/database" | ||
| "scroll-tech/common/observability" | ||
| "scroll-tech/common/utils" | ||
| "scroll-tech/common/version" | ||
|
|
||
| "scroll-tech/coordinator/internal/config" | ||
| "scroll-tech/coordinator/internal/controller/proxy" | ||
| "scroll-tech/coordinator/internal/route" | ||
| ) | ||
|
|
||
| var app *cli.App | ||
|
|
||
| func init() { | ||
| // Set up coordinator app info. | ||
| app = cli.NewApp() | ||
| app.Action = action | ||
| app.Name = "coordinator proxy" | ||
| app.Usage = "Proxy for multiple Scroll L2 Coordinators" | ||
| 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) | ||
| } | ||
| // Register `coordinator-test` app for integration-test. | ||
| utils.RegisterSimulation(app, utils.CoordinatorAPIApp) | ||
| } | ||
|
|
||
| func action(ctx *cli.Context) error { | ||
| cfgFile := ctx.String(utils.ConfigFileFlag.Name) | ||
| cfg, err := config.NewProxyConfig(cfgFile) | ||
| if err != nil { | ||
| log.Crit("failed to load config file", "config file", cfgFile, "error", err) | ||
| } | ||
|
|
||
| var db *gorm.DB | ||
| if dbCfg := cfg.ProxyManager.DB; dbCfg != nil { | ||
| db, err = database.InitDB(cfg.ProxyManager.DB) | ||
| 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 db connection", "error", err) | ||
| } | ||
| }() | ||
| observability.Server(ctx, db) | ||
| } | ||
| registry := prometheus.DefaultRegisterer | ||
|
|
||
| apiSrv := server(ctx, cfg, db, registry) | ||
|
|
||
| log.Info( | ||
| "Start coordinator api successfully.", | ||
| "version", version.Version, | ||
| ) | ||
|
|
||
| // 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 proxy server ...") | ||
|
|
||
| closeCtx, cancelExit := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancelExit() | ||
| if err = apiSrv.Shutdown(closeCtx); err != nil { | ||
| log.Warn("shutdown coordinator proxy server failure", "error", err) | ||
| return nil | ||
| } | ||
|
|
||
| <-closeCtx.Done() | ||
| log.Info("coordinator proxy server exiting success") | ||
| return nil | ||
| } | ||
|
|
||
| func server(ctx *cli.Context, cfg *config.ProxyConfig, db *gorm.DB, reg prometheus.Registerer) *http.Server { | ||
| router := gin.New() | ||
| proxy.InitController(cfg, db, reg) | ||
| route.ProxyRoute(router, cfg, reg) | ||
| port := ctx.String(httpPortFlag.Name) | ||
| srv := &http.Server{ | ||
| Addr: fmt.Sprintf(":%s", port), | ||
| Handler: router, | ||
| ReadHeaderTimeout: time.Minute, | ||
| } | ||
|
|
||
| go func() { | ||
| if runServerErr := srv.ListenAndServe(); runServerErr != nil && !errors.Is(runServerErr, http.ErrServerClosed) { | ||
| log.Crit("run coordinator proxy http server failure", "error", runServerErr) | ||
noel2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }() | ||
| return srv | ||
| } | ||
|
|
||
| // Run coordinator. | ||
| func Run() { | ||
| // RunApp the coordinator. | ||
| if err := app.Run(os.Args); err != nil { | ||
| _, _ = fmt.Fprintln(os.Stderr, err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package app | ||
|
|
||
| import "github.com/urfave/cli/v2" | ||
|
|
||
| var ( | ||
| apiFlags = []cli.Flag{ | ||
| // http flags | ||
| &httpEnabledFlag, | ||
| &httpListenAddrFlag, | ||
| &httpPortFlag, | ||
| } | ||
| // httpEnabledFlag enable rpc server. | ||
| httpEnabledFlag = cli.BoolFlag{ | ||
| Name: "http", | ||
| Usage: "Enable the HTTP-RPC server", | ||
| Value: false, | ||
| } | ||
| // httpListenAddrFlag set the http address. | ||
| httpListenAddrFlag = cli.StringFlag{ | ||
| Name: "http.addr", | ||
| Usage: "HTTP-RPC server listening interface", | ||
| Value: "localhost", | ||
| } | ||
| // httpPortFlag set http.port. | ||
| httpPortFlag = cli.IntFlag{ | ||
| Name: "http.port", | ||
| Usage: "HTTP-RPC server listening port", | ||
| Value: 8590, | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package main | ||
|
|
||
| import "scroll-tech/coordinator/cmd/proxy/app" | ||
|
|
||
| func main() { | ||
| app.Run() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "proxy_manager": { | ||
| "proxy_cli": { | ||
| "proxy_name": "proxy_name", | ||
| "secret": "client private key" | ||
| }, | ||
| "auth": { | ||
| "secret": "proxy secret key", | ||
| "challenge_expire_duration_sec": 3600, | ||
| "login_expire_duration_sec": 3600 | ||
| }, | ||
| "verifier": { | ||
| "min_prover_version": "v4.4.45", | ||
| "verifiers": [] | ||
| } | ||
| }, | ||
| "coordinators": { | ||
| "sepolia": { | ||
| "base_url": "http://localhost:8555", | ||
| "retry_count": 10, | ||
| "retry_wait_time_sec": 10, | ||
| "connection_timeout_sec": 30 | ||
| } | ||
| }, | ||
| "db": { | ||
| "driver_name": "postgres", | ||
| "dsn": "postgres://localhost/scroll?sslmode=disable", | ||
| "maxOpenNum": 200, | ||
| "maxIdleNum": 20 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "scroll-tech/common/database" | ||
| "scroll-tech/common/utils" | ||
| ) | ||
|
|
||
| // Proxy loads proxy configuration items. | ||
| type ProxyManager struct { | ||
| // Zk verifier config help to confine the connected prover. | ||
| Verifier *VerifierConfig `json:"verifier"` | ||
| Client *ProxyClient `json:"proxy_cli"` | ||
| Auth *Auth `json:"auth"` | ||
| DB *database.Config `json:"db,omitempty"` | ||
| } | ||
|
|
||
| func (m *ProxyManager) Normalize() { | ||
| if m.Client.Secret == "" { | ||
| m.Client.Secret = m.Auth.Secret | ||
| } | ||
|
|
||
| if m.Client.ProxyVersion == "" { | ||
| m.Client.ProxyVersion = m.Verifier.MinProverVersion | ||
| } | ||
| } | ||
noel2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Proxy client configuration for connect to upstream as a client | ||
| type ProxyClient struct { | ||
| ProxyName string `json:"proxy_name"` | ||
| ProxyVersion string `json:"proxy_version,omitempty"` | ||
| Secret string `json:"secret,omitempty"` | ||
| } | ||
|
|
||
| // Coordinator configuration | ||
| type UpStream struct { | ||
| BaseUrl string `json:"base_url"` | ||
| RetryCount uint `json:"retry_count"` | ||
| RetryWaitTime uint `json:"retry_wait_time_sec"` | ||
| ConnectionTimeoutSec uint `json:"connection_timeout_sec"` | ||
| CompatibileMode bool `json:"compatible_mode,omitempty"` | ||
| } | ||
|
|
||
| // Config load configuration items. | ||
| type ProxyConfig struct { | ||
| ProxyManager *ProxyManager `json:"proxy_manager"` | ||
| ProxyName string `json:"proxy_name"` | ||
| Coordinators map[string]*UpStream `json:"coordinators"` | ||
| } | ||
|
|
||
| // NewConfig returns a new instance of Config. | ||
| func NewProxyConfig(file string) (*ProxyConfig, error) { | ||
| buf, err := os.ReadFile(filepath.Clean(file)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| cfg := &ProxyConfig{} | ||
| err = json.Unmarshal(buf, cfg) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Override config with environment variables | ||
| err = utils.OverrideConfigWithEnv(cfg, "SCROLL_COORDINATOR_PROXY") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return cfg, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Upgrade mapstructure to v2.4.0 to resolve security vulnerability CVE-2025-52893.
Version 1.5.0 remains vulnerable to CVE-2025-52893 / GHSA-fv92-fjc5-jj9h (sensitive data insertion into logs). The latest version, v2.4.0, was released July 15, 2025—before this PR was created—and addresses this vulnerability.
Upgrade the dependency and adjust imports:
Then run:
Update all imports in the codebase from
"github.com/mitchellh/mapstructure"to"github.com/mitchellh/mapstructure/v2"and run tests to verify compatibility.🤖 Prompt for AI Agents