-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(coordinator): split the coordinator cron to single process (#995)
Co-authored-by: maskpp <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]> Co-authored-by: HAOYUatHZ <[email protected]>
- Loading branch information
1 parent
8494ab1
commit 50040a1
Showing
20 changed files
with
217 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 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
File renamed without changes.
This file contains 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,25 @@ | ||
# Download Go dependencies | ||
FROM scrolltech/go-alpine-builder:1.19 as base | ||
|
||
WORKDIR /src | ||
COPY go.work* ./ | ||
COPY ./rollup/go.* ./rollup/ | ||
COPY ./common/go.* ./common/ | ||
COPY ./coordinator/go.* ./coordinator/ | ||
COPY ./database/go.* ./database/ | ||
COPY ./prover/go.* ./prover/ | ||
COPY ./tests/integration-test/go.* ./tests/integration-test/ | ||
COPY ./bridge-history-api/go.* ./bridge-history-api/ | ||
RUN go mod download -x | ||
|
||
# Build coordinator | ||
FROM base as builder | ||
RUN --mount=target=. \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
cd /src/coordinator/cmd/cron/ && go build -v -p 4 -o /bin/coordinator_cron | ||
|
||
# Pull coordinator into a second stage deploy alpine container | ||
FROM alpine:latest | ||
COPY --from=builder /bin/coordinator_cron /bin/ | ||
|
||
ENTRYPOINT ["coordinator_cron"] |
This file contains 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,6 @@ | ||
assets/ | ||
contracts/ | ||
docs/ | ||
l2geth/ | ||
rpc-gateway/ | ||
*target/* |
This file contains 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 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 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 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 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 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 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 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 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/api/app" | ||
|
||
func main() { | ||
app.Run() | ||
} |
This file contains 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,87 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/scroll-tech/go-ethereum/log" | ||
"github.com/urfave/cli/v2" | ||
|
||
"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/cron" | ||
) | ||
|
||
var app *cli.App | ||
|
||
func init() { | ||
// Set up coordinator app info. | ||
app = cli.NewApp() | ||
app.Action = action | ||
app.Name = "coordinator cron" | ||
app.Usage = "The Scroll L2 Coordinator cron" | ||
app.Version = version.Version | ||
app.Flags = append(app.Flags, utils.CommonFlags...) | ||
app.Before = func(ctx *cli.Context) error { | ||
return utils.LogSetup(ctx) | ||
} | ||
// Register `coordinator-cron-test` app for integration-cron-test. | ||
utils.RegisterSimulation(app, utils.CoordinatorCronApp) | ||
} | ||
|
||
func action(ctx *cli.Context) error { | ||
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) | ||
} | ||
|
||
subCtx, cancel := context.WithCancel(ctx.Context) | ||
db, err := database.InitDB(cfg.DB) | ||
if err != nil { | ||
log.Crit("failed to init db connection", "err", err) | ||
} | ||
|
||
registry := prometheus.DefaultRegisterer | ||
observability.Server(ctx, db) | ||
|
||
proofCollector := cron.NewCollector(subCtx, db, cfg, registry) | ||
defer func() { | ||
proofCollector.Stop() | ||
cancel() | ||
if err = database.CloseDB(db); err != nil { | ||
log.Error("can not close db connection", "error", err) | ||
} | ||
}() | ||
|
||
log.Info( | ||
"coordinator cron start 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("coordinator cron exiting success") | ||
return nil | ||
} | ||
|
||
// Run coordinator. | ||
func Run() { | ||
// RunApp the coordinator. | ||
if err := app.Run(os.Args); err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.