Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
428 changes: 261 additions & 167 deletions op-node/node/node.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions op-node/p2p/cli/load_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"

"github.com/ethereum-optimism/optimism/op-node/flags"
"github.com/ethereum-optimism/optimism/op-node/p2p"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
opsigner "github.com/ethereum-optimism/optimism/op-service/signer"
)

// LoadSignerSetup loads a configuration for a Signer to be set up later
func LoadSignerSetup(ctx *cli.Context, logger log.Logger) (p2p.SignerSetup, error) {
func LoadSignerSetup(ctx cliiface.Context, logger log.Logger) (p2p.SignerSetup, error) {
key := ctx.String(flags.SequencerP2PKeyName)
signerCfg := opsigner.ReadCLIConfig(ctx)
if key != "" && signerCfg.Enabled() {
Expand Down
33 changes: 17 additions & 16 deletions op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup/engine"
"github.com/ethereum-optimism/optimism/op-node/rollup/interop"
"github.com/ethereum-optimism/optimism/op-node/rollup/sync"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
"github.com/ethereum-optimism/optimism/op-service/eth"
opflags "github.com/ethereum-optimism/optimism/op-service/flags"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
Expand All @@ -51,7 +52,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*config.Config, error) {
return nil, err
}

depSet, err := NewDependencySetFromCLI(ctx)
depSet, err := NewDependencySetFromCLI(ctx, ctx.Context)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -148,15 +149,15 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*config.Config, error) {
return cfg, nil
}

func NewSupervisorEndpointConfig(ctx *cli.Context) *interop.Config {
func NewSupervisorEndpointConfig(ctx cliiface.Context) *interop.Config {
return &interop.Config{
RPCAddr: ctx.String(flags.InteropRPCAddr.Name),
RPCPort: ctx.Int(flags.InteropRPCPort.Name),
RPCJwtSecretPath: ctx.String(flags.InteropJWTSecret.Name),
}
}

func NewBeaconEndpointConfig(ctx *cli.Context) config.L1BeaconEndpointSetup {
func NewBeaconEndpointConfig(ctx cliiface.Context) config.L1BeaconEndpointSetup {
return &config.L1BeaconEndpointConfig{
BeaconAddr: ctx.String(flags.BeaconAddr.Name),
BeaconHeader: ctx.String(flags.BeaconHeader.Name),
Expand All @@ -166,7 +167,7 @@ func NewBeaconEndpointConfig(ctx *cli.Context) config.L1BeaconEndpointSetup {
}
}

func NewL1EndpointConfig(ctx *cli.Context) *config.L1EndpointConfig {
func NewL1EndpointConfig(ctx cliiface.Context) *config.L1EndpointConfig {
return &config.L1EndpointConfig{
L1NodeAddr: ctx.String(flags.L1NodeAddr.Name),
L1TrustRPC: ctx.Bool(flags.L1TrustRPC.Name),
Expand All @@ -179,7 +180,7 @@ func NewL1EndpointConfig(ctx *cli.Context) *config.L1EndpointConfig {
}
}

func NewL2EndpointConfig(ctx *cli.Context, logger log.Logger) (*config.L2EndpointConfig, error) {
func NewL2EndpointConfig(ctx cliiface.Context, logger log.Logger) (*config.L2EndpointConfig, error) {
l2Addr := ctx.String(flags.L2EngineAddr.Name)
fileName := ctx.String(flags.L2EngineJWTSecret.Name)
secret, err := rpc.ObtainJWTSecret(logger, fileName, true)
Expand All @@ -194,15 +195,15 @@ func NewL2EndpointConfig(ctx *cli.Context, logger log.Logger) (*config.L2Endpoin
}, nil
}

func NewConfigPersistence(ctx *cli.Context) config.ConfigPersistence {
func NewConfigPersistence(ctx cliiface.Context) config.ConfigPersistence {
stateFile := ctx.String(flags.RPCAdminPersistence.Name)
if stateFile == "" {
return config.DisabledConfigPersistence{}
}
return config.NewConfigPersistence(stateFile)
}

func NewDriverConfig(ctx *cli.Context) *driver.Config {
func NewDriverConfig(ctx cliiface.Context) *driver.Config {
return &driver.Config{
VerifierConfDepth: ctx.Uint64(flags.VerifierL1Confs.Name),
SequencerConfDepth: ctx.Uint64(flags.SequencerL1Confs.Name),
Expand All @@ -213,7 +214,7 @@ func NewDriverConfig(ctx *cli.Context) *driver.Config {
}
}

func NewRollupConfigFromCLI(log log.Logger, ctx *cli.Context) (*rollup.Config, error) {
func NewRollupConfigFromCLI(log log.Logger, ctx cliiface.Context) (*rollup.Config, error) {
network := ctx.String(opflags.NetworkFlagName)
rollupConfigPath := ctx.String(opflags.RollupConfigFlagName)
if ctx.Bool(flags.BetaExtraNetworks.Name) {
Expand Down Expand Up @@ -257,7 +258,7 @@ Conflicting configuration is deprecated, and will stop the op-node from starting
return &rollupConfig, nil
}

func applyOverrides(ctx *cli.Context, rollupConfig *rollup.Config) {
func applyOverrides(ctx cliiface.Context, rollupConfig *rollup.Config) {
if ctx.IsSet(opflags.CanyonOverrideFlagName) {
canyon := ctx.Uint64(opflags.CanyonOverrideFlagName)
rollupConfig.CanyonTime = &canyon
Expand Down Expand Up @@ -300,7 +301,7 @@ func applyOverrides(ctx *cli.Context, rollupConfig *rollup.Config) {
}
}

func NewL1ChainConfig(chainId *big.Int, ctx *cli.Context, log log.Logger) (*params.ChainConfig, error) {
func NewL1ChainConfig(chainId *big.Int, ctx cliiface.Context, log log.Logger) (*params.ChainConfig, error) {
if chainId == nil {
panic("l1 chain id is nil")
}
Expand All @@ -323,7 +324,7 @@ func NewL1ChainConfig(chainId *big.Int, ctx *cli.Context, log log.Logger) (*para
return cf, nil
}

func NewL1ChainConfigFromCLI(log log.Logger, ctx *cli.Context) (*params.ChainConfig, error) {
func NewL1ChainConfigFromCLI(log log.Logger, ctx cliiface.Context) (*params.ChainConfig, error) {
l1ChainConfigPath := ctx.String(flags.L1ChainConfig.Name)
file, err := os.Open(l1ChainConfigPath)
if err != nil {
Expand All @@ -344,15 +345,15 @@ func NewL1ChainConfigFromCLI(log log.Logger, ctx *cli.Context) (*params.ChainCon
return jsonutil.LoadJSONFieldStrict[params.ChainConfig](l1ChainConfigPath, "config")
}

func NewDependencySetFromCLI(ctx *cli.Context) (depset.DependencySet, error) {
if !ctx.IsSet(flags.InteropDependencySet.Name) {
func NewDependencySetFromCLI(cli cliiface.Context, ctx context.Context) (depset.DependencySet, error) {
if !cli.IsSet(flags.InteropDependencySet.Name) {
return nil, nil
}
loader := &depset.JSONDependencySetLoader{Path: ctx.Path(flags.InteropDependencySet.Name)}
return loader.LoadDependencySet(ctx.Context)
loader := &depset.JSONDependencySetLoader{Path: cli.Path(flags.InteropDependencySet.Name)}
return loader.LoadDependencySet(ctx)
}

func NewSyncConfig(ctx *cli.Context, log log.Logger) (*sync.Config, error) {
func NewSyncConfig(ctx cliiface.Context, log log.Logger) (*sync.Config, error) {
if ctx.IsSet(flags.L2EngineSyncEnabled.Name) && ctx.IsSet(flags.SyncModeFlag.Name) {
return nil, errors.New("cannot set both --l2.engine-sync and --syncmode at the same time")
} else if ctx.IsSet(flags.L2EngineSyncEnabled.Name) {
Expand Down
21 changes: 21 additions & 0 deletions op-service/cliiface/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cliiface

import (
"time"
)

// Context defines the minimal surface of urfave/cli.Context that our
// configuration constructors depend on, across services.
type Context interface {
String(name string) string
Bool(name string) bool
Int(name string) int
Uint(name string) uint
Uint64(name string) uint64
Float64(name string) float64
Duration(name string) time.Duration
StringSlice(name string) []string
IsSet(name string) bool
Path(name string) string
Generic(name string) any
}
3 changes: 2 additions & 1 deletion op-service/log/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/cliapp"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
"github.com/ethereum-optimism/optimism/op-service/log/logfilter"
)

Expand Down Expand Up @@ -263,7 +264,7 @@ func DefaultCLIConfig() CLIConfig {
}
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
cfg := DefaultCLIConfig()
cfg.Level = ctx.Generic(LevelFlagName).(*LevelFlagValue).Level()
cfg.Format = ctx.Generic(FormatFlagName).(*FormatFlagValue).FormatType()
Expand Down
3 changes: 2 additions & 1 deletion op-service/metrics/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

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

"github.com/ethereum-optimism/optimism/op-service/cliiface"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func (m CLIConfig) Check() error {
return nil
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
return CLIConfig{
Enabled: ctx.Bool(EnabledFlagName),
ListenAddr: ctx.String(ListenAddrFlagName),
Expand Down
3 changes: 2 additions & 1 deletion op-service/oppprof/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
openum "github.com/ethereum-optimism/optimism/op-service/enum"
"github.com/ethereum-optimism/optimism/op-service/flags"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -129,7 +130,7 @@ func (m CLIConfig) Check() error {
return nil
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
profilePathFlag := ctx.Generic(ProfilePathFlagName).(*flags.PathFlag)
return CLIConfig{
ListenEnabled: ctx.Bool(EnabledFlagName),
Expand Down
3 changes: 2 additions & 1 deletion op-service/rpc/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func (c CLIConfig) Check() error {
return nil
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
return CLIConfig{
ListenAddr: ctx.String(ListenAddrFlagName),
ListenPort: ctx.Int(PortFlagName),
Expand Down
4 changes: 2 additions & 2 deletions op-service/signer/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/urfave/cli/v2"

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

Expand Down Expand Up @@ -70,7 +71,7 @@ func (c CLIConfig) Enabled() bool {
return c.Endpoint != "" && c.Address != ""
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
var headers = http.Header{}
if ctx.StringSlice(HeadersFlagName) != nil {
for _, header := range ctx.StringSlice(HeadersFlagName) {
Expand All @@ -80,7 +81,6 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
}
}
}

cfg := CLIConfig{
Endpoint: ctx.String(EndpointFlagName),
Address: ctx.String(AddressFlagName),
Expand Down
3 changes: 2 additions & 1 deletion op-service/tls/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/urfave/cli/v2"

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

const (
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c CLIConfig) TLSEnabled() bool {

// ReadCLIConfigWithPrefix reads tls cli configs with flag prefix
// Should be used for client TLS configs when different from server on the same process
func ReadCLIConfigWithPrefix(ctx *cli.Context, flagPrefix string) CLIConfig {
func ReadCLIConfigWithPrefix(ctx cliiface.Context, flagPrefix string) CLIConfig {
prefixFunc := func(flagName string) string {
return strings.Trim(fmt.Sprintf("%s.%s", flagPrefix, flagName), ".")
}
Expand Down
3 changes: 2 additions & 1 deletion op-service/txmgr/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/cliiface"
opcrypto "github.com/ethereum-optimism/optimism/op-service/crypto"
"github.com/ethereum-optimism/optimism/op-service/eth"
opsigner "github.com/ethereum-optimism/optimism/op-service/signer"
Expand Down Expand Up @@ -352,7 +353,7 @@ func (m CLIConfig) Check() error {
return nil
}

func ReadCLIConfig(ctx *cli.Context) CLIConfig {
func ReadCLIConfig(ctx cliiface.Context) CLIConfig {
return CLIConfig{
L1RPCURL: ctx.String(L1RPCFlagName),
Mnemonic: ctx.String(MnemonicFlagName),
Expand Down