Commit f2cf85a0 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-node: Expose method to load rollup config without a CLI context. (#9554)

parent 08921d5c
...@@ -50,7 +50,7 @@ func Main(cliCtx *cli.Context) error { ...@@ -50,7 +50,7 @@ func Main(cliCtx *cli.Context) error {
m := metrics.NewMetrics("default") m := metrics.NewMetrics("default")
ctx := context.Background() ctx := context.Background()
config, err := opnode.NewRollupConfig(logger, cliCtx) config, err := opnode.NewRollupConfigFromCLI(logger, cliCtx)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -101,7 +101,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*Config, error) { ...@@ -101,7 +101,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*Config, error) {
return nil, errors.Wrap(err, "missing required flags") return nil, errors.Wrap(err, "missing required flags")
} }
rollupCfg, err := opnode.NewRollupConfig(log, ctx) rollupCfg, err := opnode.NewRollupConfigFromCLI(log, ctx)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to load rollup config") return nil, errors.Wrap(err, "failed to load rollup config")
} }
......
...@@ -29,7 +29,7 @@ var Subcommands = []*cli.Command{ ...@@ -29,7 +29,7 @@ var Subcommands = []*cli.Command{
return errors.New("must specify a network name") return errors.New("must specify a network name")
} }
rCfg, err := opnode.NewRollupConfig(logger, ctx) rCfg, err := opnode.NewRollupConfigFromCLI(logger, ctx)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -33,7 +33,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) { ...@@ -33,7 +33,7 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
return nil, err return nil, err
} }
rollupConfig, err := NewRollupConfig(log, ctx) rollupConfig, err := NewRollupConfigFromCLI(log, ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -196,12 +196,21 @@ func NewDriverConfig(ctx *cli.Context) *driver.Config { ...@@ -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) network := ctx.String(opflags.NetworkFlagName)
rollupConfigPath := ctx.String(opflags.RollupConfigFlagName) rollupConfigPath := ctx.String(opflags.RollupConfigFlagName)
if ctx.Bool(flags.BetaExtraNetworks.Name) { if ctx.Bool(flags.BetaExtraNetworks.Name) {
log.Warn("The beta.extra-networks flag is deprecated and can be omitted safely.") 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 network != "" {
if rollupConfigPath != "" { if rollupConfigPath != "" {
log.Error(`Cannot configure network and rollup-config at the same time. log.Error(`Cannot configure network and rollup-config at the same time.
...@@ -213,7 +222,6 @@ Conflicting configuration is deprecated, and will stop the op-node from starting ...@@ -213,7 +222,6 @@ Conflicting configuration is deprecated, and will stop the op-node from starting
if err != nil { if err != nil {
return nil, err return nil, err
} }
applyOverrides(ctx, rollupConfig)
return rollupConfig, nil return rollupConfig, nil
} }
...@@ -227,7 +235,6 @@ Conflicting configuration is deprecated, and will stop the op-node from starting ...@@ -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 { if err := json.NewDecoder(file).Decode(&rollupConfig); err != nil {
return nil, fmt.Errorf("failed to decode rollup config: %w", err) return nil, fmt.Errorf("failed to decode rollup config: %w", err)
} }
applyOverrides(ctx, &rollupConfig)
return &rollupConfig, nil return &rollupConfig, nil
} }
......
...@@ -46,7 +46,6 @@ type Config struct { ...@@ -46,7 +46,6 @@ type Config struct {
L1RPCKind sources.RPCProviderKind L1RPCKind sources.RPCProviderKind
// L2Head is the l2 block hash contained in the L2 Output referenced by the L2OutputRoot // 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 L2Head common.Hash
// L2OutputRoot is the agreed L2 output root to start derivation from // L2OutputRoot is the agreed L2 output root to start derivation from
L2OutputRoot common.Hash L2OutputRoot common.Hash
...@@ -138,7 +137,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) { ...@@ -138,7 +137,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
if err := flags.CheckRequired(ctx); err != nil { if err := flags.CheckRequired(ctx); err != nil {
return nil, err return nil, err
} }
rollupCfg, err := opnode.NewRollupConfig(log, ctx) rollupCfg, err := opnode.NewRollupConfigFromCLI(log, ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
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