Skip to content
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

Add modifcation for fallback rpc's in AddChainConfiguration funcs #834

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *CosmosChain) AddFullNodes(ctx context.Context, configFileOverrides map[
for configFile, modifiedConfig := range configFileOverrides {
modifiedToml, ok := modifiedConfig.(testutil.Toml)
if !ok {
return fmt.Errorf("Provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
return fmt.Errorf("provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
}
if err := testutil.ModifyTomlConfigFile(
ctx,
Expand Down Expand Up @@ -208,6 +208,11 @@ func (c *CosmosChain) GetRPCAddress() string {
return fmt.Sprintf("http://%s:26657", c.getFullNode().HostName())
}

// Implements Chain interface
func (c *CosmosChain) GetFallbackRPCAddress() []string {
return []string{} //Todo: return fallback rpc's correctly
}

// Implements Chain interface
func (c *CosmosChain) GetAPIAddress() string {
return fmt.Sprintf("http://%s:1317", c.getFullNode().HostName())
Expand Down Expand Up @@ -871,7 +876,7 @@ func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGene
for configFile, modifiedConfig := range configFileOverrides {
modifiedToml, ok := modifiedConfig.(testutil.Toml)
if !ok {
return fmt.Errorf("Provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
return fmt.Errorf("provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
}
if err := testutil.ModifyTomlConfigFile(
ctx,
Expand Down Expand Up @@ -903,7 +908,7 @@ func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGene
for configFile, modifiedConfig := range configFileOverrides {
modifiedToml, ok := modifiedConfig.(testutil.Toml)
if !ok {
return fmt.Errorf("Provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
return fmt.Errorf("provided toml override for file %s is of type (%T). Expected (DecodedToml)", configFile, modifiedConfig)
}
if err := testutil.ModifyTomlConfigFile(
ctx,
Expand Down
3 changes: 1 addition & 2 deletions chain/penumbra/penumbra_app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
Expand All @@ -25,7 +24,7 @@ type PenumbraAppNode struct {
Chain *PenumbraChain
TestName string
NetworkID string
DockerClient *client.Client
DockerClient *dockerclient.Client
Image ibc.DockerImage

containerLifecycle *dockerutil.ContainerLifecycle
Expand Down
5 changes: 5 additions & 0 deletions chain/penumbra/penumbra_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func (c *PenumbraChain) GetRPCAddress() string {
return fmt.Sprintf("http://%s:26657", c.getFullNode().TendermintNode.HostName())
}

// Implements Chain interface
func (c *PenumbraChain) GetFallbackRPCAddress() []string {
return []string{} //TODO: implement fallback rpc returns correctly
}

// Implements Chain interface
func (c *PenumbraChain) GetGRPCAddress() string {
return fmt.Sprintf("%s:9090", c.getFullNode().TendermintNode.HostName())
Expand Down
15 changes: 9 additions & 6 deletions chain/polkadot/polkadot_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package polkadot

import (
"context"
"crypto/rand"
crand "crypto/rand"
"encoding/json"
"fmt"
Expand All @@ -16,7 +15,6 @@ import (
"github.com/cosmos/go-bip39"
"github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
dockerclient "github.com/docker/docker/client"
"github.com/icza/dyno"
p2pcrypto "github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -105,7 +103,7 @@ func (c *PolkadotChain) NewRelayChainNode(
image ibc.DockerImage,
) (*RelayChainNode, error) {
seed := make([]byte, 32)
if _, err := rand.Read(seed); err != nil {
if _, err := crand.Read(seed); err != nil {
return nil, err
}

Expand Down Expand Up @@ -239,7 +237,7 @@ func (c *PolkadotChain) NewParachainNode(

// Initialize initializes node structs so that things like initializing keys can be done before starting the chain.
// Implements Chain interface.
func (c *PolkadotChain) Initialize(ctx context.Context, testName string, cli *client.Client, networkID string) error {
func (c *PolkadotChain) Initialize(ctx context.Context, testName string, cli *dockerclient.Client, networkID string) error {
relayChainNodes := []*RelayChainNode{}
chainCfg := c.Config()
images := []ibc.DockerImage{}
Expand Down Expand Up @@ -553,6 +551,11 @@ func (c *PolkadotChain) GetRPCAddress() string {
//return fmt.Sprintf("%s:%s", c.RelayChainNodes[0].HostName(), strings.Split(rpcPort, "/")[0])
}

// Implements Chain interface
func (c *PolkadotChain) GetFallbackRPCAddress() []string {
return []string{} //TODO: implement proper return
}

// GetGRPCAddress retrieves the grpc address that can be reached by other containers in the docker network.
// Implements Chain interface.
func (c *PolkadotChain) GetGRPCAddress() string {
Expand Down Expand Up @@ -631,7 +634,7 @@ func NewMnemonic() (string, error) {
func (c *PolkadotChain) CreateKey(ctx context.Context, keyName string) error {
_, err := c.keyring.Get(keyName)
if err == nil {
return fmt.Errorf("Key already exists: %s", keyName)
return fmt.Errorf("key already exists: %s", keyName)
}

mnemonic, err := NewMnemonic()
Expand Down Expand Up @@ -661,7 +664,7 @@ func (c *PolkadotChain) CreateKey(ctx context.Context, keyName string) error {
func (c *PolkadotChain) RecoverKey(ctx context.Context, keyName, mnemonic string) error {
_, err := c.keyring.Get(keyName)
if err == nil {
return fmt.Errorf("Key already exists: %s", keyName)
return fmt.Errorf("key already exists: %s", keyName)
}

kp, err := signature.KeyringPairFromSecret(mnemonic, Ss58Format)
Expand Down
4 changes: 2 additions & 2 deletions chain/polkadot/ss58.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func DecodeAddressSS58(address string) ([]byte, error) {
} else if IntInSlice(len(ss58AddrDecoded), []int{17}) {
checksumLength = 8
} else {
return nil, fmt.Errorf("Cannot get checksum length")
return nil, fmt.Errorf("cannot get checksum length")
}
bss := ss58AddrDecoded[0 : len(ss58AddrDecoded)-checksumLength]
checksum, _ := blake2b.New(64, []byte{})
Expand All @@ -69,7 +69,7 @@ func DecodeAddressSS58(address string) ([]byte, error) {

h := checksum.Sum(nil)
if BytesToHex(h[0:checksumLength]) != BytesToHex(ss58AddrDecoded[len(ss58AddrDecoded)-checksumLength:]) {
return nil, fmt.Errorf("Checksum incorrect")
return nil, fmt.Errorf("checksum incorrect")
}
return ss58AddrDecoded[1 : len(ss58AddrDecoded)-checksumLength], nil
}
Expand Down
4 changes: 4 additions & 0 deletions ibc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Chain interface {
// Note that this will not return a valid value until after Start returns.
GetHostRPCAddress() string

// GetFallbackRPCAddress returns the fallback rpc address's that can be reached by processes on the host machine.
// Note that this will not return a valid value until after Start returns.
GetFallbackRPCAddress() []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
2 changes: 1 addition & 1 deletion ibc/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Relayer interface {
GetWallet(chainID string) (Wallet, bool)

// 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 string, fallbackRpc []string) error

// generate new path between two chains
GeneratePath(ctx context.Context, rep RelayerExecReporter, srcChainID, dstChainID, pathName string) error
Expand Down
5 changes: 3 additions & 2 deletions interchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,17 @@ 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, fallbackRpc := c.GetRPCAddress(), c.GetGRPCAddress(), c.GetFallbackRPCAddress()
if !r.UseDockerNetwork() {
rpcAddr, grpcAddr = c.GetHostRPCAddress(), c.GetHostGRPCAddress()
fallbackRpc = c.GetFallbackRPCAddress()
}

chainName := ic.chains[c]
if err := r.AddChainConfiguration(ctx,
rep,
c.Config(), chainName,
rpcAddr, grpcAddr,
rpcAddr, grpcAddr, fallbackRpc,
); 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 @@ -158,14 +158,14 @@ func (r *DockerRelayer) AddWallet(chainID string, wallet ibc.Wallet) {
r.wallets[chainID] = wallet
}

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 string, fallbackRpc []string) error {
// For rly this file is json, but the file extension should not matter.
// Using .config to avoid implying any particular format.
chainConfigFile := chainConfig.ChainID + ".config"

chainConfigContainerFilePath := path.Join(r.HomeDir(), chainConfigFile)

configContent, err := r.c.ConfigContent(ctx, chainConfig, keyName, rpcAddr, grpcAddr)
configContent, err := r.c.ConfigContent(ctx, chainConfig, keyName, rpcAddr, grpcAddr, fallbackRpc)
if err != nil {
return fmt.Errorf("failed to generate config content: %w", err)
}
Expand Down Expand Up @@ -523,7 +523,7 @@ type RelayerCommander interface {
DockerUser() 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 string, fallbackRpc []string) ([]byte, error)

// ParseAddKeyOutput processes the output of AddKey
// to produce the wallet that was created.
Expand Down
2 changes: 1 addition & 1 deletion relayer/hermes/hermes_commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c commander) Flush(pathName, channelID, homeDir string) []string {
panic("flush implemented in hermes relayer not the commander")
}

func (c commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
func (c commander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string, fallbackRpc []string) ([]byte, error) {
panic("config content implemented in hermes relayer not the commander")
}

Expand Down
6 changes: 3 additions & 3 deletions relayer/hermes/hermes_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func NewHermesRelayer(log *zap.Logger, testName string, cli *client.Client, netw

// AddChainConfiguration is called once per chain configuration, which means that in the case of hermes, the single
// config file is overwritten with a new entry each time this function is called.
func (r *Relayer) AddChainConfiguration(ctx context.Context, rep ibc.RelayerExecReporter, chainConfig ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) error {
configContent, err := r.configContent(chainConfig, keyName, rpcAddr, grpcAddr)
func (r *Relayer) AddChainConfiguration(ctx context.Context, rep ibc.RelayerExecReporter, chainConfig ibc.ChainConfig, keyName, rpcAddr, grpcAddr string, fallbackRpc []string) error {
configContent, err := r.configContent(chainConfig, keyName, rpcAddr, grpcAddr, fallbackRpc)
if err != nil {
return fmt.Errorf("failed to generate config content: %w", err)
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (r *Relayer) GeneratePath(ctx context.Context, rep ibc.RelayerExecReporter,
// configContent returns the contents of the hermes config file as a byte array. Note: as hermes expects a single file
// rather than multiple config files, we need to maintain a list of chain configs each time they are added to write the
// full correct file update calling Relayer.AddChainConfiguration.
func (r *Relayer) configContent(cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
func (r *Relayer) configContent(cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string, fallbackRpc []string) ([]byte, error) {
r.chainConfigs = append(r.chainConfigs, ChainConfig{
cfg: cfg,
keyName: keyName,
Expand Down
4 changes: 2 additions & 2 deletions relayer/hyperspace/hyperspace_commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type pathConfiguration struct {

// pathChainConfig holds all values that will be required when interacting with a path.
type pathChainConfig struct {
chainID string
chainID string
}

func (hyperspaceCommander) Name() string {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (hyperspaceCommander) UpdateClients(pathName, homeDir string) []string {
panic("[UpdateClients] Do not use me")
}

func (hyperspaceCommander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string) ([]byte, error) {
func (hyperspaceCommander) ConfigContent(ctx context.Context, cfg ibc.ChainConfig, keyName, rpcAddr, grpcAddr string, fallbackRpc []string) ([]byte, error) {
fmt.Println("[hyperspace] ConfigContent", cfg, keyName, rpcAddr, grpcAddr)
HyperspaceRelayerChainConfig := ChainConfigToHyperspaceRelayerChainConfig(cfg, keyName, rpcAddr, grpcAddr)
bytes, err := toml.Marshal(HyperspaceRelayerChainConfig)
Expand Down
2 changes: 1 addition & 1 deletion relayer/rly/cosmos_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (commander) UpdateClients(pathName, homeDir string) []string {
}
}

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