Skip to content

Commit

Permalink
op-wheel,op-service: create op-wheel, and extend op-service base func…
Browse files Browse the repository at this point in the history
…tionality
  • Loading branch information
protolambda committed Dec 7, 2022
1 parent c129ec6 commit fe7509d
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use (
./op-batcher
./op-bindings
./op-chain-ops
./op-wheel
./op-e2e
./op-exporter
./op-node
Expand Down
72 changes: 72 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion op-service/log/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"os"
"strings"

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"
"golang.org/x/term"

opservice "github.com/ethereum-optimism/optimism/op-service"
)

const (
Expand Down Expand Up @@ -77,6 +78,14 @@ func DefaultCLIConfig() CLIConfig {
}
}

func ReadLocalCLIConfig(ctx *cli.Context) CLIConfig {
cfg := DefaultCLIConfig()
cfg.Level = ctx.String(LevelFlagName)
cfg.Format = ctx.String(FormatFlagName)
cfg.Color = ctx.Bool(ColorFlagName)
return cfg
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
cfg := DefaultCLIConfig()
cfg.Level = ctx.GlobalString(LevelFlagName)
Expand Down
8 changes: 8 additions & 0 deletions op-service/metrics/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
ListenPort: ctx.GlobalInt(PortFlagName),
}
}

func ReadLocalCLIConfig(ctx *cli.Context) CLIConfig {
return CLIConfig{
Enabled: ctx.Bool(EnabledFlagName),
ListenAddr: ctx.String(ListenAddrFlagName),
ListenPort: ctx.Int(PortFlagName),
}
}
44 changes: 44 additions & 0 deletions op-service/util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
package op_service

import (
"context"
"errors"
"os"
"os/signal"
"syscall"
"time"
)

func PrefixEnvVar(prefix, suffix string) string {
return prefix + "_" + suffix
}

// CloseAction runs the function in the background, until it finishes or until it is closed by the user with an interrupt.
func CloseAction(fn func(ctx context.Context, shutdown <-chan struct{}) error) error {
stopped := make(chan error, 1)
shutdown := make(chan struct{}, 1)

ctx, cancel := context.WithCancel(context.Background())
go func() {
stopped <- fn(ctx, shutdown)
}()

doneCh := make(chan os.Signal, 1)
signal.Notify(doneCh, []os.Signal{
os.Interrupt,
os.Kill,
syscall.SIGTERM,
syscall.SIGQUIT,
}...)

select {
case <-doneCh:
cancel()
shutdown <- struct{}{}

select {
case err := <-stopped:
return err
case <-time.After(time.Second * 10):
return errors.New("command action is unresponsive for more than 10 seconds... shutting down")
}
case err := <-stopped:
cancel()
return err
}
}
1 change: 1 addition & 0 deletions op-wheel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
18 changes: 18 additions & 0 deletions op-wheel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.18.0-alpine3.15 as builder

RUN apk add --no-cache make gcc musl-dev linux-headers

COPY ./op-wheel/docker.go.work /app/go.work
COPY ./op-node /app/op-node
COPY ./op-service /app/op-service
COPY ./op-wheel /app/op-wheel

WORKDIR /app/op-wheel

RUN go build -o op-wheel ./cmd/main.go

FROM alpine:3.15

COPY --from=builder /app/op-wheel/op-wheel /usr/local/bin

CMD ["op-wheel"]
52 changes: 52 additions & 0 deletions op-wheel/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"errors"
"fmt"
"os"

"github.com/urfave/cli"

"github.com/ethereum/go-ethereum/log"

oplog "github.com/ethereum-optimism/optimism/op-service/log"
wheel "github.com/ethereum-optimism/optimism/op-wheel"
)

var (
Version = ""
GitCommit = ""
GitDate = ""
)

func main() {
app := cli.NewApp()
app.Version = fmt.Sprintf("%s-%s-%s", Version, GitCommit, GitDate)
app.Name = "op-wheel"
app.Usage = "Optimism Wheel is a CLI tool for the execution engine"
app.Description = "Optimism Wheel is a CLI tool to direct the engine one way or the other with DB cheats and Engine API routines."
app.Flags = []cli.Flag{wheel.GlobalGethLogLvlFlag}
app.Before = func(c *cli.Context) error {
log.Root().SetHandler(
log.LvlFilterHandler(
oplog.Level(c.GlobalString(wheel.GlobalGethLogLvlFlag.Name)),
log.StreamHandler(os.Stdout, log.TerminalFormat(true)),
),
)
return nil
}
app.Action = cli.ActionFunc(func(c *cli.Context) error {
return errors.New("see 'cheat' and 'engine' subcommands and --help")
})
app.Writer = os.Stdout
app.ErrWriter = os.Stderr
app.Commands = []cli.Command{
//wheel.CheatCmd,
//wheel.EngineCmd,
}

err := app.Run(os.Args)
if err != nil {
log.Crit("Application failed", "message", err)
}
}
16 changes: 16 additions & 0 deletions op-wheel/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package wheel

import (
"github.com/urfave/cli"

opservice "github.com/ethereum-optimism/optimism/op-service"
)

var (
GlobalGethLogLvlFlag = cli.StringFlag{
Name: "geth-log-level",
Usage: "Set the global geth logging level",
EnvVar: opservice.PrefixEnvVar("OP_WHEEL", "GETH_LOG_LEVEL"),
Value: "error",
}
)
7 changes: 7 additions & 0 deletions op-wheel/docker.go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go 1.18

use (
./op-node
./op-service
./op-wheel
)
19 changes: 19 additions & 0 deletions op-wheel/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/ethereum-optimism/optimism/op-wheel

go 1.18

require (
github.com/ethereum-optimism/optimism/op-service v0.10.3
github.com/ethereum/go-ethereum v1.10.26
github.com/urfave/cli v1.22.10
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
)

replace github.com/ethereum/go-ethereum v1.10.26 => github.com/ethereum-optimism/op-geth v0.0.0-20221205191237-0678a130d790
23 changes: 23 additions & 0 deletions op-wheel/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/ethereum-optimism/op-geth v0.0.0-20221205191237-0678a130d790 h1:QJL/gtfxGe11tApZIPCeKERQHrLZMAG0RwGV9eTgtvE=
github.com/ethereum-optimism/op-geth v0.0.0-20221205191237-0678a130d790/go.mod h1:p0Yox74PhYlq1HvijrCBCD9A3cI7rXco7hT6KrQr+rY=
github.com/ethereum-optimism/optimism/op-service v0.10.3 h1:gr+eVq6CzxMFqo0/9n6EoUkpumtYZEzO84gti6ekj/s=
github.com/ethereum-optimism/optimism/op-service v0.10.3/go.mod h1:hCY0nAeGYp3YqB0NpLmOzUdXV/5t9EyukHMTJL3pIUQ=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit fe7509d

Please sign in to comment.