From f20ce5a3ae665bf13d4548e0157d61f8ff3f92d7 Mon Sep 17 00:00:00 2001 From: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:23:53 +0400 Subject: [PATCH] fix(local-ic): multiple ics, faster relayer (#1235) --- dockerutil/env.go | 21 ++++++ dockerutil/image.go | 2 +- local-interchain/chains/README.md | 13 ++++ .../chains/interchainsecurity.json | 75 ++++++++++++++++--- local-interchain/interchain/start.go | 34 ++++++--- relayer/rly/cosmos_relayer.go | 68 +++++++++++------ 6 files changed, 165 insertions(+), 48 deletions(-) create mode 100644 dockerutil/env.go create mode 100644 local-interchain/chains/README.md diff --git a/dockerutil/env.go b/dockerutil/env.go new file mode 100644 index 000000000..bb8be9a81 --- /dev/null +++ b/dockerutil/env.go @@ -0,0 +1,21 @@ +package dockerutil + +import ( + "fmt" + "os" + "time" +) + +// GetTimeFromEnv gets a time.Duration from a given environment variable key, or returns the fallback value if the key is not set. +func GetTimeFromEnv(key string, fallback time.Duration) time.Duration { + value, ok := os.LookupEnv(key) + if !ok { + return fallback + } + + v, err := time.ParseDuration(value) + if err != nil { + panic(fmt.Sprintf("BUG: failed to parse %s: %s", value, err)) + } + return v +} diff --git a/dockerutil/image.go b/dockerutil/image.go index 161fb9558..8c9d6184f 100644 --- a/dockerutil/image.go +++ b/dockerutil/image.go @@ -224,7 +224,7 @@ func (image *Image) Start(ctx context.Context, cmd []string, opts ContainerOptio return nil, image.WrapErr(fmt.Errorf("create container %s: %w", containerName, err)) } - logger.Info("About to start container") + logger.Info("Exec") err = StartContainer(ctx, image.client, cID) if err != nil { diff --git a/local-interchain/chains/README.md b/local-interchain/chains/README.md new file mode 100644 index 000000000..6feb25125 --- /dev/null +++ b/local-interchain/chains/README.md @@ -0,0 +1,13 @@ +# Chains Examples + +## interchainsecurity & neutron + +Current the neutron heighliner image does not work due to some /tmp issue in the docker image. For this reason, you must compile the image yourself to use the latest v50 instance. + +```bash +git clone https://github.com/neutron-org/neutron.git --depth 1 --branch v4.2.1 +cd neutron + +# neutron-node:latest +make build-e2e-docker-image +``` diff --git a/local-interchain/chains/interchainsecurity.json b/local-interchain/chains/interchainsecurity.json index 73400bff6..e5463c064 100644 --- a/local-interchain/chains/interchainsecurity.json +++ b/local-interchain/chains/interchainsecurity.json @@ -52,15 +52,15 @@ }, { "name": "ics-consumer", - "chain_id": "localneutron-1", - "denom": "untrn", - "binary": "neutrond", - "bech32_prefix": "neutron", + "chain_id": "localstride-1", + "denom": "ustrd", + "binary": "strided", + "bech32_prefix": "stride", "docker_image": { - "version": "v3.0.4", - "repository": "ghcr.io/strangelove-ventures/heighliner/neutron" + "version": "v23.0.0", + "repository": "ghcr.io/strangelove-ventures/heighliner/stride" }, - "gas_prices": "0.0untrn,0.0uatom", + "gas_prices": "0.0ustride,0.0uatom", "chain_type": "cosmos", "coin_type": 118, "trusting_period": "336h", @@ -83,7 +83,7 @@ { "key": "app_state.ccvconsumer.params.reward_denoms", "value": [ - "untrn" + "ustrd" ] }, { @@ -91,10 +91,59 @@ "value": [ "uatom" ] + } + ], + "accounts": [ + { + "name": "acc0", + "address": "stride1hj5fveer5cjtn4wd6wstzugjfdxzl0xp98jwc0", + "amount": "10000000000%DENOM%", + "mnemonic": "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" + } + ] + } + }, + { + "name": "ics-consumer", + "chain_id": "localneutron-1", + "denom": "untrn", + "binary": "neutrond", + "bech32_prefix": "neutron", + "docker_image": { + "version": "latest", + "repository": "neutron-node" + }, + "ics_version_override": { + "provider": "v3.3.x", + "consumer": "v4.x" + }, + "gas_prices": "0.025untrn,0.0uatom", + "chain_type": "cosmos", + "coin_type": 118, + "trusting_period": "336h", + "gas_adjustment": 1.3, + "number_vals": 1, + "number_node": 0, + "ics_consumer_link": "localcosmos-1", + "debugging": true, + "block_time": "1s", + "genesis": { + "modify": [ + { + "key": "consensus.params.block.max_gas", + "value": "100000000" }, { - "key": "consensus_params.block.max_gas", - "value": "1000000000" + "key": "app_state.ccvconsumer.params.reward_denoms", + "value": [ + "untrn" + ] + }, + { + "key": "app_state.ccvconsumer.params.provider_reward_denoms", + "value": [ + "uatom" + ] }, { "key": "app_state.globalfee.params.minimum_gas_prices", @@ -105,6 +154,10 @@ } ] }, + { + "key": "app_state.feemarket.params.enabled", + "value": false + }, { "key": "app_state.feeburner.params.treasury_address", "value": "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky" @@ -145,4 +198,4 @@ } } ] -} \ No newline at end of file +} diff --git a/local-interchain/interchain/start.go b/local-interchain/interchain/start.go index e40b67a10..b5c77cdb9 100644 --- a/local-interchain/interchain/start.go +++ b/local-interchain/interchain/start.go @@ -162,32 +162,42 @@ func StartChain(installDir, chainCfgFile string, ac *types.AppStartConfig) { icsProviderPaths := make(map[string]ibc.Chain) if len(icsPair) > 0 { for provider, consumers := range icsPair { - var p, c ibc.Chain + var p ibc.Chain - // a provider can have multiple consumers + allConsumers := []ibc.Chain{} for _, consumer := range consumers { for _, chain := range chains { if chain.Config().ChainID == provider { p = chain } if chain.Config().ChainID == consumer { - c = chain + allConsumers = append(allConsumers, chain) } } } - pathName := fmt.Sprintf("%s-%s", p.Config().ChainID, c.Config().ChainID) + if p == nil { + logger.Fatal("provider not found in chains on Start", zap.String("provider", provider)) + } + + for _, c := range allConsumers { + pathName := fmt.Sprintf("%s-%s", p.Config().ChainID, c.Config().ChainID) - logger.Info("Adding ICS pair", zap.String("provider", p.Config().ChainID), zap.String("consumer", c.Config().ChainID), zap.String("path", pathName)) + logger.Info("Adding ICS pair", zap.String("provider", p.Config().ChainID), zap.String("consumer", c.Config().ChainID), zap.String("path", pathName)) - icsProviderPaths[pathName] = p + if _, ok := icsProviderPaths[pathName]; ok { + logger.Fatal("pathName already exists in icsProviderPaths. Update the consumers ChainID to be unique", zap.String("pathName", pathName)) + } - ic = ic.AddProviderConsumerLink(interchaintest.ProviderConsumerLink{ - Provider: p, - Consumer: c, - Relayer: relayer, - Path: pathName, - }) + icsProviderPaths[pathName] = p + + ic = ic.AddProviderConsumerLink(interchaintest.ProviderConsumerLink{ + Provider: p, + Consumer: c, + Relayer: relayer, + Path: pathName, + }) + } } } diff --git a/relayer/rly/cosmos_relayer.go b/relayer/rly/cosmos_relayer.go index b36d30a80..60cc9d445 100644 --- a/relayer/rly/cosmos_relayer.go +++ b/relayer/rly/cosmos_relayer.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "strings" + "time" "github.com/docker/docker/client" "go.uber.org/zap" @@ -44,18 +45,19 @@ func NewCosmosRelayer(log *zap.Logger, testName string, cli *client.Client, netw } type CosmosRelayerChainConfigValue struct { - AccountPrefix string `json:"account-prefix"` - ChainID string `json:"chain-id"` - Debug bool `json:"debug"` - GRPCAddr string `json:"grpc-addr"` - GasAdjustment float64 `json:"gas-adjustment"` - GasPrices string `json:"gas-prices"` - Key string `json:"key"` - KeyringBackend string `json:"keyring-backend"` - OutputFormat string `json:"output-format"` - RPCAddr string `json:"rpc-addr"` - SignMode string `json:"sign-mode"` - Timeout string `json:"timeout"` + AccountPrefix string `json:"account-prefix"` + ChainID string `json:"chain-id"` + Debug bool `json:"debug"` + GRPCAddr string `json:"grpc-addr"` + GasAdjustment float64 `json:"gas-adjustment"` + GasPrices string `json:"gas-prices"` + Key string `json:"key"` + KeyringBackend string `json:"keyring-backend"` + OutputFormat string `json:"output-format"` + RPCAddr string `json:"rpc-addr"` + SignMode string `json:"sign-mode"` + Timeout string `json:"timeout"` + MinLoopDuration time.Duration `json:"min-loop-duration"` } type CosmosRelayerChainConfig struct { @@ -82,21 +84,39 @@ func ChainConfigToCosmosRelayerChainConfig(chainConfig ibc.ChainConfig, keyName, if chainType == "polkadot" || chainType == "parachain" || chainType == "relaychain" { chainType = "substrate" } + + var err error + loopDuration := time.Millisecond * 50 + for _, env := range chainConfig.Env { + if strings.Contains(env, "ICTEST_RELAYER_LOOP_DURATION") { + e := strings.Split(env, "=") + if len(e) != 2 { + panic(fmt.Sprintf("BUG: failed to parse %s", env)) + } + + loopDuration, err = time.ParseDuration(e[1]) + if err != nil { + panic(fmt.Sprintf("BUG: failed to parse %s: %s", e[1], err)) + } + } + } + return CosmosRelayerChainConfig{ Type: chainType, Value: CosmosRelayerChainConfigValue{ - Key: keyName, - ChainID: chainConfig.ChainID, - RPCAddr: rpcAddr, - GRPCAddr: gprcAddr, - AccountPrefix: chainConfig.Bech32Prefix, - KeyringBackend: keyring.BackendTest, - GasAdjustment: chainConfig.GasAdjustment, - GasPrices: chainConfig.GasPrices, - Debug: true, - Timeout: "10s", - OutputFormat: "json", - SignMode: "direct", + Key: keyName, + ChainID: chainConfig.ChainID, + RPCAddr: rpcAddr, + GRPCAddr: gprcAddr, + AccountPrefix: chainConfig.Bech32Prefix, + KeyringBackend: keyring.BackendTest, + GasAdjustment: chainConfig.GasAdjustment, + GasPrices: chainConfig.GasPrices, + Debug: true, + Timeout: "10s", + OutputFormat: "json", + SignMode: "direct", + MinLoopDuration: loopDuration, }, } }