Commit fe7509da authored by protolambda's avatar protolambda

op-wheel,op-service: create op-wheel, and extend op-service base functionality

parent c129ec6a
...@@ -11,6 +11,7 @@ use ( ...@@ -11,6 +11,7 @@ use (
./op-batcher ./op-batcher
./op-bindings ./op-bindings
./op-chain-ops ./op-chain-ops
./op-wheel
./op-e2e ./op-e2e
./op-exporter ./op-exporter
./op-node ./op-node
......
This diff is collapsed.
...@@ -5,10 +5,11 @@ import ( ...@@ -5,10 +5,11 @@ import (
"os" "os"
"strings" "strings"
opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/term" "golang.org/x/term"
opservice "github.com/ethereum-optimism/optimism/op-service"
) )
const ( const (
...@@ -77,6 +78,14 @@ func DefaultCLIConfig() CLIConfig { ...@@ -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 { func ReadCLIConfig(ctx *cli.Context) CLIConfig {
cfg := DefaultCLIConfig() cfg := DefaultCLIConfig()
cfg.Level = ctx.GlobalString(LevelFlagName) cfg.Level = ctx.GlobalString(LevelFlagName)
......
...@@ -62,3 +62,11 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig { ...@@ -62,3 +62,11 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
ListenPort: ctx.GlobalInt(PortFlagName), ListenPort: ctx.GlobalInt(PortFlagName),
} }
} }
func ReadLocalCLIConfig(ctx *cli.Context) CLIConfig {
return CLIConfig{
Enabled: ctx.Bool(EnabledFlagName),
ListenAddr: ctx.String(ListenAddrFlagName),
ListenPort: ctx.Int(PortFlagName),
}
}
package op_service package op_service
import (
"context"
"errors"
"os"
"os/signal"
"syscall"
"time"
)
func PrefixEnvVar(prefix, suffix string) string { func PrefixEnvVar(prefix, suffix string) string {
return prefix + "_" + suffix 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
}
}
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"]
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)
}
}
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",
}
)
go 1.18
use (
./op-node
./op-service
./op-wheel
)
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
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=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment