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
5 changes: 5 additions & 0 deletions node/derivation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ func (c *Config) SetCliContext(ctx *cli.Context) error {
}
}

legacyValidatorMode := ctx.GlobalBool(flags.LegacyValidatorMode.Name)
if legacyValidatorMode {
log.Warn("--validator is deprecated; use --derivation.verify-mode=layer1")
c.VerifyMode = VerifyModeLayer1
}
if ctx.GlobalIsSet(flags.DerivationVerifyMode.Name) {
c.VerifyMode = ctx.GlobalString(flags.DerivationVerifyMode.Name)
}
Expand Down
62 changes: 62 additions & 0 deletions node/derivation/config_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package derivation

import (
"flag"
"path/filepath"
"strings"
"testing"

"github.com/urfave/cli"

"morph-l2/node/flags"
)

// SPEC-005 section 4.2 + 5.1 verify-mode dispatch tests. The mode is bound at
Expand Down Expand Up @@ -35,6 +41,31 @@ func TestVerifyMode_AcceptsExplicitModes(t *testing.T) {
}
}

func TestVerifyMode_LegacyValidatorAlias(t *testing.T) {
cfg := DefaultConfig()
if err := cfg.SetCliContext(newVerifyModeTestContext(t, map[string]string{
flags.LegacyValidatorMode.Name: "true",
})); err != nil {
t.Fatalf("legacy validator alias rejected: %v", err)
}
if cfg.VerifyMode != VerifyModeLayer1 {
t.Fatalf("legacy validator alias resolved to %q, want %q", cfg.VerifyMode, VerifyModeLayer1)
}
}

func TestVerifyMode_ExplicitModeOverridesLegacyValidatorAlias(t *testing.T) {
cfg := DefaultConfig()
if err := cfg.SetCliContext(newVerifyModeTestContext(t, map[string]string{
flags.LegacyValidatorMode.Name: "true",
flags.DerivationVerifyMode.Name: VerifyModeLocal,
})); err != nil {
t.Fatalf("explicit verify-mode rejected: %v", err)
}
if cfg.VerifyMode != VerifyModeLocal {
t.Fatalf("explicit verify-mode resolved to %q, want %q", cfg.VerifyMode, VerifyModeLocal)
}
}

func TestVerifyMode_RejectsUnknown(t *testing.T) {
// "hybrid" was the old default; ensure post-removal it's rejected so
// stale operator configs fail loud rather than silently falling back to
Expand Down Expand Up @@ -66,3 +97,34 @@ func validateAndDefaultVerifyModeErr(t *testing.T, s string) error {
}
return err
}

func newVerifyModeTestContext(t *testing.T, values map[string]string) *cli.Context {
t.Helper()

flagSet := flag.NewFlagSet(t.Name(), flag.ContinueOnError)
for _, f := range []cli.Flag{
flags.LegacyValidatorMode,
flags.DerivationVerifyMode,
flags.L1BeaconAddr,
flags.L2EngineJWTSecret,
} {
f.Apply(flagSet)
}

defaults := map[string]string{
flags.L1BeaconAddr.Name: "http://beacon.example",
flags.L2EngineJWTSecret.Name: filepath.Join(t.TempDir(), "jwt.hex"),
}
for name, value := range defaults {
if err := flagSet.Set(name, value); err != nil {
t.Fatalf("set default flag %s: %v", name, err)
}
}
for name, value := range values {
if err := flagSet.Set(name, value); err != nil {
t.Fatalf("set flag %s: %v", name, err)
}
}

return cli.NewContext(cli.NewApp(), flagSet, nil)
}
7 changes: 7 additions & 0 deletions node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ var (
EnvVar: prefixEnvVar("MOCK_SEQUENCER"),
}

LegacyValidatorMode = cli.BoolFlag{
Name: "validator",
Usage: "Deprecated compatibility alias for --derivation.verify-mode=layer1",
EnvVar: prefixEnvVar("VALIDATOR"),
}

// derivation
RollupContractAddress = cli.StringFlag{
Name: "derivation.rollupAddress",
Expand Down Expand Up @@ -368,6 +374,7 @@ var Flags = []cli.Flag{
DevSequencer,
TendermintConfigPath,
MockEnabled,
LegacyValidatorMode,

// derivation
RollupContractAddress,
Expand Down
Loading