-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
3,250 additions
and
1,619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//nolint:dupl // disable duplicate code warning for cmds | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/creasty/defaults" | ||
"github.com/ethpandaops/xatu/pkg/cannon" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
yaml "gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
cannonCfgFile string | ||
) | ||
|
||
// cannonCmd represents the cannon command | ||
var cannonCmd = &cobra.Command{ | ||
Use: "cannon", | ||
Short: "Runs Xatu in cannon mode.", | ||
Long: `Runs Xatu in cannon mode, which means it will connect to xatu | ||
server and process jobs like deriving events from beacon blocks..`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
initCommon() | ||
|
||
log.WithField("location", cannonCfgFile).Info("Loading config") | ||
|
||
config, err := loadcannonConfigFromFile(cannonCfgFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Info("Config loaded") | ||
|
||
logLevel, err := logrus.ParseLevel(config.LoggingLevel) | ||
if err != nil { | ||
log.WithField("logLevel", config.LoggingLevel).Fatal("invalid logging level") | ||
} | ||
|
||
log.SetLevel(logLevel) | ||
|
||
cannon, err := cannon.New(cmd.Context(), log, config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := cannon.Start(cmd.Context()); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Info("Xatu cannon exited - cya!") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(cannonCmd) | ||
|
||
cannonCmd.Flags().StringVar(&cannonCfgFile, "config", "cannon.yaml", "config file (default is cannon.yaml)") | ||
} | ||
|
||
func loadcannonConfigFromFile(file string) (*cannon.Config, error) { | ||
if file == "" { | ||
file = "cannon.yaml" | ||
} | ||
|
||
config := &cannon.Config{} | ||
|
||
if err := defaults.Set(config); err != nil { | ||
return nil, err | ||
} | ||
|
||
yamlFile, err := os.ReadFile(file) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
type plain cannon.Config | ||
|
||
if err := yaml.Unmarshal(yamlFile, (*plain)(config)); err != nil { | ||
return nil, err | ||
} | ||
|
||
return config, nil | ||
} |
Oops, something went wrong.