Skip to content

Commit

Permalink
use wss for fuji (#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero authored Sep 10, 2024
1 parent 954ed3b commit 8bfe436
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/nodecmd/wiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions cmd/teleportercmd/relayercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -39,6 +40,8 @@ var (
deployFlags DeployFlags
)

const disableDeployToRemotePrompt = true

// avalanche teleporter relayer deploy
func newDeployCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 8 additions & 1 deletion pkg/models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/subnet/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/teleporter/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,15 @@ func CreateBaseRelayerConfigIfMissing(
relayerConfigPath string,
logLevel string,
storageLocation string,
metricsPort uint16,
network models.Network,
) error {
if !utils.FileExists(relayerConfigPath) {
return CreateBaseRelayerConfig(
relayerConfigPath,
logLevel,
storageLocation,
metricsPort,
network,
)
}
Expand All @@ -341,6 +343,7 @@ func CreateBaseRelayerConfig(
relayerConfigPath string,
logLevel string,
storageLocation string,
metricsPort uint16,
network models.Network,
) error {
awmRelayerConfig := &config.Config{
Expand All @@ -357,7 +360,7 @@ func CreateBaseRelayerConfig(
ProcessMissedBlocks: false,
SourceBlockchains: []*config.SourceBlockchain{},
DestinationBlockchains: []*config.DestinationBlockchain{},
MetricsPort: constants.AWMRelayerMetricsPort,
MetricsPort: metricsPort,
}
return saveRelayerConfig(awmRelayerConfig, relayerConfigPath)
}
Expand Down

0 comments on commit 8bfe436

Please sign in to comment.