Skip to content

Commit 690e734

Browse files
authored
Start stop relayer (#1631)
* add network options with cluster + teleporter deploy cmd * fix e2e v1 * point to correct branch * increase time of cli setup from source for e2e * force 10 min cli setup from source if e2e * lint * add basic relayer commands * partial work * awm relayer host selection working * nits * add cchain teleporter info to cluster * nits * nits * partial work * nits * almost * relayer working * nits * all good except receipt * add -y flag to node destroy * nit * add clusters to key list network options * add flag to key list to have a shortest way to specify chains to show info about * add tx hash for failed msg at destination * partial work * bump golang * add trace to teleporter msg is receipt status is wrong * enable first creating a subnet then creating a blockchain * improve add subnet validators speed * nit * seems pretty well * seems pretty weel * add proposer vm setup simil teleporter e2e * just create subnet/blockchain on one subnet deploy * working! * nit * nit * nit * nit * subnet join to not fail if blockchain was not deployed yet * local stop almost working * nit * start accessing node related functions from teleportercmd * basic remote start/stop without check for process status * add node lib * disable cli setup from source * nit * nit * lint * address PR comments * addres PR comments
1 parent 15d0746 commit 690e734

File tree

6 files changed

+259
-57
lines changed

6 files changed

+259
-57
lines changed

cmd/nodecmd/wiz.go

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/ava-labs/avalanche-cli/pkg/constants"
1616
"github.com/ava-labs/avalanche-cli/pkg/models"
1717
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
18+
"github.com/ava-labs/avalanche-cli/pkg/node"
1819
"github.com/ava-labs/avalanche-cli/pkg/ssh"
1920
"github.com/ava-labs/avalanche-cli/pkg/subnet"
2021
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
@@ -268,7 +269,7 @@ func wiz(cmd *cobra.Command, args []string) error {
268269
var awmRelayerHost *models.Host
269270
if sc.TeleporterReady && sc.RunRelayer && isEVMGenesis {
270271
// get or set AWM Relayer host and configure/stop service
271-
awmRelayerHost, err = getAWMRelayerHost(clusterName)
272+
awmRelayerHost, err = node.GetAWMRelayerHost(app, clusterName)
272273
if err != nil {
273274
return err
274275
}
@@ -488,31 +489,10 @@ func updateProposerVMs(
488489
return teleporter.SetProposerVM(app, network, "C", "")
489490
}
490491

491-
func getHostWithCloudID(clusterName string, cloudID string) (*models.Host, error) {
492-
hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName))
493-
if err != nil {
494-
return nil, err
495-
}
496-
monitoringInventoryFile := app.GetMonitoringInventoryDir(clusterName)
497-
if utils.FileExists(monitoringInventoryFile) {
498-
monitoringHosts, err := ansible.GetInventoryFromAnsibleInventoryFile(monitoringInventoryFile)
499-
if err != nil {
500-
return nil, err
501-
}
502-
hosts = append(hosts, monitoringHosts...)
503-
}
504-
for _, host := range hosts {
505-
if host.GetCloudID() == cloudID {
506-
return host, nil
507-
}
508-
}
509-
return nil, nil
510-
}
511-
512492
func setAWMRelayerHost(host *models.Host) error {
513493
cloudID := host.GetCloudID()
514494
ux.Logger.PrintToUser("")
515-
ux.Logger.PrintToUser("configuring AWM Relayer on host %s", cloudID)
495+
ux.Logger.PrintToUser("configuring AWM RElayer on host %s", cloudID)
516496
nodeConfig, err := app.LoadClusterNodeConfig(cloudID)
517497
if err != nil {
518498
return err
@@ -541,24 +521,6 @@ func updateAWMRelayerHostConfig(host *models.Host, subnetName string, clusterNam
541521
return ssh.RunSSHStartAWMRelayerService(host)
542522
}
543523

544-
func getAWMRelayerHost(clusterName string) (*models.Host, error) {
545-
clusterConfig, err := app.GetClusterConfig(clusterName)
546-
if err != nil {
547-
return nil, err
548-
}
549-
relayerCloudID := ""
550-
for _, cloudID := range clusterConfig.GetCloudIDs() {
551-
nodeConfig, err := app.LoadClusterNodeConfig(cloudID)
552-
if err != nil {
553-
return nil, err
554-
}
555-
if nodeConfig.IsAWMRelayer {
556-
relayerCloudID = nodeConfig.NodeID
557-
}
558-
}
559-
return getHostWithCloudID(clusterName, relayerCloudID)
560-
}
561-
562524
func chooseAWMRelayerHost(clusterName string) (*models.Host, error) {
563525
// first look up for separate monitoring host
564526
monitoringInventoryFile := app.GetMonitoringInventoryDir(clusterName)
@@ -577,11 +539,11 @@ func chooseAWMRelayerHost(clusterName string) (*models.Host, error) {
577539
return nil, err
578540
}
579541
if len(clusterConfig.APINodes) > 0 {
580-
return getHostWithCloudID(clusterName, clusterConfig.APINodes[0])
542+
return node.GetHostWithCloudID(app, clusterName, clusterConfig.APINodes[0])
581543
}
582544
// finally go for other hosts
583545
if len(clusterConfig.Nodes) > 0 {
584-
return getHostWithCloudID(clusterName, clusterConfig.Nodes[0])
546+
return node.GetHostWithCloudID(app, clusterName, clusterConfig.Nodes[0])
585547
}
586548
return nil, fmt.Errorf("no hosts found on cluster")
587549
}

cmd/teleportercmd/relayer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ and configuring an AWM relayer on localhost.`,
2424
}
2525
cmd.AddCommand(newPrepareRelayerServiceCmd())
2626
cmd.AddCommand(newAddSubnetToRelayerServiceCmd())
27+
cmd.AddCommand(newStopRelayerCmd())
28+
cmd.AddCommand(newStartRelayerCmd())
2729
return cmd
2830
}

cmd/teleportercmd/startRelayer.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
package teleportercmd
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/ava-labs/avalanche-cli/pkg/models"
9+
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
10+
"github.com/ava-labs/avalanche-cli/pkg/node"
11+
"github.com/ava-labs/avalanche-cli/pkg/ssh"
12+
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
13+
"github.com/ava-labs/avalanche-cli/pkg/ux"
14+
15+
"github.com/spf13/cobra"
16+
)
17+
18+
var startRelayerNetworkOptions = []networkoptions.NetworkOption{networkoptions.Local, networkoptions.Cluster}
19+
20+
// avalanche teleporter relayer start
21+
func newStartRelayerCmd() *cobra.Command {
22+
cmd := &cobra.Command{
23+
Use: "start",
24+
Short: "starts AWM relayer",
25+
Long: `Starts AWM relayer on the specified network (Currently only for local network).`,
26+
SilenceUsage: true,
27+
RunE: startRelayer,
28+
Args: cobra.ExactArgs(0),
29+
}
30+
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, startRelayerNetworkOptions)
31+
return cmd
32+
}
33+
34+
func startRelayer(_ *cobra.Command, _ []string) error {
35+
network, err := networkoptions.GetNetworkFromCmdLineFlags(
36+
app,
37+
globalNetworkFlags,
38+
false,
39+
startRelayerNetworkOptions,
40+
"",
41+
)
42+
if err != nil {
43+
return err
44+
}
45+
switch {
46+
case network.Kind == models.Local:
47+
if relayerIsUp, _, _, err := teleporter.RelayerIsUp(
48+
app.GetAWMRelayerRunPath(),
49+
); err != nil {
50+
return err
51+
} else if relayerIsUp {
52+
return fmt.Errorf("local AWM relayer is already running")
53+
}
54+
if err := teleporter.DeployRelayer(
55+
app.GetAWMRelayerBinDir(),
56+
app.GetAWMRelayerConfigPath(),
57+
app.GetAWMRelayerLogPath(),
58+
app.GetAWMRelayerRunPath(),
59+
app.GetAWMRelayerStorageDir(),
60+
); err != nil {
61+
return err
62+
}
63+
ux.Logger.GreenCheckmarkToUser("Local AWM Relayer successfully started")
64+
ux.Logger.PrintToUser("Logs can be found at %s", app.GetAWMRelayerLogPath())
65+
case network.ClusterName != "":
66+
host, err := node.GetAWMRelayerHost(app, network.ClusterName)
67+
if err != nil {
68+
return err
69+
}
70+
if err := ssh.RunSSHStartAWMRelayerService(host); err != nil {
71+
return err
72+
}
73+
ux.Logger.GreenCheckmarkToUser("Remote AWM Relayer on %s successfully started", host.GetCloudID())
74+
}
75+
return nil
76+
}

cmd/teleportercmd/stopRelayer.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
package teleportercmd
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/ava-labs/avalanche-cli/pkg/models"
9+
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
10+
"github.com/ava-labs/avalanche-cli/pkg/node"
11+
"github.com/ava-labs/avalanche-cli/pkg/ssh"
12+
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
13+
"github.com/ava-labs/avalanche-cli/pkg/ux"
14+
15+
"github.com/spf13/cobra"
16+
)
17+
18+
var stopRelayerNetworkOptions = []networkoptions.NetworkOption{networkoptions.Local, networkoptions.Cluster}
19+
20+
// avalanche teleporter relayer stop
21+
func newStopRelayerCmd() *cobra.Command {
22+
cmd := &cobra.Command{
23+
Use: "stop",
24+
Short: "stops AWM relayer",
25+
Long: `Stops AWM relayer on the specified network (Currently only for local network, cluster).`,
26+
SilenceUsage: true,
27+
RunE: stopRelayer,
28+
Args: cobra.ExactArgs(0),
29+
}
30+
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, stopRelayerNetworkOptions)
31+
return cmd
32+
}
33+
34+
func stopRelayer(_ *cobra.Command, _ []string) error {
35+
network, err := networkoptions.GetNetworkFromCmdLineFlags(
36+
app,
37+
globalNetworkFlags,
38+
false,
39+
stopRelayerNetworkOptions,
40+
"",
41+
)
42+
if err != nil {
43+
return err
44+
}
45+
switch {
46+
case network.Kind == models.Local:
47+
b, _, _, err := teleporter.RelayerIsUp(
48+
app.GetAWMRelayerRunPath(),
49+
)
50+
if err != nil {
51+
return err
52+
}
53+
if !b {
54+
return fmt.Errorf("there is no CLI-managed local AWM relayer running")
55+
}
56+
if err := teleporter.RelayerCleanup(
57+
app.GetAWMRelayerRunPath(),
58+
app.GetAWMRelayerStorageDir(),
59+
); err != nil {
60+
return err
61+
}
62+
ux.Logger.GreenCheckmarkToUser("Local AWM Relayer successfully stopped")
63+
case network.ClusterName != "":
64+
host, err := node.GetAWMRelayerHost(app, network.ClusterName)
65+
if err != nil {
66+
return err
67+
}
68+
if err := ssh.RunSSHStopAWMRelayerService(host); err != nil {
69+
return err
70+
}
71+
ux.Logger.GreenCheckmarkToUser("Remote AWM Relayer on %s successfully stopped", host.GetCloudID())
72+
}
73+
return nil
74+
}

pkg/node/node.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
package node
4+
5+
import (
6+
"github.com/ava-labs/avalanche-cli/pkg/ansible"
7+
"github.com/ava-labs/avalanche-cli/pkg/application"
8+
"github.com/ava-labs/avalanche-cli/pkg/models"
9+
"github.com/ava-labs/avalanche-cli/pkg/utils"
10+
)
11+
12+
func GetHostWithCloudID(app *application.Avalanche, clusterName string, cloudID string) (*models.Host, error) {
13+
hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName))
14+
if err != nil {
15+
return nil, err
16+
}
17+
monitoringInventoryFile := app.GetMonitoringInventoryDir(clusterName)
18+
if utils.FileExists(monitoringInventoryFile) {
19+
monitoringHosts, err := ansible.GetInventoryFromAnsibleInventoryFile(monitoringInventoryFile)
20+
if err != nil {
21+
return nil, err
22+
}
23+
hosts = append(hosts, monitoringHosts...)
24+
}
25+
for _, host := range hosts {
26+
if host.GetCloudID() == cloudID {
27+
return host, nil
28+
}
29+
}
30+
return nil, nil
31+
}
32+
33+
func GetAWMRelayerHost(app *application.Avalanche, clusterName string) (*models.Host, error) {
34+
clusterConfig, err := app.GetClusterConfig(clusterName)
35+
if err != nil {
36+
return nil, err
37+
}
38+
relayerCloudID := ""
39+
for _, cloudID := range clusterConfig.GetCloudIDs() {
40+
if nodeConfig, err := app.LoadClusterNodeConfig(cloudID); err != nil {
41+
return nil, err
42+
} else if nodeConfig.IsAWMRelayer {
43+
relayerCloudID = nodeConfig.NodeID
44+
}
45+
}
46+
return GetHostWithCloudID(app, clusterName, relayerCloudID)
47+
}

0 commit comments

Comments
 (0)