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

Validator Manager SDK #2297

Merged
merged 12 commits into from
Oct 31, 2024
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
64 changes: 44 additions & 20 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"
"time"

blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/network/peer"

Expand Down Expand Up @@ -484,7 +486,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}

if sidecar.Sovereign {
if !convertOnly && !generateNodeID {
if !generateNodeID {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why !convertOnly was removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./bin/avalanche blockchain deploy e2eSubnetTest --etna-devnet --use-local-machine --avalanchego-path=tests/e2e/assets/avalanchego --num-local-nodes=1 --ewoq --change-owner-address P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p --convert-only will ask for more prompts otherwise

clusterName := fmt.Sprintf("%s-local-node", blockchainName)
if globalNetworkFlags.ClusterName != "" {
clusterName = globalNetworkFlags.ClusterName
Expand Down Expand Up @@ -873,17 +875,35 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
ux.Logger.PrintToUser("Initializing Proof of Authority Validator Manager contract on blockchain %s ...", blockchainName)
if err := validatormanager.SetupPoA(
subnetID, err := contract.GetSubnetID(
app,
network,
rpcURL,
chainSpec,
genesisPrivateKey,
common.HexToAddress(sidecar.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
extraAggregatorPeers,
aggregatorLogLevel,
); err != nil {
)
if err != nil {
return err
}
blockchainID, err := contract.GetBlockchainID(
app,
network,
chainSpec,
)
if err != nil {
return err
}
ownerAddress := common.HexToAddress(sidecar.PoAValidatorManagerOwner)
subnetSDK := blockchainSDK.Subnet{
SubnetID: subnetID,
BlockchainID: blockchainID,
OwnerAddress: &ownerAddress,
RPC: rpcURL,
BootstrapValidators: avaGoBootstrapValidators,
}
logLvl, err := logging.ToLevel(aggregatorLogLevel)
if err != nil {
logLvl = logging.Off
}
if err := subnetSDK.InitializeProofOfAuthority(network, genesisPrivateKey, extraAggregatorPeers, logLvl); err != nil {
return err
}
ux.Logger.GreenCheckmarkToUser("Proof of Authority Validator Manager contract successfully initialized on blockchain %s", blockchainName)
Expand Down Expand Up @@ -1214,17 +1234,7 @@ func UrisToPeers(uris []string) ([]info.Peer, error) {
return peers, nil
}

func GetAggregatorExtraPeers(
network models.Network,
extraURIs []string,
) ([]info.Peer, error) {
uris, err := GetAggregatorNetworkUris(network)
if err != nil {
return nil, err
}
uris = append(uris, extraURIs...)
urisSet := set.Of(uris...)
uris = urisSet.List()
func ConvertURIToPeers(uris []string) ([]info.Peer, error) {
aggregatorPeers, err := UrisToPeers(uris)
if err != nil {
return nil, err
Expand All @@ -1251,6 +1261,20 @@ func GetAggregatorExtraPeers(
return aggregatorPeers, nil
}

func GetAggregatorExtraPeers(
network models.Network,
extraURIs []string,
) ([]info.Peer, error) {
uris, err := GetAggregatorNetworkUris(network)
if err != nil {
return nil, err
}
uris = append(uris, extraURIs...)
urisSet := set.Of(uris...)
uris = urisSet.List()
return ConvertURIToPeers(uris)
}

func GetAggregatorNetworkUris(network models.Network) ([]string, error) {
aggregatorExtraPeerEndpointsUris := []string{}
if network.ClusterName != "" {
Expand Down
30 changes: 25 additions & 5 deletions cmd/contractcmd/init_poa_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/prompts"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanche-cli/pkg/validatormanager"
blockchainSDK "github.com/ava-labs/avalanche-cli/sdk/blockchain"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ethereum/go-ethereum/common"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -124,14 +124,34 @@ func initPOAManager(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if err := validatormanager.SetupPoA(
subnetID, err := contract.GetSubnetID(
app,
network,
chainSpec,
)
if err != nil {
return err
}
blockchainID, err := contract.GetBlockchainID(
app,
network,
initPOAManagerFlags.rpcEndpoint,
chainSpec,
)
if err != nil {
return err
}
ownerAddress := common.HexToAddress(sc.PoAValidatorManagerOwner)
subnetSDK := blockchainSDK.Subnet{
SubnetID: subnetID,
BlockchainID: blockchainID,
BootstrapValidators: avaGoBootstrapValidators,
OwnerAddress: &ownerAddress,
RPC: initPOAManagerFlags.rpcEndpoint,
}
if err := validatormanager.SetupPoA(
subnetSDK,
network,
privateKey,
common.HexToAddress(sc.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
extraAggregatorPeers,
initPOAManagerFlags.aggregatorLogLevel,
); err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/ux/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func (us *UserSpinner) Stop() {

func (us *UserSpinner) SpinToUser(msg string, args ...interface{}) *ysmrr.Spinner {
formattedMsg := fmt.Sprintf(msg, args...)
Logger.log.Info(formattedMsg + " [Spinner Start]")
if Logger != nil {
Logger.log.Info(formattedMsg + " [Spinner Start]")
}
sp := us.spinner.AddSpinner(formattedMsg)
us.mutex.Lock()
if !us.started {
Expand All @@ -71,5 +73,7 @@ func SpinComplete(s *ysmrr.Spinner) {
return
}
s.Complete()
Logger.log.Info(s.GetMessage() + " [Spinner Complete]")
if Logger != nil {
Logger.log.Info(s.GetMessage() + " [Spinner Complete]")
}
}
Loading
Loading