-
Notifications
You must be signed in to change notification settings - Fork 80
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
Integrate local machine into subnet deploy #2235
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7175e30
one command
sukantoraymond 151e1a9
1 command sync local
sukantoraymond 32ef65c
1 command
sukantoraymond 0e7067c
fix lint
sukantoraymond 23a76bc
Merge branch 'node-create-local' into integrate-local-devnet
sukantoraymond 8b7f331
wait for healthy local
sukantoraymond 6614449
wait for healthy local
sukantoraymond 6217d99
fix lint
sukantoraymond 54479df
address comments
sukantoraymond 3dfad06
remove err
sukantoraymond 084018f
Merge branch 'node-create-local' into integrate-local-devnet
sukantoraymond 50986b7
Merge branch 'node-create-local' into integrate-local-devnet
sukantoraymond 2c56e09
fix merge
sukantoraymond 84e8ab5
update sidecar legacy
sukantoraymond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
"os" | ||
"path/filepath" | ||
|
||
"github.com/ava-labs/avalanche-cli/pkg/node" | ||
|
||
"github.com/ava-labs/avalanche-cli/pkg/binutils" | ||
"github.com/ava-labs/avalanche-cli/pkg/cobrautils" | ||
"github.com/ava-labs/avalanche-cli/pkg/constants" | ||
|
@@ -17,10 +19,7 @@ | |
"github.com/ava-labs/avalanche-cli/pkg/utils" | ||
"github.com/ava-labs/avalanche-cli/pkg/ux" | ||
"github.com/ava-labs/avalanche-network-runner/client" | ||
anrutils "github.com/ava-labs/avalanche-network-runner/utils" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -205,6 +204,14 @@ | |
} | ||
} | ||
serverLogPath := filepath.Join(rootDir, "server.log") | ||
// make sure rootDir exists | ||
if err := os.MkdirAll(rootDir, 0o700); err != nil { | ||
return fmt.Errorf("could not create root directory %s: %w", rootDir, err) | ||
} | ||
// make sure pluginDir exists | ||
if err := os.MkdirAll(pluginDir, 0o700); err != nil { | ||
return fmt.Errorf("could not create plugin directory %s: %w", pluginDir, err) | ||
} | ||
sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") | ||
if err := sd.StartServer( | ||
constants.ServerRunFileLocalClusterPrefix, | ||
|
@@ -350,7 +357,7 @@ | |
spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") | ||
if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { | ||
ux.SpinFailWithError(spinner, "", err) | ||
localDestroyNode(nil, []string{clusterName}) | ||
return fmt.Errorf("failed to start local avalanchego: %w", err) | ||
} | ||
ux.SpinComplete(spinner) | ||
|
@@ -414,14 +421,14 @@ | |
func localDestroyNode(_ *cobra.Command, args []string) error { | ||
clusterName := args[0] | ||
|
||
localStopNode(nil, nil) | ||
|
||
rootDir := app.GetLocalDir(clusterName) | ||
if err := os.RemoveAll(rootDir); err != nil { | ||
return err | ||
} | ||
|
||
if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { | ||
if ok, err := node.CheckClusterIsLocal(app, clusterName); err != nil || !ok { | ||
return fmt.Errorf("local cluster %q not found", clusterName) | ||
} | ||
|
||
|
@@ -451,118 +458,13 @@ | |
return app.WriteClustersConfigFile(&clustersConfig) | ||
} | ||
|
||
func checkClusterIsLocal(clusterName string) (bool, error) { | ||
clustersConfig, err := app.GetClustersConfig() | ||
if err != nil { | ||
return false, err | ||
} | ||
clusterConf, ok := clustersConfig.Clusters[clusterName] | ||
return ok && clusterConf.Local, nil | ||
} | ||
|
||
func localTrack(_ *cobra.Command, args []string) error { | ||
clusterName := args[0] | ||
blockchainName := args[1] | ||
if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { | ||
return fmt.Errorf("local node %q is not found", clusterName) | ||
} | ||
sc, err := app.LoadSidecar(blockchainName) | ||
if err != nil { | ||
return err | ||
} | ||
clustersConfig, err := app.LoadClustersConfig() | ||
if err != nil { | ||
return err | ||
} | ||
clusterConfig := clustersConfig.Clusters[clusterName] | ||
network := clusterConfig.Network | ||
if sc.Networks[network.Name()].BlockchainID == ids.Empty { | ||
return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) | ||
} | ||
subnetID := sc.Networks[network.Name()].SubnetID | ||
blockchainID := sc.Networks[network.Name()].BlockchainID | ||
vmID, err := anrutils.VMID(blockchainName) | ||
if err != nil { | ||
return fmt.Errorf("failed to create VM ID from %s: %w", blockchainName, err) | ||
} | ||
var vmBin string | ||
switch sc.VM { | ||
case models.SubnetEvm: | ||
_, vmBin, err = binutils.SetupSubnetEVM(app, sc.VMVersion) | ||
if err != nil { | ||
return fmt.Errorf("failed to install subnet-evm: %w", err) | ||
} | ||
case models.CustomVM: | ||
vmBin = binutils.SetupCustomBin(app, blockchainName) | ||
default: | ||
return fmt.Errorf("unknown vm: %s", sc.VM) | ||
} | ||
rootDir := app.GetLocalDir(clusterName) | ||
pluginPath := filepath.Join(rootDir, "node1", "plugins", vmID.String()) | ||
if err := utils.FileCopy(vmBin, pluginPath); err != nil { | ||
return err | ||
} | ||
if err := os.Chmod(pluginPath, constants.DefaultPerms755); err != nil { | ||
return err | ||
} | ||
if app.ChainConfigExists(blockchainName) { | ||
inputChainConfigPath := app.GetChainConfigPath(blockchainName) | ||
outputChainConfigPath := filepath.Join(rootDir, "node1", "configs", "chains", blockchainID.String(), "config.json") | ||
if err := os.MkdirAll(filepath.Dir(outputChainConfigPath), 0o700); err != nil { | ||
return fmt.Errorf("could not create chain conf directory %s: %w", filepath.Dir(outputChainConfigPath), err) | ||
} | ||
if err := utils.FileCopy(inputChainConfigPath, outputChainConfigPath); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
cli, err := binutils.NewGRPCClientWithEndpoint( | ||
binutils.LocalClusterGRPCServerEndpoint, | ||
binutils.WithAvoidRPCVersionCheck(true), | ||
binutils.WithDialTimeout(constants.FastGRPCDialTimeout), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
ctx, cancel := utils.GetANRContext() | ||
defer cancel() | ||
status, err := cli.Status(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
publicEndpoints := []string{} | ||
for _, nodeInfo := range status.ClusterInfo.NodeInfos { | ||
if _, err := cli.RestartNode(ctx, nodeInfo.Name, client.WithWhitelistedSubnets(subnetID.String())); err != nil { | ||
return err | ||
} | ||
publicEndpoints = append(publicEndpoints, nodeInfo.Uri) | ||
} | ||
networkInfo := sc.Networks[network.Name()] | ||
rpcEndpoints := set.Of(networkInfo.RPCEndpoints...) | ||
wsEndpoints := set.Of(networkInfo.WSEndpoints...) | ||
for _, publicEndpoint := range publicEndpoints { | ||
rpcEndpoints.Add(getRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) | ||
wsEndpoints.Add(getWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) | ||
} | ||
networkInfo.RPCEndpoints = rpcEndpoints.List() | ||
networkInfo.WSEndpoints = wsEndpoints.List() | ||
sc.Networks[clusterConfig.Network.Name()] = networkInfo | ||
if err := app.UpdateSidecar(&sc); err != nil { | ||
return err | ||
} | ||
ux.Logger.GreenCheckmarkToUser("%s successfully tracking %s", clusterName, blockchainName) | ||
return nil | ||
return node.TrackSubnetWithLocalMachine(app, clusterName, blockchainName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure it is the moment to move this to node pgk. we keep a part of logic here and a part in node. |
||
} | ||
|
||
func notImplementedForLocal(what string) error { | ||
ux.Logger.PrintToUser("Unsupported cmd: %s is not supported by local clusters", logging.LightBlue.Wrap(what)) | ||
return nil | ||
} | ||
|
||
func getRPCEndpoint(endpoint string, blockchainID string) string { | ||
return models.NewDevnetNetwork(endpoint, 0).BlockchainEndpoint(blockchainID) | ||
} | ||
|
||
func getWSEndpoint(endpoint string, blockchainID string) string { | ||
return models.NewDevnetNetwork(endpoint, 0).BlockchainWSEndpoint(blockchainID) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cluster name to be taken from the input network itself IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which should be a cluster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
models.Networks has ClusterName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2244
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to do it when integrating local node start