check flags validity in Action method

This commit is contained in:
maskpp 2025-07-09 16:04:03 +08:00
parent 063033834b
commit 2cf8806d56

View file

@ -258,17 +258,35 @@ var (
Usage: `Blockchain sync mode ("snap" or "full")`, Usage: `Blockchain sync mode ("snap" or "full")`,
Value: ethconfig.Defaults.SyncMode.String(), Value: ethconfig.Defaults.SyncMode.String(),
Category: flags.StateCategory, Category: flags.StateCategory,
Action: func(c *cli.Context, s string) error {
if s != "snap" && s != "full" {
Fatalf("--syncmode must be either 'snap' or 'full'")
}
return nil
},
} }
GCModeFlag = &cli.StringFlag{ GCModeFlag = &cli.StringFlag{
Name: "gcmode", Name: "gcmode",
Usage: `Blockchain garbage collection mode ("full", "archive")`, Usage: `Blockchain garbage collection mode ("full", "archive")`,
Value: "full", Value: "full",
Category: flags.StateCategory, Category: flags.StateCategory,
Action: func(c *cli.Context, s string) error {
if s != "full" && s != "archive" {
Fatalf("--gcmode must be either 'full' or 'archive'")
}
return nil
},
} }
StateSchemeFlag = &cli.StringFlag{ StateSchemeFlag = &cli.StringFlag{
Name: "state.scheme", Name: "state.scheme",
Usage: "Scheme to use for storing ethereum state ('hash' or 'path')", Usage: "Scheme to use for storing ethereum state ('hash' or 'path')",
Category: flags.StateCategory, Category: flags.StateCategory,
Action: func(c *cli.Context, s string) error {
if s != "hash" && s != "path" {
Fatalf("--state.scheme must be either 'hash' or 'path'")
}
return nil
},
} }
StateHistoryFlag = &cli.Uint64Flag{ StateHistoryFlag = &cli.Uint64Flag{
Name: "history.state", Name: "history.state",
@ -287,6 +305,12 @@ var (
Usage: `Blockchain history retention ("all" or "postmerge")`, Usage: `Blockchain history retention ("all" or "postmerge")`,
Value: ethconfig.Defaults.HistoryMode.String(), Value: ethconfig.Defaults.HistoryMode.String(),
Category: flags.StateCategory, Category: flags.StateCategory,
Action: func(c *cli.Context, s string) error {
if s != "all" && s != "postmerge" {
Fatalf("--history.chain must be either 'all' or 'postmerge'")
}
return nil
},
} }
LogHistoryFlag = &cli.Uint64Flag{ LogHistoryFlag = &cli.Uint64Flag{
Name: "history.logs", Name: "history.logs",
@ -1622,10 +1646,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(EraFlag.Name) { if ctx.IsSet(EraFlag.Name) {
cfg.DatabaseEra = ctx.String(EraFlag.Name) cfg.DatabaseEra = ctx.String(EraFlag.Name)
} }
if gcmode := ctx.String(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
if ctx.IsSet(GCModeFlag.Name) { if ctx.IsSet(GCModeFlag.Name) {
cfg.NoPruning = ctx.String(GCModeFlag.Name) == "archive" cfg.NoPruning = ctx.String(GCModeFlag.Name) == "archive"
} }
@ -2179,9 +2199,6 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
if err != nil { if err != nil {
Fatalf("%v", err) Fatalf("%v", err)
} }
if gcmode := ctx.String(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
scheme, err := rawdb.ParseStateScheme(ctx.String(StateSchemeFlag.Name), chainDb) scheme, err := rawdb.ParseStateScheme(ctx.String(StateSchemeFlag.Name), chainDb)
if err != nil { if err != nil {
Fatalf("%v", err) Fatalf("%v", err)