From 61136ccf2d0b09d81a80ea7aec43cc8e33677a4d Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:32:22 -0600 Subject: [PATCH] Interchain modifcation for fallback rpc in AddChainConfiguration functions --- chain/cosmos/cosmos_chain.go | 11 ++++++++--- chain/penumbra/penumbra_app_node.go | 3 +-- chain/penumbra/penumbra_chain.go | 5 +++++ chain/polkadot/polkadot_chain.go | 15 +++++++++------ chain/polkadot/ss58.go | 4 ++-- ibc/chain.go | 4 ++++ ibc/relayer.go | 2 +- interchain.go | 5 +++-- relayer/docker.go | 6 +++--- relayer/hermes/hermes_commander.go | 2 +- relayer/hermes/hermes_relayer.go | 6 +++--- relayer/hyperspace/hyperspace_commander.go | 4 ++-- relayer/rly/cosmos_relayer.go | 2 +- 13 files changed, 43 insertions(+), 26 deletions(-) diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 2336b7ce3..926ac28a6 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -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, @@ -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()) @@ -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, @@ -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, diff --git a/chain/penumbra/penumbra_app_node.go b/chain/penumbra/penumbra_app_node.go index 78ce8762b..2240a607e 100644 --- a/chain/penumbra/penumbra_app_node.go +++ b/chain/penumbra/penumbra_app_node.go @@ -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" @@ -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 diff --git a/chain/penumbra/penumbra_chain.go b/chain/penumbra/penumbra_chain.go index 9c80eac4b..9099aaf71 100644 --- a/chain/penumbra/penumbra_chain.go +++ b/chain/penumbra/penumbra_chain.go @@ -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()) diff --git a/chain/polkadot/polkadot_chain.go b/chain/polkadot/polkadot_chain.go index 149d21ec4..b15687d2f 100644 --- a/chain/polkadot/polkadot_chain.go +++ b/chain/polkadot/polkadot_chain.go @@ -2,7 +2,6 @@ package polkadot import ( "context" - "crypto/rand" crand "crypto/rand" "encoding/json" "fmt" @@ -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" @@ -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 } @@ -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{} @@ -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 { @@ -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() @@ -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) diff --git a/chain/polkadot/ss58.go b/chain/polkadot/ss58.go index 0abcb3e87..237d04a2a 100644 --- a/chain/polkadot/ss58.go +++ b/chain/polkadot/ss58.go @@ -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{}) @@ -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 } diff --git a/ibc/chain.go b/ibc/chain.go index d9120f5ba..41de4d837 100644 --- a/ibc/chain.go +++ b/ibc/chain.go @@ -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 diff --git a/ibc/relayer.go b/ibc/relayer.go index 0202f2a3a..cebc9ff2a 100644 --- a/ibc/relayer.go +++ b/ibc/relayer.go @@ -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 diff --git a/interchain.go b/interchain.go index 33fa5ee57..470234499 100644 --- a/interchain.go +++ b/interchain.go @@ -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) } diff --git a/relayer/docker.go b/relayer/docker.go index 4eabd29a1..f96d69a40 100644 --- a/relayer/docker.go +++ b/relayer/docker.go @@ -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) } @@ -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. diff --git a/relayer/hermes/hermes_commander.go b/relayer/hermes/hermes_commander.go index ad9cc5a7d..aecce7415 100644 --- a/relayer/hermes/hermes_commander.go +++ b/relayer/hermes/hermes_commander.go @@ -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") } diff --git a/relayer/hermes/hermes_relayer.go b/relayer/hermes/hermes_relayer.go index fc133db82..3da316bb3 100644 --- a/relayer/hermes/hermes_relayer.go +++ b/relayer/hermes/hermes_relayer.go @@ -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) } @@ -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, diff --git a/relayer/hyperspace/hyperspace_commander.go b/relayer/hyperspace/hyperspace_commander.go index e98544ddf..fa222029b 100644 --- a/relayer/hyperspace/hyperspace_commander.go +++ b/relayer/hyperspace/hyperspace_commander.go @@ -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 { @@ -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) diff --git a/relayer/rly/cosmos_relayer.go b/relayer/rly/cosmos_relayer.go index c59f2d1c0..83e674d0a 100644 --- a/relayer/rly/cosmos_relayer.go +++ b/relayer/rly/cosmos_relayer.go @@ -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 {