Skip to content

Commit

Permalink
fix(local-ic): multiple ics, faster relayer (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups authored Oct 30, 2024
1 parent a8a5b2b commit f20ce5a
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 48 deletions.
21 changes: 21 additions & 0 deletions dockerutil/env.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion dockerutil/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions local-interchain/chains/README.md
Original file line number Diff line number Diff line change
@@ -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
```
75 changes: 64 additions & 11 deletions local-interchain/chains/interchainsecurity.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -83,18 +83,67 @@
{
"key": "app_state.ccvconsumer.params.reward_denoms",
"value": [
"untrn"
"ustrd"
]
},
{
"key": "app_state.ccvconsumer.params.provider_reward_denoms",
"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",
Expand All @@ -105,6 +154,10 @@
}
]
},
{
"key": "app_state.feemarket.params.enabled",
"value": false
},
{
"key": "app_state.feeburner.params.treasury_address",
"value": "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky"
Expand Down Expand Up @@ -145,4 +198,4 @@
}
}
]
}
}
34 changes: 22 additions & 12 deletions local-interchain/interchain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
}

Expand Down
68 changes: 44 additions & 24 deletions relayer/rly/cosmos_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/docker/docker/client"
"go.uber.org/zap"
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
},
}
}
Expand Down

0 comments on commit f20ce5a

Please sign in to comment.