diff --git a/cmd/nodecmd/wiz.go b/cmd/nodecmd/wiz.go index d6fe3b477..d50ccf5db 100644 --- a/cmd/nodecmd/wiz.go +++ b/cmd/nodecmd/wiz.go @@ -1021,6 +1021,7 @@ func addBlockchainToRelayerConf(network models.Network, cloudNodeID string, bloc configPath, logging.Info.LowerString(), app.GetAWMRelayerServiceStorageDir(storageBasePath), + constants.RemoteAWMRelayerMetricsPort, network, ); err != nil { return err diff --git a/cmd/teleportercmd/relayercmd/deploy.go b/cmd/teleportercmd/relayercmd/deploy.go index c67de4ebd..2ccc4fe8b 100644 --- a/cmd/teleportercmd/relayercmd/deploy.go +++ b/cmd/teleportercmd/relayercmd/deploy.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" + "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/contract" "github.com/ava-labs/avalanche-cli/pkg/evm" "github.com/ava-labs/avalanche-cli/pkg/localnet" @@ -39,6 +40,8 @@ var ( deployFlags DeployFlags ) +const disableDeployToRemotePrompt = true + // avalanche teleporter relayer deploy func newDeployCmd() *cobra.Command { cmd := &cobra.Command{ @@ -75,7 +78,7 @@ func CallDeploy(_ []string, flags DeployFlags) error { } deployToRemote := false - if network.Kind != models.Local { + if !disableDeployToRemotePrompt && network.Kind != models.Local { prompt := "Do you want to deploy the relayer to a remote or a local host?" remoteHostOption := "I want to deploy the relayer into a remote node in the cloud" localHostOption := "I prefer to deploy into a localhost process" @@ -331,10 +334,28 @@ func CallDeploy(_ []string, flags DeployFlags) error { configPath := app.GetLocalRelayerConfigPath(network.Kind, localNetworkRootDir) logPath := app.GetLocalRelayerLogPath(network.Kind) + metricsPort := constants.RemoteAWMRelayerMetricsPort + if !deployToRemote { + switch network.Kind { + case models.Local: + metricsPort = constants.LocalNetworkLocalAWMRelayerMetricsPort + case models.Devnet: + metricsPort = constants.DevnetLocalAWMRelayerMetricsPort + case models.Fuji: + metricsPort = constants.FujiLocalAWMRelayerMetricsPort + } + } + // create config ux.Logger.PrintToUser("") ux.Logger.PrintToUser("Generating relayer config file at %s", configPath) - if err := teleporter.CreateBaseRelayerConfig(configPath, logLevel, storageDir, network); err != nil { + if err := teleporter.CreateBaseRelayerConfig( + configPath, + logLevel, + storageDir, + uint16(metricsPort), + network, + ); err != nil { return err } for _, source := range configSpec.sources { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index f3b5df2a1..df572b316 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -261,7 +261,13 @@ const ( ICMKeyName = "cli-teleporter-deployer" AWMRelayerKeyName = "cli-awm-relayer" - AWMRelayerMetricsPort = 9091 + // to not interfere with other node services + RemoteAWMRelayerMetricsPort = 9091 + + // enables having many local relayers + LocalNetworkLocalAWMRelayerMetricsPort = 9091 + DevnetLocalAWMRelayerMetricsPort = 9092 + FujiLocalAWMRelayerMetricsPort = 9093 SubnetEVMBin = "subnet-evm" diff --git a/pkg/models/network.go b/pkg/models/network.go index 927b44476..08128c2fc 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -123,7 +123,14 @@ func (n Network) BlockchainWSEndpoint(blockchainID string) string { trimmedURI := n.Endpoint trimmedURI = strings.TrimPrefix(trimmedURI, "http://") trimmedURI = strings.TrimPrefix(trimmedURI, "https://") - return fmt.Sprintf("ws://%s/ext/bc/%s/ws", trimmedURI, blockchainID) + scheme := "ws" + switch n.Kind { + case Fuji: + scheme = "wss" + case Mainnet: + scheme = "wss" + } + return fmt.Sprintf("%s://%s/ext/bc/%s/ws", scheme, trimmedURI, blockchainID) } func (n Network) NetworkIDFlagValue() string { diff --git a/pkg/subnet/local.go b/pkg/subnet/local.go index d4190cac6..cd6efa2af 100644 --- a/pkg/subnet/local.go +++ b/pkg/subnet/local.go @@ -364,6 +364,7 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp relayerConfigPath, logging.Info.LowerString(), d.app.GetLocalRelayerStorageDir(models.Local), + constants.LocalNetworkLocalAWMRelayerMetricsPort, network, ); err != nil { return nil, err @@ -508,6 +509,10 @@ func (d *LocalDeployer) doDeploy(chain string, genesisPath string, icmSpec ICMSp d.app.GetLocalRelayerRunPath(models.Local), d.app.GetLocalRelayerStorageDir(models.Local), ); err != nil { + logPath := d.app.GetLocalRelayerLogPath(models.Local) + if bs, err := os.ReadFile(logPath); err == nil { + ux.Logger.PrintToUser(string(bs)) + } return nil, err } } diff --git a/pkg/teleporter/relayer.go b/pkg/teleporter/relayer.go index 631a10796..c56250218 100644 --- a/pkg/teleporter/relayer.go +++ b/pkg/teleporter/relayer.go @@ -324,6 +324,7 @@ func CreateBaseRelayerConfigIfMissing( relayerConfigPath string, logLevel string, storageLocation string, + metricsPort uint16, network models.Network, ) error { if !utils.FileExists(relayerConfigPath) { @@ -331,6 +332,7 @@ func CreateBaseRelayerConfigIfMissing( relayerConfigPath, logLevel, storageLocation, + metricsPort, network, ) } @@ -341,6 +343,7 @@ func CreateBaseRelayerConfig( relayerConfigPath string, logLevel string, storageLocation string, + metricsPort uint16, network models.Network, ) error { awmRelayerConfig := &config.Config{ @@ -357,7 +360,7 @@ func CreateBaseRelayerConfig( ProcessMissedBlocks: false, SourceBlockchains: []*config.SourceBlockchain{}, DestinationBlockchains: []*config.DestinationBlockchain{}, - MetricsPort: constants.AWMRelayerMetricsPort, + MetricsPort: metricsPort, } return saveRelayerConfig(awmRelayerConfig, relayerConfigPath) }