Skip to content

Commit

Permalink
op-node: Expose method to load rollup config without a CLI context. (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored Feb 15, 2024
1 parent 08921d5 commit f2cf85a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion op-bootnode/bootnode/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Main(cliCtx *cli.Context) error {
m := metrics.NewMetrics("default")
ctx := context.Background()

config, err := opnode.NewRollupConfig(logger, cliCtx)
config, err := opnode.NewRollupConfigFromCLI(logger, cliCtx)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion op-conductor/conductor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*Config, error) {
return nil, errors.Wrap(err, "missing required flags")
}

rollupCfg, err := opnode.NewRollupConfig(log, ctx)
rollupCfg, err := opnode.NewRollupConfigFromCLI(log, ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to load rollup config")
}
Expand Down
2 changes: 1 addition & 1 deletion op-node/cmd/networks/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var Subcommands = []*cli.Command{
return errors.New("must specify a network name")
}

rCfg, err := opnode.NewRollupConfig(logger, ctx)
rCfg, err := opnode.NewRollupConfigFromCLI(logger, ctx)
if err != nil {
return err
}
Expand Down
15 changes: 11 additions & 4 deletions op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
return nil, err
}

rollupConfig, err := NewRollupConfig(log, ctx)
rollupConfig, err := NewRollupConfigFromCLI(log, ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,12 +196,21 @@ func NewDriverConfig(ctx *cli.Context) *driver.Config {
}
}

func NewRollupConfig(log log.Logger, ctx *cli.Context) (*rollup.Config, error) {
func NewRollupConfigFromCLI(log log.Logger, ctx *cli.Context) (*rollup.Config, error) {
network := ctx.String(opflags.NetworkFlagName)
rollupConfigPath := ctx.String(opflags.RollupConfigFlagName)
if ctx.Bool(flags.BetaExtraNetworks.Name) {
log.Warn("The beta.extra-networks flag is deprecated and can be omitted safely.")
}
rollupConfig, err := NewRollupConfig(log, network, rollupConfigPath)
if err != nil {
return nil, err
}
applyOverrides(ctx, rollupConfig)
return rollupConfig, nil
}

func NewRollupConfig(log log.Logger, network string, rollupConfigPath string) (*rollup.Config, error) {
if network != "" {
if rollupConfigPath != "" {
log.Error(`Cannot configure network and rollup-config at the same time.
Expand All @@ -213,7 +222,6 @@ Conflicting configuration is deprecated, and will stop the op-node from starting
if err != nil {
return nil, err
}
applyOverrides(ctx, rollupConfig)
return rollupConfig, nil
}

Expand All @@ -227,7 +235,6 @@ Conflicting configuration is deprecated, and will stop the op-node from starting
if err := json.NewDecoder(file).Decode(&rollupConfig); err != nil {
return nil, fmt.Errorf("failed to decode rollup config: %w", err)
}
applyOverrides(ctx, &rollupConfig)
return &rollupConfig, nil
}

Expand Down
3 changes: 1 addition & 2 deletions op-program/host/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type Config struct {
L1RPCKind sources.RPCProviderKind

// L2Head is the l2 block hash contained in the L2 Output referenced by the L2OutputRoot
// TODO(inphi): This can be made optional with hardcoded rollup configs and output oracle addresses by searching the oracle for the l2 output root
L2Head common.Hash
// L2OutputRoot is the agreed L2 output root to start derivation from
L2OutputRoot common.Hash
Expand Down Expand Up @@ -138,7 +137,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
if err := flags.CheckRequired(ctx); err != nil {
return nil, err
}
rollupCfg, err := opnode.NewRollupConfig(log, ctx)
rollupCfg, err := opnode.NewRollupConfigFromCLI(log, ctx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f2cf85a

Please sign in to comment.