Skip to content

Commit

Permalink
Validate node config
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Sep 12, 2024
1 parent 690f812 commit fd3823b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 0 additions & 4 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.L
var nodes []mn.Node[mn.StringID, *client.Client]

for i, nodeInfo := range cfg.ListNodes() {
if nodeInfo == nil || nodeInfo.Name == nil || nodeInfo.URL == nil {
return nil, fmt.Errorf("node config contains nil: %+v", nodeInfo)
}
// create client and check
rpcClient, err := client.NewClient(nodeInfo.URL.String(), cfg, DefaultRequestTimeout, logger.Named(lggr, "Client."+*nodeInfo.Name))
if err != nil {
lggr.Warnw("failed to create client", "name", *nodeInfo.Name, "solana-url", nodeInfo.URL.String(), "err", err.Error())
Expand Down
17 changes: 17 additions & 0 deletions pkg/solana/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ func (c *TOMLConfig) ValidateConfig() (err error) {
if len(c.Nodes) == 0 {
err = errors.Join(err, config.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
}

for _, node := range c.Nodes {
if node == nil {
err = errors.Join(err, config.ErrMissing{Name: "Node", Msg: "required for all nodes"})
}
if node.Name == nil {
err = errors.Join(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"})
} else if *node.Name == "" {
err = errors.Join(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
}
if node.URL == nil {
err = errors.Join(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"})
} else if (*url.URL)(node.URL) == nil {
err = errors.Join(err, config.ErrEmpty{Name: "URL", Msg: "required for all nodes"})
}
}

return
}

Expand Down

0 comments on commit fd3823b

Please sign in to comment.