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

Filter network #2356

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 20 additions & 5 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
networkoptions.Devnet,
networkoptions.Fuji,
networkoptions.Mainnet,
networkoptions.EtnaDevnet,
}

nodeIDStr string
Expand Down Expand Up @@ -128,18 +129,36 @@ func addValidator(_ *cobra.Command, args []string) error {
return err
}

sc, err := app.LoadSidecar(blockchainName)
arturrez marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("failed to load sidecar: %w", err)
}

networkOptionsList := []networkoptions.NetworkOption{}
for scNetwork := range sc.Networks {
if networkoptions.NetworkOptionFromString(scNetwork) != networkoptions.Undefined {
networkOptionsList = append(networkOptionsList, networkoptions.NetworkOptionFromString(scNetwork))
}
}

// default network options to add validator options
if len(networkOptionsList) == 0 {
networkOptionsList = addValidatorSupportedNetworkOptions
}

network, err := networkoptions.GetNetworkFromCmdLineFlags(
app,
"",
globalNetworkFlags,
true,
false,
addValidatorSupportedNetworkOptions,
networkOptionsList,
"",
)
if err != nil {
return err
}

if network.ClusterName != "" {
clusterNameFlagValue = network.ClusterName
network = models.ConvertClusterToNetwork(network)
Expand Down Expand Up @@ -183,10 +202,6 @@ func addValidator(_ *cobra.Command, args []string) error {
return err
}

sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return fmt.Errorf("failed to load sidecar: %w", err)
}
sovereign := sc.Sovereign

if sovereign && network.Kind == models.Mainnet {
Expand Down
24 changes: 18 additions & 6 deletions cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,36 @@ func setWeight(_ *cobra.Command, args []string) error {
return err
}

sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return fmt.Errorf("failed to load sidecar: %w", err)
}

networkOptionsList := []networkoptions.NetworkOption{}
for scNetwork := range sc.Networks {
if networkoptions.NetworkOptionFromString(scNetwork) != networkoptions.Undefined {
networkOptionsList = append(networkOptionsList, networkoptions.NetworkOptionFromString(scNetwork))
}
}

// default network options to remove validator options
if len(networkOptionsList) == 0 {
networkOptionsList = removeValidatorSupportedNetworkOptions
}

network, err := networkoptions.GetNetworkFromCmdLineFlags(
app,
"",
globalNetworkFlags,
true,
false,
removeValidatorSupportedNetworkOptions,
networkOptionsList,
"",
)
if err != nil {
return err
}

sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return err
}

if network.Kind == models.Mainnet && sc.Sovereign {
return errNotSupportedOnMainnet
}
Expand Down
25 changes: 19 additions & 6 deletions cmd/blockchaincmd/remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var removeValidatorSupportedNetworkOptions = []networkoptions.NetworkOption{
networkoptions.Devnet,
networkoptions.Fuji,
networkoptions.Mainnet,
networkoptions.EtnaDevnet,
}

// avalanche blockchain removeValidator
Expand Down Expand Up @@ -70,13 +71,30 @@ func removeValidator(_ *cobra.Command, args []string) error {
return err
}

sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return err
}

networkOptionsList := []networkoptions.NetworkOption{}
for scNetwork := range sc.Networks {
if networkoptions.NetworkOptionFromString(scNetwork) != networkoptions.Undefined {
networkOptionsList = append(networkOptionsList, networkoptions.NetworkOptionFromString(scNetwork))
}
}

// default network options to remove validator options
if len(networkOptionsList) == 0 {
networkOptionsList = removeValidatorSupportedNetworkOptions
}

network, err := networkoptions.GetNetworkFromCmdLineFlags(
app,
"",
globalNetworkFlags,
true,
false,
removeValidatorSupportedNetworkOptions,
networkOptionsList,
"",
)
if err != nil {
Expand All @@ -101,11 +119,6 @@ func removeValidator(_ *cobra.Command, args []string) error {
}
network.HandlePublicNetworkSimulation()

sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return err
}

if sc.Sovereign && network.Kind == models.Mainnet {
return errNotSupportedOnMainnet
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/networkoptions/network_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func NetworkOptionFromString(s string) NetworkOption {
return Devnet
case "Cluster":
return Cluster
default:
if strings.Contains(s, "Devnet") {
arturrez marked this conversation as resolved.
Show resolved Hide resolved
return Devnet
} else if strings.Contains(s, "Cluster") {
arturrez marked this conversation as resolved.
Show resolved Hide resolved
return Cluster
}
sukantoraymond marked this conversation as resolved.
Show resolved Hide resolved
}
return Undefined
}
Expand Down
Loading