Skip to content

Commit

Permalink
Validator removal (#2267)
Browse files Browse the repository at this point in the history
* node local init

* hardcode etna devnet config

* wip

* rm not needed utils

* ready for draft PR

* nits
rm unused struct

* refactor - wip

* make sure we can resume without prompts

* add custom network and local cluster

* devnet instead of custom network, rm custom

* go mod tidy

* upgrade.json for etna devnet

* more local cluster

* partial work

* separate between local network and local cluster

* working

* nit

* fix plugin

* nit

* improve snapshot management

* fix bug

* nit

* proper etna devnet boostrappers

* fix bug with local rootdir

* remove global node config stuff

* destroy node data and processes if bad start

* nit

* always use fresh staking keys

* nit

* so less flags

* add back fast boot time

* add checks for local cluster. minor refactor (#2239)

* add checks for local cluster
minor refactoring

* fix test

* addressed Felipe feedback

---------

Signed-off-by: arturrez <56270896+arturrez@users.noreply.github.com>

* bump anr

* fixes for convert flow

* add check for already initialized error on PoA init

* nit

* not to much further to have a complete flow

* ok esto esta funcionando

* started refactoring

* use relayer branch

* partial work

* use anr main

* working for devnets

* is this working

* working for local

* nit

* working

* bump anr

* initialization

* nit

* add last step

* split

* nit

* nit

* nit

* improval

* Fix merge

* Fix merge

* Fix merge

* nits

* lint

* fix merge

* add tracing function for tx on blockchain

* now I have control of logs

* added log level flag for aggregator

* improve err management a bit more

* working

* adjust weights

* nits

* nit

* nits

* lint

* nit

* nit

* nit

* lint

---------

Signed-off-by: arturrez <56270896+arturrez@users.noreply.github.com>
Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Co-authored-by: Artur Reznikov <artur.reznikov@avalabs.org>
Co-authored-by: arturrez <56270896+arturrez@users.noreply.github.com>
Co-authored-by: sukantoraymond <rsukanto@umich.edu>
  • Loading branch information
4 people authored Oct 17, 2024
1 parent 191f129 commit d517e5f
Show file tree
Hide file tree
Showing 21 changed files with 1,161 additions and 509 deletions.
17 changes: 7 additions & 10 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ var (
remainingBalanceOwnerAddr string
disableOwnerAddr string
rpcURL string
aggregatorLogLevel string

errNoSubnetID = errors.New("failed to find the subnet ID for this subnet, has it been deployed/created on this network?")
errMutuallyExclusiveDurationOptions = errors.New("--use-default-duration/--use-default-validator-params and --staking-period are mutually exclusive")
errMutuallyExclusiveStartOptions = errors.New("--use-default-start-time/--use-default-validator-params and --start-time are mutually exclusive")
errMutuallyExclusiveWeightOptions = errors.New("--use-default-validator-params and --weight are mutually exclusive")
ErrNotPermissionedSubnet = errors.New("subnet is not permissioned")
privateAggregatorEndpoints []string
aggregatorExtraEndpoints []string
)

// avalanche blockchain addValidator
Expand Down Expand Up @@ -97,9 +98,10 @@ Testnet or Mainnet.`,
cmd.Flags().StringVar(&remainingBalanceOwnerAddr, "remaining-balance-owner", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet")
cmd.Flags().StringVar(&disableOwnerAddr, "disable-owner", "", "P-Chain address that will able to disable the validator with a P-Chain transaction")
cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint")
cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
privateKeyFlags.AddToCmd(cmd, "to pay fees for completing the validator's registration (blockchain gas token)")
cmd.Flags().StringVar(&rpcURL, "rpc", "", "connect to validator manager at the given rpc endpoint")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", "Off", "log level to use with signature aggregator")
return cmd
}

Expand Down Expand Up @@ -322,17 +324,10 @@ func CallAddValidator(
Addresses: disableOwnerAddrID,
}

// given by users
extraAggregatorPeers, err := UrisToPeers(privateAggregatorEndpoints)
extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
if err != nil {
return err
}
// available in local cluster
networkAggregatorEndpoints, err := GetAggregatorExtraPeerEndpoints(network)
if err != nil {
return err
}
extraAggregatorPeers = append(extraAggregatorPeers, networkAggregatorEndpoints...)

signedMessage, validationID, err := validatormanager.InitValidatorRegistration(
app,
Expand All @@ -347,6 +342,7 @@ func CallAddValidator(
disableOwners,
weight,
extraAggregatorPeers,
aggregatorLogLevel,
)
if err != nil {
return err
Expand Down Expand Up @@ -375,6 +371,7 @@ func CallAddValidator(
privateKey,
validationID,
extraAggregatorPeers,
aggregatorLogLevel,
); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func setWeight(_ *cobra.Command, args []string) error {
deployer := subnet.NewPublicDeployer(app, kc, network)

// first remove the validator from subnet
err = removeValidatorSOV(deployer, network, subnetID, nodeID)
err = removeValidatorSOV(deployer, network, kc, blockchainName, nodeID)
if err != nil {
return err
}
Expand Down
49 changes: 40 additions & 9 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanche-cli/pkg/node"
avagoutils "github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
"github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -139,6 +141,8 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().BoolVar(&generateNodeID, "generate-node-id", false, "whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)")
cmd.Flags().StringSliceVar(&bootstrapEndpoints, "bootstrap-endpoints", nil, "take validator node info from the given endpoints")
cmd.Flags().BoolVar(&convertOnly, "convert-only", false, "avoid node track, restart and poa manager setup")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", "Off", "log level to use with signature aggregator")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().StringVar(&localMachineCluster, "local-machine-cluster", "", "existing local machine to be used as a blockchain validator")

Expand Down Expand Up @@ -515,7 +519,17 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
network = models.NewNetworkFromCluster(network, clusterName)
// anrSettings, avagoVersionSettings, globalNetworkFlags are empty
if err = node.StartLocalNode(app, clusterName, useEtnaDevnet, avagoBinaryPath, anrSettings, avagoVersionSettings, globalNetworkFlags, nil); err != nil {
if err = node.StartLocalNode(
app,
clusterName,
useEtnaDevnet,
avagoBinaryPath,
1,
anrSettings,
avagoVersionSettings,
globalNetworkFlags,
nil,
); err != nil {
return err
}
}
Expand Down Expand Up @@ -828,7 +842,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
evm.WaitForChainID(client)
privateAggregatorEndpoints, err := GetAggregatorExtraPeerEndpoints(network)
extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
if err != nil {
return err
}
Expand All @@ -841,7 +855,8 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
genesisPrivateKey,
common.HexToAddress(sidecar.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
privateAggregatorEndpoints,
extraAggregatorPeers,
aggregatorLogLevel,
); err != nil {
return err
}
Expand Down Expand Up @@ -915,6 +930,7 @@ func ConvertToAvalancheGoSubnetValidator(subnetValidators []models.SubnetValidat
}
bootstrapValidators = append(bootstrapValidators, bootstrapValidator)
}
avagoutils.Sort(bootstrapValidators)
return bootstrapValidators, nil
}

Expand Down Expand Up @@ -1139,29 +1155,44 @@ func UrisToPeers(uris []string) ([]info.Peer, error) {
return peers, nil
}

func GetAggregatorExtraPeerEndpoints(network models.Network) ([]info.Peer, error) {
aggregatorExtraPeerEndpointsUris, err := GetAggregatorExtraPeerEndpointsUris(network)
func GetAggregatorExtraPeers(
network models.Network,
extraURIs []string,
) ([]info.Peer, error) {
uris, err := GetAggregatorNetworkUris(network)
if err != nil {
return nil, err
}
aggregatorPeers, err := UrisToPeers(aggregatorExtraPeerEndpointsUris)
uris = append(uris, extraURIs...)
urisSet := set.Of(uris...)
uris = urisSet.List()
aggregatorPeers, err := UrisToPeers(uris)
if err != nil {
return nil, err
}
for _, uri := range aggregatorExtraPeerEndpointsUris {
nodeIDs := utils.Map(aggregatorPeers, func(peer info.Peer) ids.NodeID {
return peer.Info.ID
})
nodeIDsSet := set.Of(nodeIDs...)
for _, uri := range uris {
infoClient := info.NewClient(uri)
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
peers, err := infoClient.Peers(ctx)
if err != nil {
return nil, err
}
aggregatorPeers = append(aggregatorPeers, peers...)
for _, peer := range peers {
if !nodeIDsSet.Contains(peer.Info.ID) {
aggregatorPeers = append(aggregatorPeers, peer)
nodeIDsSet.Add(peer.Info.ID)
}
}
}
return aggregatorPeers, nil
}

func GetAggregatorExtraPeerEndpointsUris(network models.Network) ([]string, error) {
func GetAggregatorNetworkUris(network models.Network) ([]string, error) {
aggregatorExtraPeerEndpointsUris := []string{}
if network.ClusterName != "" {
clustersConfig, err := app.LoadClustersConfig()
Expand Down
Loading

0 comments on commit d517e5f

Please sign in to comment.