Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 7, 2023
1 parent 2a42e97 commit a10c62b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ func WithGlobalNodeConfig(nodeConfig string) OpOption {
}
}

func WithNetworkID(networkId uint32) OpOption {
func WithNetworkID(networkID uint32) OpOption {
return func(op *Op) {
op.networkID = networkId
op.networkID = networkID
}
}

Expand Down
9 changes: 3 additions & 6 deletions cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
subnetConfigs string
reassignPortsIfUsed bool
dynamicPorts bool
networkId uint32
networkID uint32
)

func setLogs() error {
Expand Down Expand Up @@ -178,7 +178,7 @@ func newStartCommand() *cobra.Command {
"avalanchego binary path",
)
cmd.PersistentFlags().Uint32Var(
&networkId,
&networkID,
"network-id",
0,
"network id to assign to the network",
Expand Down Expand Up @@ -272,10 +272,7 @@ func startFunc(*cobra.Command, []string) error {
client.WithRootDataDir(rootDataDir),
client.WithReassignPortsIfUsed(reassignPortsIfUsed),
client.WithDynamicPorts(dynamicPorts),
}

if networkId != 0 {
opts = append(opts, client.WithNetworkID(networkId))
client.WithNetworkID(networkID),
}

if globalNodeConfig != "" {
Expand Down
14 changes: 10 additions & 4 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ava-labs/avalanchego/network/peer"
"github.com/ava-labs/avalanchego/staking"
"github.com/ava-labs/avalanchego/utils/beacon"
avagoconstants "github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/ips"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -445,13 +446,18 @@ func (ln *localNetwork) loadConfig(ctx context.Context, networkConfig network.Co
ln.genesis = []byte(networkConfig.Genesis)

// Set network ID
ln.networkID = constants.DefaultNetworkID
var err error
ln.networkID, err = utils.NetworkIDFromGenesis(ln.genesis)
if err != nil {
return err
}
if networkConfig.NetworkID != 0 {
if networkConfig.NetworkID < 11 {
return fmt.Errorf("network IDs < 11 are reserved ones")
}
ln.networkID = networkConfig.NetworkID
}
switch ln.networkID {
case avagoconstants.TestnetID, avagoconstants.MainnetID:
return errors.New("network ID can't be mainnet or testnet")
}
genesis, err := utils.SetGenesisNetworkID(ln.genesis, ln.networkID)
if err != nil {
return fmt.Errorf("couldn't set network ID to genesis: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func (c *Config) Validate() error {
if err != nil {
return fmt.Errorf("couldn't get network ID from genesis: %w", err)
}
if c.NetworkID != 0 {
networkID = c.NetworkID
}

var someNodeIsBeacon bool
for i, nodeConfig := range c.NodeConfigs {
Expand Down
5 changes: 1 addition & 4 deletions utils/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const (
DefaultExecPathEnvVar = "AVALANCHEGO_EXEC_PATH"
DefaultPluginDirEnvVar = "AVALANCHEGO_PLUGIN_PATH"
LocalGenesisFile = "genesis.json"
DefaultNetworkID = uint32(1337)
)

var (
LocalConfigDir = filepath.Join("local", "default")
)
var LocalConfigDir = filepath.Join("local", "default")
7 changes: 4 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const (
)

var (
ErrEmptyExecPath = errors.New("avalanche exec is not defined")
ErrNotExists = errors.New("avalanche exec not exists")
ErrNotExistsPlugin = errors.New("plugin exec not exists")
ErrEmptyExecPath = errors.New("avalanche exec is not defined")
ErrNotExists = errors.New("avalanche exec not exists")
ErrNotExistsPlugin = errors.New("plugin exec not exists")
ErrorNoNetworkIDKey = fmt.Errorf("couldn't find key %q in genesis", genesisNetworkIDKey)
)

func ToNodeID(stakingKey, stakingCert []byte) (ids.NodeID, error) {
Expand Down

0 comments on commit a10c62b

Please sign in to comment.