Skip to content

Commit

Permalink
Plumbing Websocket Address
Browse files Browse the repository at this point in the history
  • Loading branch information
joeabbey committed Jun 1, 2022
1 parent 7697b02 commit 97ba77d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
11 changes: 11 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (c *CosmosChain) GetGRPCAddress() string {
return fmt.Sprintf("%s:9090", c.getFullNode().HostName())
}

// Implements Chain interface
func (c *CosmosChain) GetWebsocketAddress() string {
return fmt.Sprintf("ws://%s:26657/websocket", c.getFullNode().HostName())
}

// GetHostRPCAddress returns the address of the RPC server accessible by the host.
// This will not return a valid address until the chain has been started.
func (c *CosmosChain) GetHostRPCAddress() string {
Expand All @@ -119,6 +124,12 @@ func (c *CosmosChain) GetHostGRPCAddress() string {
return dockerutil.GetHostPort(c.getFullNode().Container, grpcPort)
}

// GetHostWebsocketAddress returns the address of the websocket stream accessible by the host.
// This will not return a valid address until the chain has been started.
func (c *CosmosChain) GetHostWebsocketAddress() string {
return "ws://" + dockerutil.GetHostPort(c.getFullNode().Container, rpcPort) + "/websocket"
}

// Implements Chain interface
func (c *CosmosChain) CreateKey(ctx context.Context, keyName string) error {
return c.getFullNode().CreateKey(ctx, keyName)
Expand Down
11 changes: 11 additions & 0 deletions chain/penumbra/penumbra_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ func (c *PenumbraChain) GetGRPCAddress() string {
return fmt.Sprintf("%s:9090", c.getRelayerNode().TendermintNode.HostName())
}

// Implements Chain interface
func (c *PenumbraChain) GetWebsocketAddress() string {
return fmt.Sprintf("ws://%s:26657/websocket", c.getRelayerNode().TendermintNode.HostName())
}

// GetHostRPCAddress returns the address of the RPC server accessible by the host.
// This will not return a valid address until the chain has been started.
func (c *PenumbraChain) GetHostRPCAddress() string {
Expand All @@ -135,6 +140,12 @@ func (c *PenumbraChain) GetHostGRPCAddress() string {
return dockerutil.GetHostPort(c.getRelayerNode().TendermintNode.Container, grpcPort)
}

// GetHostWebsocketAddress returns the address of the websocket stream accessible by the host.
// This will not return a valid address until the chain has been started.
func (c *PenumbraChain) GetHostWebsocketAddress() string {
return "ws://" + dockerutil.GetHostPort(c.getRelayerNode().TendermintNode.Container, rpcPort) + "/websocket"
}

// Implements Chain interface
func (c *PenumbraChain) CreateKey(ctx context.Context, keyName string) error {
return c.getRelayerNode().PenumbraAppNode.CreateKey(ctx, keyName)
Expand Down
2 changes: 1 addition & 1 deletion ibc/Relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Relayer interface {
AddKey(ctx context.Context, rep RelayerExecReporter, chainID, keyName string) (RelayerWallet, error)

// add relayer configuration for a chain
AddChainConfiguration(ctx context.Context, rep RelayerExecReporter, chainConfig ChainConfig, keyName, rpcAddr, grpcAddr string) error
AddChainConfiguration(ctx context.Context, rep RelayerExecReporter, chainConfig ChainConfig, keyName, rpcAddr, grpcAddr, websocketAddr string) error

// generate new path between two chains
GeneratePath(ctx context.Context, rep RelayerExecReporter, srcChainID, dstChainID, pathName string) error
Expand Down
7 changes: 7 additions & 0 deletions ibc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ type Chain interface {
// retrieves grpc address that can be reached by other containers in the docker network
GetGRPCAddress() string

// retrieves websocket address that can be reached by other containers in the docker network
GetWebsocketAddress() string

// GetHostRPCAddress returns the rpc address that can be reached by processes on the host machine.
// Note that this will not return a valid value until after Start returns.
GetHostRPCAddress() string

// GetHostWebsocketAddress returns the websocket endpoint that can be reached by processes on the host machine.
// Note that this will not return a valid value until after Start returns.
GetHostWebsocketAddress() string

// GetHostGRPCAddress returns the grpc address that can be reached by processes on the host machine.
// Note that this will not return a valid value until after Start returns.
GetHostGRPCAddress() string
Expand Down
6 changes: 3 additions & 3 deletions interchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ func (ic *Interchain) configureRelayerKeys(ctx context.Context, rep *testreporte

for r, chains := range ic.relayerChains() {
for _, c := range chains {
rpcAddr, grpcAddr := c.GetRPCAddress(), c.GetGRPCAddress()
rpcAddr, grpcAddr, websocket := c.GetRPCAddress(), c.GetGRPCAddress(), c.GetWebsocketAddress()
if !r.UseDockerNetwork() {
rpcAddr, grpcAddr = c.GetHostRPCAddress(), c.GetHostGRPCAddress()
rpcAddr, grpcAddr, websocket = c.GetHostRPCAddress(), c.GetHostGRPCAddress(), c.GetHostWebsocketAddress()
}

chainName := ic.chains[c]
if err := r.AddChainConfiguration(ctx,
rep,
c.Config(), chainName,
rpcAddr, grpcAddr,
rpcAddr, grpcAddr, websocket,
); err != nil {
return fmt.Errorf("failed to configure relayer %s for chain %s: %w", ic.relayers[r], chainName, err)
}
Expand Down
6 changes: 3 additions & 3 deletions relayer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewDockerRelayer(log *zap.Logger, testName, home string, pool *dockertest.P
}
}

func (r *DockerRelayer) AddChainConfiguration(ctx context.Context, rep ibc.RelayerExecReporter, chainConfig ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) error {
func (r *DockerRelayer) AddChainConfiguration(ctx context.Context, rep ibc.RelayerExecReporter, chainConfig ibc.ChainConfig, keyName, rpcAddr, grpcAddr, websocketAddr string) error {
// rly needs to run "rly config init", and AddChainConfiguration should be the first call where it's needed.
// This might be a better fit for NewDockerRelayer, but that would considerably change the function signature.
if !r.didInit {
Expand All @@ -75,7 +75,7 @@ func (r *DockerRelayer) AddChainConfiguration(ctx context.Context, rep ibc.Relay
chainConfigLocalFilePath := filepath.Join(r.Dir(), chainConfigFile)
chainConfigContainerFilePath := fmt.Sprintf("%s/%s", r.NodeHome(), chainConfigFile)

configContent, err := r.c.ConfigContent(ctx, chainConfig, keyName, rpcAddr, grpcAddr)
configContent, err := r.c.ConfigContent(ctx, chainConfig, keyName, rpcAddr, "", grpcAddr)
if err != nil {
return fmt.Errorf("failed to generate config content: %w", err)
}
Expand Down Expand Up @@ -370,7 +370,7 @@ type RelayerCommander interface {
ContainerVersion() string

// ConfigContent generates the content of the config file that will be passed to AddChainConfiguration.
ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error)
ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr, websocketAddr string) ([]byte, error)

// ParseAddKeyOutput processes the output of AddKey
// to produce the wallet that was created.
Expand Down
14 changes: 7 additions & 7 deletions relayer/hermes/hermes_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func GetGasPriceFromString(gasPrices string) HermesGasPriceConfig {
}
}

func ChainConfigToHermesChainConfig(chainConfig ibc.ChainConfig, keyName, rpcAddr, gprcAddr string) HermesChainConfig {
func ChainConfigToHermesChainConfig(chainConfig ibc.ChainConfig, keyName, rpcAddr, gprcAddr, websocketAddr string) HermesChainConfig {
return HermesChainConfig{
ID: chainConfig.ChainID,
RpcAddr: rpcAddr,
WebSocketAddr: "ws://127.0.0.1:26657/websocket", //Required
WebSocketAddr: websocketAddr,
GRPCAddr: gprcAddr,
RPCTimeout: "10s",
AccountPrefix: chainConfig.Bech32Prefix,
Expand Down Expand Up @@ -191,23 +191,23 @@ func (c commander) CreateConnections(pathName, homeDir string) []string {
// FIXME GeneratePath
func (commander) GeneratePath(srcChainID, dstChainID, pathName, homeDir string) []string {
return []string{
"hermes", "paths", "new", srcChainID, dstChainID, "--create-new-connections",
"hermes", "paths", "new", srcChainID, dstChainID, "--new-client-connection",
"-c", filepath.Join(homeDir, "config.toml"),
"-j",
}
}

func (commander) GetChannels(chainID, homeDir string) []string {
return []string{
"hermes", "q", "channels", chainID,
"hermes", "query", "channels", chainID,
"-c", filepath.Join(homeDir, "config.toml"),
"-j",
}
}

func (commander) GetConnections(chainID, homeDir string) []string {
return []string{
"hermes", "q", "connections", chainID,
"hermes", "query", "connections", chainID,
"-c", filepath.Join(homeDir, "config.toml"),
"-j",
}
Expand Down Expand Up @@ -260,8 +260,8 @@ func (c commander) UpdateClients(pathName, homeDir string) []string {
}

// FIXME ConfigContent
func (commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
cosmosRelayerChainConfig := ChainConfigToHermesChainConfig(cfg, keyName, rpcAddr, grpcAddr)
func (commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr, websocketAddr string) ([]byte, error) {
cosmosRelayerChainConfig := ChainConfigToHermesChainConfig(cfg, keyName, rpcAddr, grpcAddr, websocketAddr)
jsonBytes, err := json.Marshal(cosmosRelayerChainConfig)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions relayer/rly/cosmos_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Capabilities() map[relayer.Capability]bool {
return m
}

func ChainConfigToCosmosRelayerChainConfig(chainConfig ibc.ChainConfig, keyName, rpcAddr, gprcAddr string) CosmosRelayerChainConfig {
func ChainConfigToCosmosRelayerChainConfig(chainConfig ibc.ChainConfig, keyName, rpcAddr, gprcAddr, websocketAddr string) CosmosRelayerChainConfig {
return CosmosRelayerChainConfig{
Type: chainConfig.Type,
Value: CosmosRelayerChainConfigValue{
Expand Down Expand Up @@ -194,8 +194,8 @@ func (commander) UpdateClients(pathName, homeDir string) []string {
}
}

func (commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
cosmosRelayerChainConfig := ChainConfigToCosmosRelayerChainConfig(cfg, keyName, rpcAddr, grpcAddr)
func (commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr, websocketAddr string) ([]byte, error) {
cosmosRelayerChainConfig := ChainConfigToCosmosRelayerChainConfig(cfg, keyName, rpcAddr, grpcAddr, websocketAddr)
jsonBytes, err := json.Marshal(cosmosRelayerChainConfig)
if err != nil {
return nil, err
Expand Down

0 comments on commit 97ba77d

Please sign in to comment.