From c4d5e8a7ab12239f380a438046e6e994f0253ab3 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Fri, 26 Feb 2021 13:09:13 +0100 Subject: [PATCH] WIP --- cli/node/main.go | 10 ++++++---- config/config.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cli/node/main.go b/cli/node/main.go index b95e141..d7bf69d 100644 --- a/cli/node/main.go +++ b/cli/node/main.go @@ -144,10 +144,15 @@ func cmdRun(c *cli.Context) error { } func cmdServeAPI(c *cli.Context) error { - cfg, err := parseCli(c) + cfgPath := c.String(flagCfg) + cfg, err := config.LoadAPIServer(cfgPath) if err != nil { + if err := cli.ShowAppHelp(c); err != nil { + panic(err) + } return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err)) } + node, err := node.NewNode(cfg.mode, cfg.node) if err != nil { return tracerr.Wrap(fmt.Errorf("error starting node: %w", err)) @@ -261,9 +266,6 @@ func getConfig(c *cli.Context) (*Config, error) { var cfg Config mode := c.String(flagMode) nodeCfgPath := c.String(flagCfg) - if nodeCfgPath == "" { - return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCfg)) - } var err error switch mode { case modeSync: diff --git a/config/config.go b/config/config.go index 463807c..f517497 100644 --- a/config/config.go +++ b/config/config.go @@ -338,6 +338,17 @@ type APIServer struct { Coordinator bool } `validate:"required"` } `validate:"required"` + L2DB struct { + // MaxTxs is the maximum number of pending L2Txs that can be + // stored in the pool. Once this number of pending L2Txs is + // reached, inserts to the pool will be denied until some of + // the pending txs are forged. + MaxTxs uint32 `validate:"required"` + // MinFeeUSD is the minimum fee in USD that a tx must pay in + // order to be accepted into the pool. Txs with lower than + // minimum fee will be rejected at the API level. + MinFeeUSD float64 + } `validate:"required"` Debug NodeDebug `validate:"required"` } @@ -382,3 +393,16 @@ func LoadNode(path string) (*Node, error) { } return &cfg, nil } + +// LoadAPIServer loads the APIServer configuration from path. +func LoadAPIServer(path string) (*APIServer, error) { + var cfg APIServer + if err := Load(path, &cfg); err != nil { + return nil, tracerr.Wrap(fmt.Errorf("error loading apiServer configuration file: %w", err)) + } + validate := validator.New() + if err := validate.Struct(cfg); err != nil { + return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err)) + } + return &cfg, nil +}