-
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.
Merge pull request #168 from ethpandaops/feat/cannon
feat: Cannon
- Loading branch information
Showing
52 changed files
with
9,088 additions
and
2,065 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"mode": "debug", | ||
"program": "${workspaceRoot}", | ||
"args": [ | ||
"sentry" | ||
"cannon" | ||
], | ||
} | ||
] | ||
|
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 | ||
} |
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,9 @@ | ||
CREATE TABLE cannon_location ( | ||
location_id SERIAL PRIMARY KEY, | ||
create_time TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
update_time TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
network_id VARCHAR(256), | ||
type VARCHAR(256), | ||
value TEXT, | ||
CONSTRAINT cannon_location_unique UNIQUE (network_id, type) | ||
); |
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 @@ | ||
DROP TABLE IF EXISTS cannon_location; |
Oops, something went wrong.