Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable non mainline networks #24

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/sentry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,18 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
// Apply environment variables first, then override with CLI flags if set
if network := os.Getenv("CONTRIBUTOOR_NETWORK"); network != "" {
log.Infof("Setting network from env to %s", network)
cfg.SetNetwork(network)

if err := cfg.SetNetwork(network); err != nil {
return errors.Wrap(err, "failed to set network from env")
}
}

if c.String("network") != "" {
log.Infof("Overriding network from CLI to %s", c.String("network"))
cfg.SetNetwork(c.String("network"))

if err := cfg.SetNetwork(c.String("network")); err != nil {
return errors.Wrap(err, "failed to set network from cli")
}
}

if addr := os.Getenv("CONTRIBUTOOR_BEACON_NODE_ADDRESS"); addr != "" {
Expand Down
8 changes: 6 additions & 2 deletions cmd/sentry/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,12 @@ func TestConfigOverridePrecedence(t *testing.T) {
expectedValue: "holesky",
envVar: "CONTRIBUTOOR_NETWORK",
cliFlag: "network",
setter: func(c *config.Config, v string) { c.SetNetwork(v) },
getter: func(c *config.Config) string { return strings.ToLower(c.NetworkName.DisplayName()) },
setter: func(c *config.Config, v string) {
if err := c.SetNetwork(v); err != nil {
t.Fatalf("failed to set network: %v", err)
}
},
getter: func(c *config.Config) string { return strings.ToLower(c.NetworkName.DisplayName()) },
},
{
name: "Env overrides config but not CLI - beacon node",
Expand Down
10 changes: 8 additions & 2 deletions pkg/config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package config

import (
"encoding/json"
"errors"
"fmt"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -164,9 +166,9 @@ func (c *Config) GetHealthCheckHostPort() (host, port string) {
}

// SetNetwork sets the network name.
func (c *Config) SetNetwork(network string) {
func (c *Config) SetNetwork(network string) error {
if network == "" {
return
return errors.New("network is required")
}

switch strings.ToLower(network) {
Expand All @@ -176,7 +178,11 @@ func (c *Config) SetNetwork(network string) {
c.NetworkName = NetworkName_NETWORK_NAME_SEPOLIA
case "holesky":
c.NetworkName = NetworkName_NETWORK_NAME_HOLESKY
default:
return fmt.Errorf("invalid network: %s", network)
}

return nil
}

// SetBeaconNodeAddress sets the beacon node address.
Expand Down