cosmos / relayer

An IBC relayer for ibc-go
Apache License 2.0
390 stars 1.71k forks source link

Bug in `rly paths fetch`; infinite loop #873

Closed jtieri closed 2 years ago

jtieri commented 2 years ago

While preparing to update the IBC light clients on Juno I noticed that rly paths fetch gets stuck in an infinite loop when you have many chains in your config.

Here is the config:

global:
    api-listen-addr: :5183
    timeout: 10s
    memo: ""
    light-cache-size: 20
chains:
    akash:
        type: cosmos
        value:
            key: default
            chain-id: akashnet-2
            rpc-addr: https://akash-rpc.polkachu.com:443
            account-prefix: akash
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uakt
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    assetmantle:
        type: cosmos
        value:
            key: default
            chain-id: mantle-1
            rpc-addr: https://rpc.asset-mantle.ezstaking.io:443
            account-prefix: mantle
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01umntl
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    axelar:
        type: cosmos
        value:
            key: default
            chain-id: axelar-dojo-1
            rpc-addr: https://rpc-axelar-ia.notional.ventures:443/
            account-prefix: axelar
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uaxl
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    bandchain:
        type: cosmos
        value:
            key: default
            chain-id: laozi-mainnet
            rpc-addr: http://rpc.laozi1.bandchain.org:80
            account-prefix: band
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uband
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    bitcanna:
        type: cosmos
        value:
            key: default
            chain-id: bitcanna-1
            rpc-addr: https://bitcanna-rpc.polkachu.com:443
            account-prefix: bcna
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01ubcna
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    bitsong:
        type: cosmos
        value:
            key: default
            chain-id: bitsong-2b
            rpc-addr: https://rpc-bitsong.itastakers.com:443
            account-prefix: bitsong
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01ubtsg
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    chihuahua:
        type: cosmos
        value:
            key: default
            chain-id: chihuahua-1
            rpc-addr: https://rpc-chihuahua.ecostake.com:443
            account-prefix: chihuahua
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uhuahua
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    comdex:
        type: cosmos
        value:
            key: default
            chain-id: comdex-1
            rpc-addr: https://rpc-comdex.zenchainlabs.io:443/
            account-prefix: comdex
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01ucmdx
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    cosmoshub:
        type: cosmos
        value:
            key: default
            chain-id: cosmoshub-4
            rpc-addr: https://rpc-cosmoshub.ecostake.com:443
            account-prefix: cosmos
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uatom
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    kichain:
        type: cosmos
        value:
            key: default
            chain-id: kichain-2
            rpc-addr: https://rpc.kichain.ezstaking.io:443
            account-prefix: ki
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uxki
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    kujira:
        type: cosmos
        value:
            key: default
            chain-id: kaiyo-1
            rpc-addr: https://rpc.kaiyo.kujira.setten.io:443
            account-prefix: kujira
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01ukuji
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    likecoin:
        type: cosmos
        value:
            key: default
            chain-id: likecoin-mainnet-2
            rpc-addr: https://mainnet-node.like.co:443/rpc/
            account-prefix: like
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01nanolike
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    omniflixhub:
        type: cosmos
        value:
            key: default
            chain-id: omniflixhub-1
            rpc-addr: https://omniflixhub-rpc.skynetvalidators.com:443
            account-prefix: omniflix
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uflix
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    osmosis:
        type: cosmos
        value:
            key: default
            chain-id: osmosis-1
            rpc-addr: https://rpc-osmosis-ia.notional.ventures:443/
            account-prefix: osmo
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uosmo
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    persistence:
        type: cosmos
        value:
            key: default
            chain-id: core-1
            rpc-addr: https://rpc.core.persistence.one:443
            account-prefix: persistence
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uxprt
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    regen:
        type: cosmos
        value:
            key: default
            chain-id: regen-1
            rpc-addr: http://public-rpc.regen.vitwit.com:26657
            account-prefix: regen
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uregen
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    rizon:
        type: cosmos
        value:
            key: default
            chain-id: titan-1
            rpc-addr: https://rpcapi.rizon.world:443/
            account-prefix: rizon
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uatolo
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    secretnetwork:
        type: cosmos
        value:
            key: default
            chain-id: secret-4
            rpc-addr: https://rpc.secret.forbole.com:443/
            account-prefix: secret
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uscrt
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    sentinel:
        type: cosmos
        value:
            key: default
            chain-id: sentinelhub-2
            rpc-addr: https://rpc-sentinel-ia.notional.ventures:443/
            account-prefix: sent
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01udvpn
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    sifchain:
        type: cosmos
        value:
            key: default
            chain-id: sifchain-1
            rpc-addr: https://sifchain-rpc.polkachu.com:443
            account-prefix: sif
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01rowan
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    stargaze:
        type: cosmos
        value:
            key: default
            chain-id: stargaze-1
            rpc-addr: https://rpc.stargaze.pupmos.network:443/
            account-prefix: stars
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01ustars
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
    umee:
        type: cosmos
        value:
            key: default
            chain-id: umee-1
            rpc-addr: https://rpc-umee-ia.notional.ventures:443/
            account-prefix: umee
            keyring-backend: test
            gas-adjustment: 1.2
            gas-prices: 0.01uumee
            debug: false
            timeout: 20s
            output-format: json
            sign-mode: direct
paths: {}
jtieri commented 2 years ago

Proposal: We ditch the library used for calculating the permutations in favor of a nested for loop

Ex:

for _, chainA := range chains {
    for _, chainB := range chains {
        if chainA == chainB {
            continue
        }

    pair := chainA + "-" + chainB
    if chainB < chainA {
        pair = chainB + "-" + chainA
    }
    chainCombinations[pair] = true
    }
}
jackzampolin commented 2 years ago

cc @boojamya

boojamya commented 2 years ago

Yea, I guess those permutations get a bit much with a config that big.

I think that is a good solution @jtieri, pretty sure that is how you originally had it implemented too.