diff --git a/README.md b/README.md index ddcbf4f67..4a50750d1 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,6 @@ meant for users wishing to relay packets/data between sets of IBC enabled chains In additon, it is well documented and intended as an example where anyone who is interested in building their own relayer can come for complete, working, examples. -If you are here for Game of Zones, please be sure to check out the [offical website](https://goz.cosmosnetwork.dev). The best place for questions is [gameofzones@cosmosnetwork.dev](mailto:gameofzones@cosmosnetwork.dev) regarding Game of Zones and prepratory testnets. - ### Security Notice If you would like to report a security critical bug related to the relayer repo, please send an email to [`security@cosmosnetwork.dev`](mailto:security@cosmosnetwork.dev) @@ -21,7 +19,7 @@ The iqlusion team is dedicated to providing an inclusive and harrassment free ex ## Testnet -If you would like to join the relayer testnet, please [check out the instructions](./testnets/README.md). +If you would like to join a relayer testnet, please [check out the instructions](./testnets/README.md). ### Compatability Table: @@ -63,43 +61,43 @@ $ rly cfg add-dir configs/demo/ $ cat ~/.relayer/config/config.yaml # Now, add the key seeds from each chain to the relayer to give it funds to work with -$ rly keys restore ibc0 testkey "$(jq -r '.secret' data/ibc0/n0/gaiacli/key_seed.json)" -$ rly keys restore ibc1 testkey "$(jq -r '.secret' data/ibc1/n0/gaiacli/key_seed.json)" +$ rly keys restore ibc0 testkey "$(jq -r '.mnemonic' data/ibc0/key_seed.json)" +$ rly k r ibc1 testkey "$(jq -r '.mnemonic' data/ibc1/key_seed.json)" # Then its time to initialize the relayer's light clients for each chain # All data moving forward is validated by these light clients. $ rly light init ibc0 -f -$ rly light init ibc1 -f +$ rly l i ibc1 -f # At this point the relayer --home directory is ready for normal operations between # ibc0 and ibc1. Looking at the folder structure of the relayer at this point is helpful $ tree ~/.relayer +# See if the chains are ready to relay over +$ rly chains list + # Now you can connect the two chains with one command: $ rly tx link demo -d -o 3s # Check the token balances on both chains -$ rly q balance ibc0 -$ rly q bal ibc1 +$ rly q balance ibc0 | jq +$ rly q bal ibc1 | jq # Then send some tokens between the chains $ rly tx transfer ibc0 ibc1 1000000samoleans $(rly chains address ibc1) -$ rly tx relay demo +$ rly tx relay demo -d # See that the transfer has completed -$ rly q bal ibc0 -$ rly q bal ibc1 - -# Query the ibc denom to send the tokens back to the sender -$ rly q bal ibc1 -i +$ rly q bal ibc0 | jq +$ rly q bal ibc1 | jq # Send the tokens back to the account on ibc0 -$ rly tx xfer ibc1 ibc0 1000000ibc/2EF4DA9D3880846723AE8514CA9D77738B4F11FBA2A437EDEE43FF62E6792037 $(rly ch addr ibc0) -$ rly tx relay demo +$ rly tx xfer ibc1 ibc0 1000000transfer/ibczeroxfer/samoleans $(rly ch addr ibc0) +$ rly tx rly demo -d # See that the return trip has completed -$ rly q bal ibc0 -$ rly q bal ibc1 +$ rly q bal ibc0 | jq +$ rly q bal ibc1 | jq # NOTE: you will see the stake balances decreasing on each chain. This is to pay for fees # You can change the amount of fees you are paying on each chain in the configuration. diff --git a/cmd/chains.go b/cmd/chains.go index 9fda27cc0..0341ffb53 100644 --- a/cmd/chains.go +++ b/cmd/chains.go @@ -387,7 +387,7 @@ func userInputAdd(cmd *cobra.Command) (cfg *Config, err error) { return nil, err } - fmt.Println("Gas Adjustment (i.e. 1.0):") + fmt.Println("Gas Adjustment (i.e. 1.3):") if value, err = readStdin(); err != nil { return nil, err } @@ -396,6 +396,15 @@ func userInputAdd(cmd *cobra.Command) (cfg *Config, err error) { return nil, err } + fmt.Println("Gas Prices (i.e. 0.025stake):") + if value, err = readStdin(); err != nil { + return nil, err + } + + if c, err = c.Update("gas-prices", value); err != nil { + return nil, err + } + fmt.Println("Trusting Period (i.e. 336h)") if value, err = readStdin(); err != nil { return nil, err diff --git a/cmd/dev.go b/cmd/dev.go index e3142600a..1572ee219 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -1,11 +1,10 @@ package cmd import ( + "context" "fmt" "os" - // tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" ) @@ -38,7 +37,7 @@ func genesisCmd() *cobra.Command { return err } - gen, err := c.Client.Genesis() + gen, err := c.Client.Genesis(context.Background()) if err != nil { return err } diff --git a/cmd/light.go b/cmd/light.go index 27e628279..e31257b06 100644 --- a/cmd/light.go +++ b/cmd/light.go @@ -20,7 +20,7 @@ import ( "strconv" "github.com/cosmos/cosmos-sdk/client/flags" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "github.com/ovrclk/relayer/relayer" "github.com/spf13/cobra" ) diff --git a/cmd/paths.go b/cmd/paths.go index 963fa74c1..1be84c025 100644 --- a/cmd/paths.go +++ b/cmd/paths.go @@ -6,9 +6,9 @@ import ( "io/ioutil" "os" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - connTypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" "github.com/ovrclk/relayer/relayer" "github.com/spf13/cobra" "gopkg.in/yaml.v2" @@ -103,7 +103,7 @@ func pathsGenCmd() *cobra.Command { for _, c := range srcClients.ClientStates { // TODO: support other client types through a switch here as they become available - clnt, _ := clientTypes.UnpackClientState(c.ClientState) + clnt, _ := clienttypes.UnpackClientState(c.ClientState) if relayer.MustGetHeight(clnt.GetLatestHeight()) != 0 && !clnt.IsFrozen() { path.Src.ClientID = c.ClientId } @@ -116,7 +116,7 @@ func pathsGenCmd() *cobra.Command { for _, c := range dstClients.ClientStates { // TODO: support other client types through a switch here as they become available - clnt, _ := clientTypes.UnpackClientState(c.ClientState) + clnt, _ := clienttypes.UnpackClientState(c.ClientState) if relayer.MustGetHeight(clnt.GetLatestHeight()) != 0 && !clnt.IsFrozen() { path.Dst.ClientID = c.ClientId } @@ -161,7 +161,7 @@ func pathsGenCmd() *cobra.Command { return err } - var srcCon *connTypes.IdentifiedConnection + var srcCon *conntypes.IdentifiedConnection for _, c := range srcConns.Connections { if c.ClientId == path.Src.ClientID { srcCon = c @@ -174,7 +174,7 @@ func pathsGenCmd() *cobra.Command { return err } - var dstCon *connTypes.IdentifiedConnection + var dstCon *conntypes.IdentifiedConnection for _, c := range dstConns.Connections { if c.ClientId == path.Dst.ClientID { dstCon = c @@ -217,7 +217,7 @@ func pathsGenCmd() *cobra.Command { return err } - var srcChan *chanTypes.IdentifiedChannel + var srcChan *chantypes.IdentifiedChannel for _, c := range srcChans.Channels { if c.ConnectionHops[0] == path.Src.ConnectionID { srcChan = c @@ -230,7 +230,7 @@ func pathsGenCmd() *cobra.Command { return err } - var dstChan *chanTypes.IdentifiedChannel + var dstChan *chantypes.IdentifiedChannel for _, c := range dstChans.Channels { if c.ConnectionHops[0] == path.Dst.ConnectionID { dstChan = c @@ -370,7 +370,7 @@ func pathsListCmd() *cobra.Command { srcConn, err := ch[src].QueryConnection(srch) dstConn, _ := ch[dst].QueryConnection(dsth) - if err == nil && srcConn.Connection.State == connTypes.OPEN && dstConn.Connection.State == connTypes.OPEN { + if err == nil && srcConn.Connection.State == conntypes.OPEN && dstConn.Connection.State == conntypes.OPEN { connection = check } else { printPath(i, k, pth, chains, clients, connection, channel) @@ -380,7 +380,7 @@ func pathsListCmd() *cobra.Command { srcChan, err := ch[src].QueryChannel(srch) dstChan, _ := ch[dst].QueryChannel(dsth) - if err == nil && srcChan.Channel.State == chanTypes.OPEN && dstChan.Channel.State == chanTypes.OPEN { + if err == nil && srcChan.Channel.State == chantypes.OPEN && dstChan.Channel.State == chantypes.OPEN { channel = check } else { printPath(i, k, pth, chains, clients, connection, channel) @@ -473,13 +473,13 @@ func pathsShowCmd() *cobra.Command { srcConn, err := ch[src].QueryConnection(srch) dstConn, _ := ch[dst].QueryConnection(dsth) - if err == nil && srcConn.Connection.State == connTypes.OPEN && dstConn.Connection.State == connTypes.OPEN { + if err == nil && srcConn.Connection.State == conntypes.OPEN && dstConn.Connection.State == conntypes.OPEN { connection = true } srcChan, err := ch[src].QueryChannel(srch) dstChan, _ := ch[dst].QueryChannel(dsth) - if err == nil && srcChan.Channel.State == chanTypes.OPEN && dstChan.Channel.State == chanTypes.OPEN { + if err == nil && srcChan.Channel.State == chantypes.OPEN && dstChan.Channel.State == chantypes.OPEN { channel = true } diff --git a/cmd/query.go b/cmd/query.go index dbacbcd1d..69516af30 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "github.com/ovrclk/relayer/relayer" "github.com/spf13/cobra" ) @@ -57,7 +57,11 @@ func queryIBCDenoms() *cobra.Command { if err != nil { return err } - res, err := chain.QueryDenomTraces(0, 1000) + h, err := chain.QueryLatestHeight() + if err != nil { + return err + } + res, err := chain.QueryDenomTraces(0, 1000, h) if err != nil { return err } @@ -153,10 +157,12 @@ func queryAccountCmd() *cobra.Command { return err } + chain.UseSDKContext() + res, err := types.NewQueryClient(chain.CLIContext(0)).Account( context.Background(), &types.QueryAccountRequest{ - Address: addr, + Address: addr.String(), }) if err != nil { return err @@ -199,7 +205,12 @@ func queryBalanceCmd() *cobra.Command { return chain.Print(coins, false, false) } - dts, err := chain.QueryDenomTraces(0, 1000) + h, err := chain.QueryLatestHeight() + if err != nil { + return err + } + + dts, err := chain.QueryDenomTraces(0, 1000, h) if err != nil { return err } @@ -208,11 +219,13 @@ func queryBalanceCmd() *cobra.Command { out := sdk.Coins{} for _, c := range coins { for _, d := range dts.DenomTraces { - if c.Denom == d.IBCDenom() { + switch { + case c.Amount.Equal(sdk.NewInt(0)): + case c.Denom == d.IBCDenom(): out = append(out, sdk.NewCoin(d.GetFullDenomPath(), c.Amount)) - continue + default: + out = append(out, c) } - out = append(out, c) } } return chain.Print(out, false, false) @@ -318,6 +331,13 @@ func queryClientCmd() *cobra.Command { return err } + if height == 0 { + height, err = chain.QueryLatestHeight() + if err != nil { + return err + } + } + if err = chain.AddPath(args[1], dcon, dcha, dpor, dord); err != nil { return err } @@ -423,6 +443,13 @@ func queryConnectionsUsingClient() *cobra.Command { return err } + if height == 0 { + height, err = chain.QueryLatestHeight() + if err != nil { + return err + } + } + res, err := chain.QueryConnectionsUsingClient(height) if err != nil { return err @@ -525,6 +552,13 @@ func queryChannel() *cobra.Command { return err } + if height == 0 { + height, err = chain.QueryLatestHeight() + if err != nil { + return err + } + } + res, err := chain.QueryChannel(height) if err != nil { return err diff --git a/cmd/raw.go b/cmd/raw.go index 128adf8cc..ed84cfd53 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -4,7 +4,7 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" "github.com/ovrclk/relayer/relayer" "github.com/spf13/cobra" ) @@ -101,8 +101,13 @@ func createClientCmd() *cobra.Command { return err } + consensusParams, err := chains[dst].QueryConsensusParams() + if err != nil { + return err + } + return sendAndPrint([]sdk.Msg{chains[src].PathEnd.CreateClient(dstHeader, - chains[dst].GetTrustingPeriod(), ubdPeriod, chains[src].MustGetAddress())}, + chains[dst].GetTrustingPeriod(), ubdPeriod, consensusParams, chains[src].MustGetAddress())}, chains[src], cmd) }, } @@ -173,7 +178,7 @@ func connTry() *cobra.Command { if err != nil { return err } - dstClientState, err := clientTypes.UnpackClientState(dstClientStateRes.ClientState) + dstClientState, err := clienttypes.UnpackClientState(dstClientStateRes.ClientState) if err != nil { return err } @@ -238,7 +243,7 @@ func connAck() *cobra.Command { if err != nil { return err } - dstClientState, _ := clientTypes.UnpackClientState(dstClientStateResponse.ClientState) + dstClientState, _ := clienttypes.UnpackClientState(dstClientStateResponse.ClientState) dstCsHeight := int64(relayer.MustGetHeight(dstClientState.GetLatestHeight())) // Then we need to query the consensus state for src at that height on dst @@ -469,7 +474,7 @@ func chanAck() *cobra.Command { } txs := []sdk.Msg{ chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()), - chains[src].PathEnd.ChanAck(dstChanState, chains[src].MustGetAddress()), + chains[src].PathEnd.ChanAck(chains[dst].PathEnd, dstChanState, chains[src].MustGetAddress()), } return sendAndPrint(txs, chains[src], cmd) diff --git a/cmd/xfer.go b/cmd/xfer.go index 2bcb2d2f2..1d9422a05 100644 --- a/cmd/xfer.go +++ b/cmd/xfer.go @@ -15,7 +15,7 @@ func xfersend() *cobra.Command { cmd := &cobra.Command{ Use: "transfer [src-chain-id] [dst-chain-id] [amount] [dst-addr]", Short: "Initiate a transfer from one chain to another", - Aliases: []string{"xfer", "txf"}, + Aliases: []string{"xfer", "txf", "send"}, Long: "Sends the first step to transfer tokens in an IBC transfer." + " The created packet must be relayed to another chain", Args: cobra.ExactArgs(4), @@ -40,6 +40,22 @@ func xfersend() *cobra.Command { return err } + srch, err := c[src].QueryLatestHeight() + if err != nil { + return err + } + + dts, err := c[src].QueryDenomTraces(0, 1000, srch) + if err != nil { + return err + } + + for _, d := range dts.DenomTraces { + if amount.Denom == d.GetFullDenomPath() { + amount = sdk.NewCoin(d.IBCDenom(), amount.Amount) + } + } + // TODO: add ability to set timeout height and time from flags // Should be relative to current time and block height // --timeout-height-offset=1000 diff --git a/configs/demo/ibc0.json b/configs/demo/ibc0.json index 601d4ff2e..390b3e83f 100644 --- a/configs/demo/ibc0.json +++ b/configs/demo/ibc0.json @@ -1 +1 @@ -{"key":"testkey","chain-id":"ibc0","rpc-addr":"http://localhost:26657","account-prefix":"cosmos","gas-adjustment":1.5,"trusting-period":"336h"} +{"key":"testkey","chain-id":"ibc0","rpc-addr":"http://localhost:26657","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake","trusting-period":"336h"} diff --git a/configs/demo/ibc1.json b/configs/demo/ibc1.json index 5b44ba18d..f0143d578 100644 --- a/configs/demo/ibc1.json +++ b/configs/demo/ibc1.json @@ -1 +1 @@ -{"key":"testkey","chain-id":"ibc1","rpc-addr":"http://localhost:26557","account-prefix":"cosmos","gas-adjustment":1.5,"trusting-period":"336h"} +{"key":"testkey","chain-id":"ibc1","rpc-addr":"http://localhost:26557","account-prefix":"cosmos","gas-adjustment":1.5,"gas-prices":"0.025stake", "trusting-period":"336h"} diff --git a/dev-env b/dev-env index e940a2d35..7bc2ce464 100755 --- a/dev-env +++ b/dev-env @@ -22,11 +22,5 @@ echo "waiting for blocks..." sleep 3 rly tx full-path demo -d -o 3s -rly tx txf ibc0 ibc1 10000000samoleans $(rly k s ibc1) -rly tx txf ibc0 ibc1 10000000samoleans $(rly k s ibc1) -rly tx txf ibc1 ibc0 10000000samoleans $(rly k s ibc0) -rly tx txf ibc1 ibc0 10000000samoleans $(rly k s ibc0) -sleep 1 -rly tx relay demo -d -rly q bal ibc0 | jq -rly q bal ibc1 | jq \ No newline at end of file +rly tx txf ibc0 ibc1 100000samoleans $(rly ch addr ibc1) +rly tx txf ibc1 ibc0 100000samoleans $(rly ch addr ibc0) \ No newline at end of file diff --git a/docs/config.md b/docs/config.md deleted file mode 100644 index da808a7a1..000000000 --- a/docs/config.md +++ /dev/null @@ -1,96 +0,0 @@ -## Configuration - -### Relayer Home Folder Layout - -The following is the folder structure for the relayer `--home` directory when there are two chains (`ibc0` an `ibc1`) properly configured with keys and light clients - -```bash -~/.relayer -├── config -│   └── config.yaml -├── keys -│   ├── keyring-test-ibc0 -│   └── keyring-test-ibc1 -└── light - ├── ibc0.db - └── ibc1.db -``` - -### Configuring the Relayer - -There are three major parts of `relayer` configuration: - -```go -type Config struct { - Global GlobalConfig `yaml:"global"` - Chains []ChainConfig `yaml:"chains"` - Paths []relayer.Paths `yaml:"paths"` -} -``` - -#### Global Configuration - -- Amount of time to sleep between relayer loops -- Number of block headers to cache for the light client - -> NOTE: Additional global configuration will be added/removed in this section as relayer development progresses - -```go -// NOTE: are there any other items that could be useful here? -type Global struct { - Timeout string `yaml:"timeout"` - LightCacheSize int `yaml:"light-cache-size"` -} -``` - -#### Chains config - -The `ConfigChain` abstraction contains all the necessary data to connect to a given chain, query it's state, and send transactions to it. The config will contain an array of these chains (`[]ChainConfig`). These `ChainConfig` instances will then be converted into the `relayer.Chain` abstration to perform all the necessary tasks. The following data will be needed by each `relayer.Chain` and is passed in via `ChainConfig`s: - -> NOTE: We need to add the chain unbonding time to this struct and `relayer.Chain` as well: https://github.com/cosmos/relayer/issues/56 - -```go -// ChainConfig describes the config necessary for an individual chain -type ChainConfig struct { - Key string `yaml:"key" json:"key"` - ChainID string `yaml:"chain-id" json:"chain-id"` - RPCAddr string `yaml:"rpc-addr" json:"rpc-addr"` - AccountPrefix string `yaml:"account-prefix" json:"account-prefix"` - GasAdjustment float64 `yaml:"gas-adjustment,omitempty" json:"gas-adjustment,omitempty"` - TrustingPeriod string `yaml:"trusting-period" json:"trusting-period"` -} -``` - -> NOTE: This may be a redundent struct. A refactor that could be undertaken would be to replace this with the `relayer.Chain` in the config parsing see: https://github.com/cosmos/relayer/issues/31 - -#### Paths - -The `Paths` in the configuration define which `Path`s the relayer will move packets between. It also defines the `Strategy` that will be used by the relayer. It contains all the identifers necessary to connect two chains: - -```go -// Path represents a pair of chains and the identifiers needed to -// relay over them -type Path struct { - Src *PathEnd `yaml:"src" json:"src"` - Dst *PathEnd `yaml:"dst" json:"dst"` - Strategy *StrategyCfg `yaml:"strategy" json:"strategy"` -} - -// StrategyCfg defines which relaying strategy to take for a given path -type StrategyCfg struct { - Type string `json:"type" yaml:"type"` - Constraints map[string]string `json:"constraints,omitempty" yaml:"constraints,omitempty"` -} - -// PathEnd represents the local connection identifers for a relay path -// The path is set on the chain before performing operations -type PathEnd struct { - ChainID string `yaml:"chain-id,omitempty" json:"chain-id,omitempty"` - ClientID string `yaml:"client-id,omitempty" json:"client-id,omitempty"` - ConnectionID string `yaml:"connection-id,omitempty" json:"connection-id,omitempty"` - ChannelID string `yaml:"channel-id,omitempty" json:"channel-id,omitempty"` - PortID string `yaml:"port-id,omitempty" json:"port-id,omitempty"` -} -``` - -> NOTE: An `Order` field needs to be added to this struct along with support for `UNORDERED` channels: https://github.com/cosmos/relayer/issues/52 \ No newline at end of file diff --git a/go.mod b/go.mod index 6c172d411..cbe0d95ac 100644 --- a/go.mod +++ b/go.mod @@ -6,14 +6,14 @@ require ( github.com/avast/retry-go v2.6.0+incompatible github.com/cenkalti/backoff/v3 v3.2.2 // indirect github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c // indirect - github.com/cosmos/cosmos-sdk v0.34.4-0.20200921130040-27db2cf89772 + github.com/cosmos/cosmos-sdk v0.40.0-rc0 github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d github.com/gorilla/mux v1.8.0 github.com/ory/dockertest/v3 v3.5.5 github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.6.1 - github.com/tendermint/tendermint v0.34.0-rc3.0.20200907055413-3359e0bf2f84 + github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6 github.com/tendermint/tm-db v0.6.2 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index 310a4978f..f4bafab2b 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= -github.com/99designs/keyring v1.1.5 h1:wLv7QyzYpFIyMSwOADq1CLTF9KbjbBfcnfmOGJ64aO4= -github.com/99designs/keyring v1.1.5/go.mod h1:7hsVvt2qXgtadGevGJ4ujg+u8m6SpJ5TpHqTozIPqf0= +github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM= +github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= @@ -124,8 +124,9 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.34.4-0.20200921130040-27db2cf89772 h1:i+YbJKkZ1Z9HYxc9hCV06Squc51Dyb/9sYWA7etYjO0= -github.com/cosmos/cosmos-sdk v0.34.4-0.20200921130040-27db2cf89772/go.mod h1:3bfA/vO+QD9jYFBt/RmBEvbeFHoM8HQWHfZnGx4lOTc= +github.com/cosmos/cosmos-sdk v0.39.1 h1:vhjf9PZh9ph8btAj9aBpHoVITgVVjNBpM3x5Gl/Vwac= +github.com/cosmos/cosmos-sdk v0.40.0-rc0 h1:GY+jzuVILZ7wlx5Zic2W0rWlo47fZgN048xV458sUAo= +github.com/cosmos/cosmos-sdk v0.40.0-rc0/go.mod h1:YZcO00Tq/qqj4ncsfn+PobyTelsot7wEMGPpxEbEAT0= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/iavl v0.15.0-rc3 h1:rSm60IFfDCD9qDfvXKEmaJhcv0rB5uCbVlBDKsynxqw= @@ -164,8 +165,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a h1:mq+R6XEM6lJX5VlLyZIrUSP8tSuJp82xTK89hvBwJbU= -github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= +github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b h1:HBah4D48ypg3J7Np4N+HY/ZR76fx3HEUGxDU6Uk39oQ= +github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= @@ -283,8 +284,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY= github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU= -github.com/grpc-ecosystem/grpc-gateway v1.14.8 h1:hXClj+iFpmLM8i3lkO6i4Psli4P2qObQuQReiII26U8= -github.com/grpc-ecosystem/grpc-gateway v1.14.8/go.mod h1:NZE8t6vs6TnwLL/ITkaK8W3ecMLGAbh2jXTclvpiwYo= +github.com/grpc-ecosystem/grpc-gateway v1.15.0 h1:ntPNC9TD/6l2XDenJZe6T5lSMg95thpV9sGAqHX4WU8= +github.com/grpc-ecosystem/grpc-gateway v1.15.0/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s= @@ -372,8 +373,8 @@ github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0Q github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/magiconair/properties v1.8.3 h1:kJSsc6EXkBLgr3SphHk9w5mtjn0bjlR4JYEXKrJ45rQ= -github.com/magiconair/properties v1.8.3/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= +github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -387,6 +388,8 @@ github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 h1:hLDRPB66XQT/8+wG github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/minio/highwayhash v1.0.0 h1:iMSDhgUILCr0TNm8LWlSjF8N0ZIj2qbO8WHp6Q/J2BA= github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc= +github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= +github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -504,8 +507,8 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2 github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.13.0 h1:vJlpe9wPgDRM1Z+7Wj3zUUjY1nr6/1jNKyl7llliccg= -github.com/prometheus/common v0.13.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= +github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= +github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -603,10 +606,11 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RM github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/tendermint v0.33.8 h1:Xxu4QhpqcomSE0iQDw1MqLgfsa8fqtPtWFJK6zZOVso= github.com/tendermint/tendermint v0.34.0-rc3 h1:d7Fsd5rdbxq4GmJ0kRfx7l7LesQM7e70f0ytWLTQ/Go= github.com/tendermint/tendermint v0.34.0-rc3/go.mod h1:BoHcEpjfpBHc1Be7RQz3AHaXFNObcDG7SNHCev6Or4g= -github.com/tendermint/tendermint v0.34.0-rc3.0.20200907055413-3359e0bf2f84 h1:BI/EhLLh6SAlOtMaHePo8BNFLsNRiFNCtJ8cMBX+OE8= -github.com/tendermint/tendermint v0.34.0-rc3.0.20200907055413-3359e0bf2f84/go.mod h1:ZgOz3PoriH5yHRJmUmhDTVX8ps4+hzFvhmDq6MDUHxU= +github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6 h1:gqZ0WDpDYgMm/iaiMEXvI1nt/GoWCuwtBomVpUMiAIs= +github.com/tendermint/tendermint v0.34.0-rc4.0.20201005135527-d7d0ffea13c6/go.mod h1:BSXqR6vWbOecet726v66qVwSkFDLfEeBrq+EhkKbij4= github.com/tendermint/tm-db v0.6.1 h1:w3X87itMPXopcRPlFiqspEKhw4FXihPk2rnFFkP0zGk= github.com/tendermint/tm-db v0.6.1/go.mod h1:m3x9kRP4UFd7JODJL0yBAZqE7wTw+S37uAE90cTx7OA= github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= @@ -723,6 +727,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 h1:Bx6FllMpG4NWDOfhMBz1VR2QYNp/SAOHPIAsaVmxfPo= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/relayer/chain.go b/relayer/chain.go index a0be5d59d..211c55076 100644 --- a/relayer/chain.go +++ b/relayer/chain.go @@ -35,6 +35,7 @@ type Chain struct { RPCAddr string `yaml:"rpc-addr" json:"rpc-addr"` AccountPrefix string `yaml:"account-prefix" json:"account-prefix"` GasAdjustment float64 `yaml:"gas-adjustment" json:"gas-adjustment"` + GasPrices string `yaml:"gas-prices" json:"gas-prices"` TrustingPeriod string `yaml:"trusting-period" json:"trusting-period"` // TODO: make these private @@ -149,6 +150,11 @@ func (c *Chain) Init(homePath string, timeout time.Duration, debug bool) error { return fmt.Errorf("failed to parse trusting period (%s) for chain %s", c.TrustingPeriod, c.ChainID) } + _, err = sdk.ParseDecCoins(c.GasPrices) + if err != nil { + return fmt.Errorf("failed to parse gas prices (%s) for chain %s", c.GasPrices, c.ChainID) + } + encodingConfig := simapp.MakeEncodingConfig() c.Keybase = keybase @@ -278,6 +284,7 @@ func (c *Chain) TxFactory(height int64) tx.Factory { WithChainID(c.ChainID). WithTxConfig(ctx.TxConfig). WithGasAdjustment(c.GasAdjustment). + WithGasPrices(c.GasPrices). WithKeybase(c.Keybase). WithSignMode(signing.SignMode_SIGN_MODE_DIRECT) } @@ -376,6 +383,12 @@ func (c *Chain) Update(key, value string) (out *Chain, err error) { return nil, err } out.GasAdjustment = adj + case "gas-prices": + _, err = sdk.ParseDecCoins(value) + if err != nil { + return nil, err + } + out.GasPrices = value case "account-prefix": out.AccountPrefix = value case "trusting-period": @@ -514,7 +527,7 @@ func (c *Chain) GetTimeout() time.Duration { // StatusErr returns err unless the chain is ready to go func (c *Chain) StatusErr() error { - stat, err := c.Client.Status() + stat, err := c.Client.Status(context.Background()) switch { case err != nil: return err diff --git a/relayer/channel-tx.go b/relayer/channel-tx.go index dac6d0e5b..7224c5427 100644 --- a/relayer/channel-tx.go +++ b/relayer/channel-tx.go @@ -4,19 +4,19 @@ import ( "fmt" "time" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "golang.org/x/sync/errgroup" ) // CreateChannel runs the channel creation messages on timeout until they pass // TODO: add max retries or something to this function func (c *Chain) CreateChannel(dst *Chain, ordered bool, to time.Duration) error { - var order chanTypes.Order + var order chantypes.Order if ordered { - order = chanTypes.ORDERED + order = chantypes.ORDERED } else { - order = chanTypes.UNORDERED + order = chantypes.UNORDERED } ticker := time.NewTicker(to) @@ -37,7 +37,11 @@ func (c *Chain) CreateChannel(dst *Chain, ordered bool, to time.Duration) error // In the case of success and this being the last transaction // debug logging, log created connection and break case chanSteps.success && chanSteps.last: - srcChan, dstChan, err := QueryChannelPair(c, dst, 0, 0) + srch, dsth, err := GetLatestLightHeights(c, dst) + if err != nil { + return err + } + srcChan, dstChan, err := QueryChannelPair(c, dst, srch, dsth) if err != nil { return err } @@ -69,13 +73,13 @@ func (c *Chain) CreateChannel(dst *Chain, ordered bool, to time.Duration) error // CreateChannelStep returns the next set of messages for creating a channel with given // identifiers between chains src and dst. If the handshake hasn't started, then CreateChannelStep // will begin the handshake on the src chain -func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayMsgs, error) { +func (c *Chain) CreateChannelStep(dst *Chain, ordering chantypes.Order) (*RelayMsgs, error) { out := NewRelayMsgs() if err := ValidatePaths(c, dst); err != nil { return nil, err } - srch, dsth, err := UpdatesWithHeaders(c, dst) + sh, err := NewSyncHeaders(c, dst) if err != nil { return nil, err } @@ -84,16 +88,16 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM var ( eg = new(errgroup.Group) srcUpdateHeader, dstUpdateHeader *tmclient.Header - srcChan, dstChan *chanTypes.QueryChannelResponse + srcChan, dstChan *chantypes.QueryChannelResponse ) eg.Go(func() error { - srcUpdateHeader, dstUpdateHeader, err = InjectTrustedFieldsHeaders(c, dst, srch, dsth) + srcUpdateHeader, dstUpdateHeader, err = sh.GetTrustedHeaders(c, dst) return err }) eg.Go(func() error { - srcChan, dstChan, err = QueryChannelPair(c, dst, srch.Header.Height-1, dsth.Header.Height-1) + srcChan, dstChan, err = QueryChannelPair(c, dst, int64(sh.GetHeight(c.ChainID))-1, int64(sh.GetHeight(dst.ChainID))-1) return err }) @@ -103,7 +107,7 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM switch { // Handshake hasn't been started on src or dst, relay `chanOpenInit` to src - case srcChan.Channel.State == chanTypes.UNINITIALIZED && dstChan.Channel.State == chanTypes.UNINITIALIZED: + case srcChan.Channel.State == chantypes.UNINITIALIZED && dstChan.Channel.State == chantypes.UNINITIALIZED: if c.debug { logChannelStates(c, dst, srcChan, dstChan) } @@ -112,7 +116,7 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM ) // Handshake has started on dst (1 step done), relay `chanOpenTry` and `updateClient` to src - case srcChan.Channel.State == chanTypes.UNINITIALIZED && dstChan.Channel.State == chanTypes.INIT: + case srcChan.Channel.State == chantypes.UNINITIALIZED && dstChan.Channel.State == chantypes.INIT: if c.debug { logChannelStates(c, dst, srcChan, dstChan) } @@ -122,7 +126,7 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM ) // Handshake has started on src (1 step done), relay `chanOpenTry` and `updateClient` to dst - case srcChan.Channel.State == chanTypes.INIT && dstChan.Channel.State == chanTypes.UNINITIALIZED: + case srcChan.Channel.State == chantypes.INIT && dstChan.Channel.State == chantypes.UNINITIALIZED: if dst.debug { logChannelStates(dst, c, dstChan, srcChan) } @@ -132,27 +136,27 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM ) // Handshake has started on src (2 steps done), relay `chanOpenAck` and `updateClient` to dst - case srcChan.Channel.State == chanTypes.TRYOPEN && dstChan.Channel.State == chanTypes.INIT: + case srcChan.Channel.State == chantypes.TRYOPEN && dstChan.Channel.State == chantypes.INIT: if dst.debug { logChannelStates(dst, c, dstChan, srcChan) } out.Dst = append(out.Dst, dst.PathEnd.UpdateClient(srcUpdateHeader, dst.MustGetAddress()), - dst.PathEnd.ChanAck(srcChan, dst.MustGetAddress()), + dst.PathEnd.ChanAck(c.PathEnd, srcChan, dst.MustGetAddress()), ) // Handshake has started on dst (2 steps done), relay `chanOpenAck` and `updateClient` to src - case srcChan.Channel.State == chanTypes.INIT && dstChan.Channel.State == chanTypes.TRYOPEN: + case srcChan.Channel.State == chantypes.INIT && dstChan.Channel.State == chantypes.TRYOPEN: if c.debug { logChannelStates(c, dst, srcChan, dstChan) } out.Src = append(out.Src, c.PathEnd.UpdateClient(dstUpdateHeader, c.MustGetAddress()), - c.PathEnd.ChanAck(dstChan, c.MustGetAddress()), + c.PathEnd.ChanAck(dst.PathEnd, dstChan, c.MustGetAddress()), ) // Handshake has confirmed on dst (3 steps done), relay `chanOpenConfirm` and `updateClient` to src - case srcChan.Channel.State == chanTypes.TRYOPEN && dstChan.Channel.State == chanTypes.OPEN: + case srcChan.Channel.State == chantypes.TRYOPEN && dstChan.Channel.State == chantypes.OPEN: if c.debug { logChannelStates(c, dst, srcChan, dstChan) } @@ -163,7 +167,7 @@ func (c *Chain) CreateChannelStep(dst *Chain, ordering chanTypes.Order) (*RelayM out.last = true // Handshake has confirmed on src (3 steps done), relay `chanOpenConfirm` and `updateClient` to dst - case srcChan.Channel.State == chanTypes.OPEN && dstChan.Channel.State == chanTypes.TRYOPEN: + case srcChan.Channel.State == chantypes.OPEN && dstChan.Channel.State == chantypes.TRYOPEN: if dst.debug { logChannelStates(dst, c, dstChan, srcChan) } @@ -218,7 +222,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { return nil, err } - srch, dsth, err := UpdatesWithHeaders(c, dst) + sh, err := NewSyncHeaders(c, dst) if err != nil { return nil, err } @@ -227,17 +231,17 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { var ( eg = new(errgroup.Group) srcUpdateHeader, dstUpdateHeader *tmclient.Header - srcChan, dstChan *chanTypes.QueryChannelResponse + srcChan, dstChan *chantypes.QueryChannelResponse ) eg.Go(func() error { // create the UpdateHeaders for src and dest Chains - srcUpdateHeader, dstUpdateHeader, err = InjectTrustedFieldsHeaders(c, dst, srch, dsth) + srcUpdateHeader, dstUpdateHeader, err = sh.GetTrustedHeaders(c, dst) return err }) eg.Go(func() error { - srcChan, dstChan, err = QueryChannelPair(c, dst, srch.Header.Height, dsth.Header.Height) + srcChan, dstChan, err = QueryChannelPair(c, dst, int64(sh.GetHeight(c.ChainID)), int64(sh.GetHeight(dst.ChainID))) return err }) @@ -250,8 +254,8 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { switch { // Closing handshake has not started, relay `updateClient` and `chanCloseInit` to src or dst according // to the channel state - case srcChan.Channel.State != chanTypes.CLOSED && dstChan.Channel.State != chanTypes.CLOSED: - if srcChan.Channel.State != chanTypes.UNINITIALIZED { + case srcChan.Channel.State != chantypes.CLOSED && dstChan.Channel.State != chantypes.CLOSED: + if srcChan.Channel.State != chantypes.UNINITIALIZED { if c.debug { logChannelStates(c, dst, srcChan, dstChan) } @@ -259,7 +263,7 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { c.PathEnd.UpdateClient(dstUpdateHeader, c.MustGetAddress()), c.PathEnd.ChanCloseInit(c.MustGetAddress()), ) - } else if dstChan.Channel.State != chanTypes.UNINITIALIZED { + } else if dstChan.Channel.State != chantypes.UNINITIALIZED { if dst.debug { logChannelStates(dst, c, dstChan, srcChan) } @@ -270,8 +274,8 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } // Closing handshake has started on src, relay `updateClient` and `chanCloseConfirm` to dst - case srcChan.Channel.State == chanTypes.CLOSED && dstChan.Channel.State != chanTypes.CLOSED: - if dstChan.Channel.State != chanTypes.UNINITIALIZED { + case srcChan.Channel.State == chantypes.CLOSED && dstChan.Channel.State != chantypes.CLOSED: + if dstChan.Channel.State != chantypes.UNINITIALIZED { if dst.debug { logChannelStates(dst, c, dstChan, srcChan) } @@ -283,8 +287,8 @@ func (c *Chain) CloseChannelStep(dst *Chain) (*RelayMsgs, error) { } // Closing handshake has started on dst, relay `updateClient` and `chanCloseConfirm` to src - case dstChan.Channel.State == chanTypes.CLOSED && srcChan.Channel.State != chanTypes.CLOSED: - if srcChan.Channel.State != chanTypes.UNINITIALIZED { + case dstChan.Channel.State == chantypes.CLOSED && srcChan.Channel.State != chantypes.CLOSED: + if srcChan.Channel.State != chantypes.UNINITIALIZED { if c.debug { logChannelStates(c, dst, srcChan, dstChan) } diff --git a/relayer/client-tx.go b/relayer/client-tx.go index 94bfdf976..851f6e00d 100644 --- a/relayer/client-tx.go +++ b/relayer/client-tx.go @@ -29,12 +29,17 @@ func (c *Chain) CreateClients(dst *Chain) (err error) { if err != nil { return err } + consensusParams, err := dst.QueryConsensusParams() + if err != nil { + return err + } clients.Src = append( clients.Src, c.PathEnd.CreateClient( dstH, dst.GetTrustingPeriod(), ubdPeriod, + consensusParams, c.MustGetAddress(), )) } @@ -51,12 +56,17 @@ func (c *Chain) CreateClients(dst *Chain) (err error) { if err != nil { return err } + consensusParams, err := c.QueryConsensusParams() + if err != nil { + return err + } clients.Dst = append( clients.Dst, dst.PathEnd.CreateClient( srcH, c.GetTrustingPeriod(), ubdPeriod, + consensusParams, dst.MustGetAddress(), )) } @@ -82,12 +92,12 @@ func (c *Chain) CreateClients(dst *Chain) (err error) { func (c *Chain) UpdateClients(dst *Chain) (err error) { clients := &RelayMsgs{Src: []sdk.Msg{}, Dst: []sdk.Msg{}} - srcH, dstH, err := UpdatesWithHeaders(c, dst) + sh, err := NewSyncHeaders(c, dst) if err != nil { return err } - srcUH, dstUH, err := InjectTrustedFieldsHeaders(c, dst, srcH, dstH) + srcUH, dstUH, err := sh.GetTrustedHeaders(c, dst) if err != nil { return err } diff --git a/relayer/connection-tx.go b/relayer/connection-tx.go index 5a2efacb0..67f0bf77a 100644 --- a/relayer/connection-tx.go +++ b/relayer/connection-tx.go @@ -4,10 +4,11 @@ import ( "fmt" "time" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - connTypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - ibcExported "github.com/cosmos/cosmos-sdk/x/ibc/exported" + retry "github.com/avast/retry-go" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "golang.org/x/sync/errgroup" ) @@ -33,7 +34,11 @@ func (c *Chain) CreateConnection(dst *Chain, to time.Duration) error { // debug logging, log created connection and break case connSteps.success && connSteps.last: if c.debug { - srcConn, dstConn, err := QueryConnectionPair(c, dst, 0, 0) + srcH, dstH, err := GetLatestLightHeights(c, dst) + if err != nil { + return err + } + srcConn, dstConn, err := QueryConnectionPair(c, dst, srcH, dstH) if err != nil { return err } @@ -72,7 +77,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { } // First, update the light clients to the latest header and return the header - srch, dsth, err := UpdatesWithHeaders(c, dst) + sh, err := NewSyncHeaders(c, dst) if err != nil { return nil, err } @@ -81,22 +86,29 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { var ( eg = new(errgroup.Group) srcUpdateHeader, dstUpdateHeader *tmclient.Header - srcConn, dstConn *connTypes.QueryConnectionResponse - srcCsRes, dstCsRes *clientTypes.QueryClientStateResponse - srcCS, dstCS ibcExported.ClientState - srcCons, dstCons *clientTypes.QueryConsensusStateResponse + srcConn, dstConn *conntypes.QueryConnectionResponse + srcCsRes, dstCsRes *clienttypes.QueryClientStateResponse + srcCS, dstCS ibcexported.ClientState + srcCons, dstCons *clienttypes.QueryConsensusStateResponse srcConsH, dstConsH int64 ) // create the UpdateHeaders for src and dest Chains eg.Go(func() error { - srcUpdateHeader, dstUpdateHeader, err = InjectTrustedFieldsHeaders(c, dst, srch, dsth) + var err error + retry.Do(func() error { + srcUpdateHeader, dstUpdateHeader, err = sh.GetTrustedHeaders(c, dst) + if err != nil { + sh.Updates(c, dst) + } + return err + }) return err }) // Query Connection data from src and dst eg.Go(func() error { - srcConn, dstConn, err = QueryConnectionPair(c, dst, srch.Header.Height-1, dsth.Header.Height-1) + srcConn, dstConn, err = QueryConnectionPair(c, dst, int64(sh.GetHeight(c.ChainID))-1, int64(sh.GetHeight(dst.ChainID))-1) return err }) @@ -105,17 +117,17 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { return nil, err } - if !(srcConn.Connection.State == connTypes.UNINITIALIZED && dstConn.Connection.State == connTypes.UNINITIALIZED) { + if !(srcConn.Connection.State == conntypes.UNINITIALIZED && dstConn.Connection.State == conntypes.UNINITIALIZED) { // Query client state from each chain's client - srcCsRes, dstCsRes, err = QueryClientStatePair(c, dst, srch.Header.Height-1, dsth.Header.Height-1) + srcCsRes, dstCsRes, err = QueryClientStatePair(c, dst, int64(sh.GetHeight(c.ChainID))-1, int64(sh.GetHeight(dst.ChainID))-1) if err != nil && (srcCsRes == nil || dstCsRes == nil) { return nil, err } - srcCS, err = clientTypes.UnpackClientState(srcCsRes.ClientState) + srcCS, err = clienttypes.UnpackClientState(srcCsRes.ClientState) if err != nil { return nil, err } - dstCS, err = clientTypes.UnpackClientState(dstCsRes.ClientState) + dstCS, err = clienttypes.UnpackClientState(dstCsRes.ClientState) if err != nil { return nil, err } @@ -126,7 +138,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { // NOTE: We query connection at height - 1 because of the way tendermint returns // proofs the commit for height n is contained in the header of height n + 1 srcCons, dstCons, err = QueryClientConsensusStatePair( - c, dst, srch.Header.Height-1, dsth.Header.Height-1, srcConsH, dstConsH) + c, dst, int64(sh.GetHeight(c.ChainID))-1, int64(sh.GetHeight(dst.ChainID))-1, srcConsH, dstConsH) if err != nil { return nil, err } @@ -134,14 +146,14 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { switch { // Handshake hasn't been started on src or dst, relay `connOpenInit` to src - case srcConn.Connection.State == connTypes.UNINITIALIZED && dstConn.Connection.State == connTypes.UNINITIALIZED: + case srcConn.Connection.State == conntypes.UNINITIALIZED && dstConn.Connection.State == conntypes.UNINITIALIZED: if c.debug { logConnectionStates(c, dst, srcConn, dstConn) } out.Src = append(out.Src, c.PathEnd.ConnInit(dst.PathEnd, c.MustGetAddress())) // Handshake has started on dst (1 stepdone), relay `connOpenTry` and `updateClient` on src - case srcConn.Connection.State == connTypes.UNINITIALIZED && dstConn.Connection.State == connTypes.INIT: + case srcConn.Connection.State == conntypes.UNINITIALIZED && dstConn.Connection.State == conntypes.INIT: if c.debug { logConnectionStates(c, dst, srcConn, dstConn) } @@ -152,7 +164,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { ) // Handshake has started on src (1 step done), relay `connOpenTry` and `updateClient` on dst - case srcConn.Connection.State == connTypes.INIT && dstConn.Connection.State == connTypes.UNINITIALIZED: + case srcConn.Connection.State == conntypes.INIT && dstConn.Connection.State == conntypes.UNINITIALIZED: if dst.debug { logConnectionStates(dst, c, dstConn, srcConn) } @@ -163,7 +175,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { ) // Handshake has started on src end (2 steps done), relay `connOpenAck` and `updateClient` to dst end - case srcConn.Connection.State == connTypes.TRYOPEN && dstConn.Connection.State == connTypes.INIT: + case srcConn.Connection.State == conntypes.TRYOPEN && dstConn.Connection.State == conntypes.INIT: if dst.debug { logConnectionStates(dst, c, dstConn, srcConn) } @@ -173,7 +185,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { ) // Handshake has started on dst end (2 steps done), relay `connOpenAck` and `updateClient` to src end - case srcConn.Connection.State == connTypes.INIT && dstConn.Connection.State == connTypes.TRYOPEN: + case srcConn.Connection.State == conntypes.INIT && dstConn.Connection.State == conntypes.TRYOPEN: if c.debug { logConnectionStates(c, dst, srcConn, dstConn) } @@ -183,7 +195,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { ) // Handshake has confirmed on dst (3 steps done), relay `connOpenConfirm` and `updateClient` to src end - case srcConn.Connection.State == connTypes.TRYOPEN && dstConn.Connection.State == connTypes.OPEN: + case srcConn.Connection.State == conntypes.TRYOPEN && dstConn.Connection.State == conntypes.OPEN: if c.debug { logConnectionStates(c, dst, srcConn, dstConn) } @@ -194,7 +206,7 @@ func (c *Chain) CreateConnectionStep(dst *Chain) (*RelayMsgs, error) { out.last = true // Handshake has confirmed on src (3 steps done), relay `connOpenConfirm` and `updateClient` to dst end - case srcConn.Connection.State == connTypes.OPEN && dstConn.Connection.State == connTypes.TRYOPEN: + case srcConn.Connection.State == conntypes.OPEN && dstConn.Connection.State == conntypes.TRYOPEN: if dst.debug { logConnectionStates(dst, c, dstConn, srcConn) } diff --git a/relayer/faucet.go b/relayer/faucet.go index a0bc0e6b2..30a5cab58 100644 --- a/relayer/faucet.go +++ b/relayer/faucet.go @@ -13,6 +13,7 @@ import ( // SendMsgWithKey allows the user to specify which relayer key will sign the message func (c *Chain) SendMsgWithKey(msg sdk.Msg, keyName string) (res *sdk.TxResponse, err error) { + fmt.Println("setting use of key", keyName) c.Key = keyName return c.SendMsg(msg) @@ -75,12 +76,15 @@ func (c *Chain) faucetSend(fromAddr, toAddr sdk.AccAddress, amounts sdk.Coins) e return err } + fmt.Println("From Address", fromAddr.String()) + fmt.Println("To Address", toAddr.String()) + fmt.Println("Amount", amounts) res, err := c.SendMsgWithKey(bank.NewMsgSend(fromAddr, toAddr, sdk.NewCoins(amounts...)), info.GetName()) if err != nil { - return fmt.Errorf("failed to send transaction: %w\n%s", err, res) + return fmt.Errorf("%w:%s", err, res.RawLog) } else if res.Code != 0 { - return fmt.Errorf("transaction failed to execute\n%s", res) + return fmt.Errorf("%s", res.RawLog) } return nil } diff --git a/relayer/headers.go b/relayer/headers.go index 2a3b15e5f..aa2d63ceb 100644 --- a/relayer/headers.go +++ b/relayer/headers.go @@ -3,9 +3,9 @@ package relayer import ( "sync" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - clientExported "github.com/cosmos/cosmos-sdk/x/ibc/exported" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" "golang.org/x/sync/errgroup" ) @@ -109,17 +109,22 @@ func InjectTrustedFields(srcChain, dstChain *Chain, srcHeader *tmclient.Header) // make copy of header stored in mop h := *(srcHeader) + dsth, err := dstChain.GetLatestLightHeight() + if err != nil { + return nil, err + } // retrieve counterparty client from dst chain - counterpartyClientRes, err := dstChain.QueryClientState(0) + counterpartyClientRes, err := dstChain.QueryClientState(dsth) if err != nil { return nil, err } - cs, err := clientTypes.UnpackClientState(counterpartyClientRes.ClientState) + cs, err := clienttypes.UnpackClientState(counterpartyClientRes.ClientState) if err != nil { panic(err) } // inject TrustedHeight as latest height stored on counterparty client - h.TrustedHeight = cs.GetLatestHeight().(clientTypes.Height) + h.TrustedHeight = cs.GetLatestHeight().(clienttypes.Height) + // query TrustedValidators at Trusted Height from srcChain valSet, err := srcChain.QueryValsetAtHeight(h.TrustedHeight) if err != nil { @@ -131,10 +136,10 @@ func InjectTrustedFields(srcChain, dstChain *Chain, srcHeader *tmclient.Header) } // MustGetHeight takes the height inteface and returns the actual height -func MustGetHeight(h clientExported.Height) uint64 { - height, ok := h.(clientTypes.Height) +func MustGetHeight(h ibcexported.Height) uint64 { + height, ok := h.(clienttypes.Height) if !ok { panic("height is not an instance of height! wtf") } - return height.EpochHeight + return height.GetVersionHeight() } diff --git a/relayer/ics24.go b/relayer/ics24.go index 5b20af079..aeefcad77 100644 --- a/relayer/ics24.go +++ b/relayer/ics24.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host" ) // Vclient validates the client identifier in the path diff --git a/relayer/log-tx.go b/relayer/log-tx.go index d6b223a32..e443c6a2e 100644 --- a/relayer/log-tx.go +++ b/relayer/log-tx.go @@ -6,8 +6,8 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" - connTypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" ) // LogFailedTx takes the transaction and the messages to create it and logs the appropriate data @@ -45,7 +45,7 @@ func (c *Chain) logPacketsRelayed(dst *Chain, num int) { num, dst.ChainID, dst.PathEnd.PortID, c.ChainID, c.PathEnd.PortID)) } -func logChannelStates(src, dst *Chain, srcChan, dstChan *chanTypes.QueryChannelResponse) { +func logChannelStates(src, dst *Chain, srcChan, dstChan *chantypes.QueryChannelResponse) { // TODO: replace channelID with portID? src.Log(fmt.Sprintf("- [%s]@{%d}chan(%s)-{%s} : [%s]@{%d}chan(%s)-{%s}", src.ChainID, @@ -59,7 +59,7 @@ func logChannelStates(src, dst *Chain, srcChan, dstChan *chanTypes.QueryChannelR )) } -func logConnectionStates(src, dst *Chain, srcConn, dstConn *connTypes.QueryConnectionResponse) { +func logConnectionStates(src, dst *Chain, srcConn, dstConn *conntypes.QueryConnectionResponse) { src.Log(fmt.Sprintf("- [%s]@{%d}conn(%s)-{%s} : [%s]@{%d}conn(%s)-{%s}", src.ChainID, MustGetHeight(srcConn.ProofHeight), diff --git a/relayer/naive-strategy.go b/relayer/naive-strategy.go index 153b57aa6..64c8d5c08 100644 --- a/relayer/naive-strategy.go +++ b/relayer/naive-strategy.go @@ -8,7 +8,8 @@ import ( retry "github.com/avast/retry-go" sdk "github.com/cosmos/cosmos-sdk/types" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" ctypes "github.com/tendermint/tendermint/rpc/core/types" "golang.org/x/sync/errgroup" ) @@ -45,7 +46,7 @@ func (nrs *NaiveStrategy) UnrelayedSequencesOrdered(src, dst *Chain, sh *SyncHea ) eg.Go(func() error { - var res *chanTypes.QueryPacketCommitmentsResponse + var res *chantypes.QueryPacketCommitmentsResponse if err = retry.Do(func() error { res, err = src.QueryPacketCommitments(0, 1000, sh.GetHeight(src.ChainID)) if err != nil || res == nil { @@ -62,7 +63,7 @@ func (nrs *NaiveStrategy) UnrelayedSequencesOrdered(src, dst *Chain, sh *SyncHea }) eg.Go(func() error { - var res *chanTypes.QueryPacketCommitmentsResponse + var res *chantypes.QueryPacketCommitmentsResponse if err = retry.Do(func() error { res, err = dst.QueryPacketCommitments(0, 1000, sh.GetHeight(dst.ChainID)) if err != nil || res == nil { @@ -140,11 +141,11 @@ func relayPacketsFromEventListener(src, dst *PathEnd, events map[string][]string // finally, get and parse the timeout if sval, ok := events["send_packet.packet_timeout_height"]; ok { - timeout, err := strconv.ParseUint(sval[i], 10, 64) + timeout, err := clienttypes.ParseHeight(sval[i]) if err != nil { return nil, err } - rp.timeout = timeout + rp.timeout = MustGetHeight(timeout) } // finally, get and parse the timeout @@ -190,11 +191,11 @@ func relayPacketsFromEventListener(src, dst *PathEnd, events map[string][]string // finally, get and parse the timeout if sval, ok := events["recv_packet.packet_timeout_height"]; ok { - timeout, err := strconv.ParseUint(sval[i], 10, 64) + timeout, err := clienttypes.ParseHeight(sval[i]) if err != nil { return nil, err } - rp.timeout = timeout + rp.timeout = MustGetHeight(timeout) } // finally, get and parse the timeout @@ -215,6 +216,7 @@ func relayPacketsFromEventListener(src, dst *PathEnd, events map[string][]string } func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []relayPacket, sh *SyncHeaders) { + // fetch the proofs for the relayPackets for _, rp := range rlyPackets { if err := rp.FetchCommitResponse(src, dst, sh); err != nil { @@ -226,7 +228,10 @@ func (nrs *NaiveStrategy) sendTxFromEventPackets(src, dst *Chain, rlyPackets []r // send the transaction, retrying if not successful if err := retry.Do(func() error { - updateHeader, err := sh.GetUpdateHeader(src, dst) + if err := sh.Updates(src, dst); err != nil { + return err + } + updateHeader, err := sh.GetUpdateHeader(dst, src) if err != nil { return err } diff --git a/relayer/packet-tx.go b/relayer/packet-tx.go index 63255a2e7..5c926a055 100644 --- a/relayer/packet-tx.go +++ b/relayer/packet-tx.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - commitmentypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" + commitmentypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" ) var ( diff --git a/relayer/path.go b/relayer/path.go index 6a8ef50d3..cec4f4926 100644 --- a/relayer/path.go +++ b/relayer/path.go @@ -5,7 +5,7 @@ import ( "gopkg.in/yaml.v2" - chantypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" ) // Paths represent connection paths between chains diff --git a/relayer/pathEnd.go b/relayer/pathEnd.go index 780998125..fc3d973b5 100644 --- a/relayer/pathEnd.go +++ b/relayer/pathEnd.go @@ -5,17 +5,18 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - xferTypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - connTypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - "github.com/cosmos/cosmos-sdk/x/ibc/exported" + transfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" + commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" + ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/light" ) -// TODO: add Order chanTypes.Order as a property and wire it up in validation +// TODO: add Order chantypes.Order as a property and wire it up in validation // as well as in the transaction commands // PathEnd represents the local connection identifers for a relay path @@ -31,27 +32,27 @@ type PathEnd struct { } // OrderFromString parses a string into a channel order byte -func OrderFromString(order string) chanTypes.Order { +func OrderFromString(order string) chantypes.Order { switch order { case "UNORDERED": - return chanTypes.UNORDERED + return chantypes.UNORDERED case "ORDERED": - return chanTypes.ORDERED + return chantypes.ORDERED default: - return chanTypes.NONE + return chantypes.NONE } } -func (pe *PathEnd) getOrder() chanTypes.Order { +func (pe *PathEnd) getOrder() chantypes.Order { return OrderFromString(strings.ToUpper(pe.Order)) } // UpdateClient creates an sdk.Msg to update the client on src with data pulled from dst -func (pe *PathEnd) UpdateClient(dstHeader exported.Header, signer sdk.AccAddress) sdk.Msg { +func (pe *PathEnd) UpdateClient(dstHeader ibcexported.Header, signer sdk.AccAddress) sdk.Msg { if err := dstHeader.ValidateBasic(); err != nil { panic(err) } - msg, err := clientTypes.NewMsgUpdateClient( + msg, err := clienttypes.NewMsgUpdateClient( pe.ClientID, dstHeader, signer, @@ -66,6 +67,7 @@ func (pe *PathEnd) UpdateClient(dstHeader exported.Header, signer sdk.AccAddress func (pe *PathEnd) CreateClient( dstHeader *tmclient.Header, trustingPeriod, unbondingPeriod time.Duration, + consensusParams *abci.ConsensusParams, signer sdk.AccAddress) sdk.Msg { if err := dstHeader.ValidateBasic(); err != nil { panic(err) @@ -78,14 +80,16 @@ func (pe *PathEnd) CreateClient( tmclient.NewFractionFromTm(light.DefaultTrustLevel), trustingPeriod, unbondingPeriod, - time.Minute*1, - dstHeader.GetHeight().(clientTypes.Height), + time.Minute*10, + dstHeader.GetHeight().(clienttypes.Height), + consensusParams, commitmenttypes.GetSDKSpecs(), + "upgrade/upgradedClient", false, false, ) - msg, err := clientTypes.NewMsgCreateClient( + msg, err := clienttypes.NewMsgCreateClient( pe.ClientID, clientState, dstHeader.ConsensusState(), @@ -103,12 +107,13 @@ func (pe *PathEnd) CreateClient( // ConnInit creates a MsgConnectionOpenInit func (pe *PathEnd) ConnInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg { - return connTypes.NewMsgConnectionOpenInit( + return conntypes.NewMsgConnectionOpenInit( pe.ConnectionID, pe.ClientID, dst.ConnectionID, dst.ClientID, defaultChainPrefix, + "", signer, ) } @@ -117,28 +122,29 @@ func (pe *PathEnd) ConnInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg { // NOTE: ADD NOTE ABOUT PROOF HEIGHT CHANGE HERE func (pe *PathEnd) ConnTry( dst *PathEnd, - dstClientState *clientTypes.QueryClientStateResponse, - dstConnState *connTypes.QueryConnectionResponse, - dstConsState *clientTypes.QueryConsensusStateResponse, + dstClientState *clienttypes.QueryClientStateResponse, + dstConnState *conntypes.QueryConnectionResponse, + dstConsState *clienttypes.QueryConsensusStateResponse, signer sdk.AccAddress, ) sdk.Msg { - cs, err := clientTypes.UnpackClientState(dstClientState.ClientState) + cs, err := clienttypes.UnpackClientState(dstClientState.ClientState) if err != nil { panic(err) } - msg := connTypes.NewMsgConnectionOpenTry( + msg := conntypes.NewMsgConnectionOpenTry( + pe.ConnectionID, pe.ConnectionID, pe.ClientID, dst.ConnectionID, dst.ClientID, cs, defaultChainPrefix, - connTypes.GetCompatibleEncodedVersions(), + conntypes.GetCompatibleEncodedVersions(), dstConnState.Proof, dstClientState.Proof, dstConsState.Proof, dstConnState.ProofHeight, - cs.GetLatestHeight().(clientTypes.Height), + cs.GetLatestHeight().(clienttypes.Height), signer, ) if err = msg.ValidateBasic(); err != nil { @@ -151,32 +157,33 @@ func (pe *PathEnd) ConnTry( // NOTE: ADD NOTE ABOUT PROOF HEIGHT CHANGE HERE func (pe *PathEnd) ConnAck( dst *PathEnd, - dstClientState *clientTypes.QueryClientStateResponse, - dstConnState *connTypes.QueryConnectionResponse, - dstConsState *clientTypes.QueryConsensusStateResponse, + dstClientState *clienttypes.QueryClientStateResponse, + dstConnState *conntypes.QueryConnectionResponse, + dstConsState *clienttypes.QueryConsensusStateResponse, signer sdk.AccAddress, ) sdk.Msg { - cs, err := clientTypes.UnpackClientState(dstClientState.ClientState) + cs, err := clienttypes.UnpackClientState(dstClientState.ClientState) if err != nil { panic(err) } - return connTypes.NewMsgConnectionOpenAck( + return conntypes.NewMsgConnectionOpenAck( pe.ConnectionID, + dst.ConnectionID, cs, dstConnState.Proof, dstClientState.Proof, dstConsState.Proof, dstConsState.ProofHeight, - cs.GetLatestHeight().(clientTypes.Height), - connTypes.GetCompatibleEncodedVersions()[0], + cs.GetLatestHeight().(clienttypes.Height), + conntypes.GetCompatibleEncodedVersions()[0], signer, ) } // ConnConfirm creates a MsgConnectionOpenAck // NOTE: ADD NOTE ABOUT PROOF HEIGHT CHANGE HERE -func (pe *PathEnd) ConnConfirm(dstConnState *connTypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { - return connTypes.NewMsgConnectionOpenConfirm( +func (pe *PathEnd) ConnConfirm(dstConnState *conntypes.QueryConnectionResponse, signer sdk.AccAddress) sdk.Msg { + return conntypes.NewMsgConnectionOpenConfirm( pe.ConnectionID, dstConnState.Proof, dstConnState.ProofHeight, @@ -186,7 +193,7 @@ func (pe *PathEnd) ConnConfirm(dstConnState *connTypes.QueryConnectionResponse, // ChanInit creates a MsgChannelOpenInit func (pe *PathEnd) ChanInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelOpenInit( + return chantypes.NewMsgChannelOpenInit( pe.PortID, pe.ChannelID, pe.Version, @@ -199,10 +206,11 @@ func (pe *PathEnd) ChanInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg { } // ChanTry creates a MsgChannelOpenTry -func (pe *PathEnd) ChanTry(dst *PathEnd, dstChanState *chanTypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelOpenTry( +func (pe *PathEnd) ChanTry(dst *PathEnd, dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelOpenTry( pe.PortID, pe.ChannelID, + pe.ChannelID, pe.Version, dstChanState.Channel.Ordering, []string{pe.ConnectionID}, @@ -216,10 +224,11 @@ func (pe *PathEnd) ChanTry(dst *PathEnd, dstChanState *chanTypes.QueryChannelRes } // ChanAck creates a MsgChannelOpenAck -func (pe *PathEnd) ChanAck(dstChanState *chanTypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelOpenAck( +func (pe *PathEnd) ChanAck(dst *PathEnd, dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelOpenAck( pe.PortID, pe.ChannelID, + dst.ChannelID, dstChanState.Channel.Version, dstChanState.Proof, dstChanState.ProofHeight, @@ -228,8 +237,8 @@ func (pe *PathEnd) ChanAck(dstChanState *chanTypes.QueryChannelResponse, signer } // ChanConfirm creates a MsgChannelOpenConfirm -func (pe *PathEnd) ChanConfirm(dstChanState *chanTypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelOpenConfirm( +func (pe *PathEnd) ChanConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelOpenConfirm( pe.PortID, pe.ChannelID, dstChanState.Proof, @@ -240,7 +249,7 @@ func (pe *PathEnd) ChanConfirm(dstChanState *chanTypes.QueryChannelResponse, sig // ChanCloseInit creates a MsgChannelCloseInit func (pe *PathEnd) ChanCloseInit(signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelCloseInit( + return chantypes.NewMsgChannelCloseInit( pe.PortID, pe.ChannelID, signer, @@ -248,8 +257,8 @@ func (pe *PathEnd) ChanCloseInit(signer sdk.AccAddress) sdk.Msg { } // ChanCloseConfirm creates a MsgChannelCloseConfirm -func (pe *PathEnd) ChanCloseConfirm(dstChanState *chanTypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { - return chanTypes.NewMsgChannelCloseConfirm( +func (pe *PathEnd) ChanCloseConfirm(dstChanState *chantypes.QueryChannelResponse, signer sdk.AccAddress) sdk.Msg { + return chantypes.NewMsgChannelCloseConfirm( pe.PortID, pe.ChannelID, dstChanState.Proof, @@ -262,35 +271,35 @@ func (pe *PathEnd) ChanCloseConfirm(dstChanState *chanTypes.QueryChannelResponse func (pe *PathEnd) MsgTransfer(dst *PathEnd, amount sdk.Coin, dstAddr string, signer sdk.AccAddress, timeoutHeight, timeoutTimestamp uint64) sdk.Msg { - return xferTypes.NewMsgTransfer( + return transfertypes.NewMsgTransfer( pe.PortID, pe.ChannelID, amount, signer, dstAddr, - clientTypes.NewHeight(0, timeoutHeight), + clienttypes.NewHeight(0, timeoutHeight), timeoutTimestamp, ) } // NewPacket returns a new packet from src to dist w func (pe *PathEnd) NewPacket(dst *PathEnd, sequence uint64, packetData []byte, - timeoutHeight, timeoutStamp uint64) chanTypes.Packet { - return chanTypes.NewPacket( + timeoutHeight, timeoutStamp uint64) chantypes.Packet { + return chantypes.NewPacket( packetData, sequence, pe.PortID, pe.ChannelID, dst.PortID, dst.ChannelID, - clientTypes.NewHeight(0, timeoutHeight), + clienttypes.NewHeight(0, timeoutHeight), timeoutStamp, ) } // XferPacket creates a new transfer packet func (pe *PathEnd) XferPacket(amount sdk.Coin, sender, receiver string) []byte { - return xferTypes.NewFungibleTokenPacketData( + return transfertypes.NewFungibleTokenPacketData( amount.Denom, amount.Amount.Uint64(), sender, diff --git a/relayer/query.go b/relayer/query.go index 249adc3ec..cadedae57 100644 --- a/relayer/query.go +++ b/relayer/query.go @@ -10,18 +10,18 @@ import ( "github.com/cosmos/cosmos-sdk/store/rootmulti" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" + querytypes "github.com/cosmos/cosmos-sdk/types/query" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" - xferTypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" - clientUtils "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - connUtils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" - connTypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" - chanUtils "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/utils" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitTypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" + transfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types" + clientutils "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/client/utils" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + connutils "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/client/utils" + conntypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types" + chanutils "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/client/utils" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" + committypes "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -54,7 +54,7 @@ func (c *Chain) QueryBalance(keyName string) (sdk.Coins, error) { addr = info.GetAddress() } - params := bankTypes.NewQueryAllBalancesRequest(addr, &query.PageRequest{ + params := bankTypes.NewQueryAllBalancesRequest(addr, &querytypes.PageRequest{ Key: []byte(""), Offset: 0, Limit: 1000, @@ -78,16 +78,16 @@ func (c *Chain) QueryBalance(keyName string) (sdk.Coins, error) { // QueryConsensusState returns a consensus state for a given chain to be used as a // client in another chain, fetches latest height when passed 0 as arg func (c *Chain) QueryConsensusState(height int64) (*tmclient.ConsensusState, int64, error) { - return clientUtils.QueryNodeConsensusState(c.CLIContext(height)) + return clientutils.QueryNodeConsensusState(c.CLIContext(height)) } // QueryClientConsensusState retrevies the latest consensus state for a client in state at a given height func (c *Chain) QueryClientConsensusState( - height, dstClientConsHeight int64) (*clientTypes.QueryConsensusStateResponse, error) { - return clientUtils.QueryConsensusStateABCI( + height, dstClientConsHeight int64) (*clienttypes.QueryConsensusStateResponse, error) { + return clientutils.QueryConsensusStateABCI( c.CLIContext(height), c.PathEnd.ClientID, - clientTypes.NewHeight(0, uint64(dstClientConsHeight)), + clienttypes.NewHeight(0, uint64(dstClientConsHeight)), ) } @@ -95,7 +95,7 @@ func (c *Chain) QueryClientConsensusState( func QueryClientConsensusStatePair( src, dst *Chain, srch, dsth, srcClientConsH, - dstClientConsH int64) (srcCsRes, dstCsRes *clientTypes.QueryConsensusStateResponse, err error) { + dstClientConsH int64) (srcCsRes, dstCsRes *clienttypes.QueryConsensusStateResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { srcCsRes, err = src.QueryClientConsensusState(srch, srcClientConsH) @@ -110,14 +110,14 @@ func QueryClientConsensusStatePair( } // QueryClientState retrevies the latest consensus state for a client in state at a given height -func (c *Chain) QueryClientState(height int64) (*clientTypes.QueryClientStateResponse, error) { - return clientUtils.QueryClientStateABCI(c.CLIContext(height), c.PathEnd.ClientID) +func (c *Chain) QueryClientState(height int64) (*clienttypes.QueryClientStateResponse, error) { + return clientutils.QueryClientStateABCI(c.CLIContext(height), c.PathEnd.ClientID) } // QueryClientStatePair returns a pair of connection responses func QueryClientStatePair( src, dst *Chain, - srch, dsth int64) (srcCsRes, dstCsRes *clientTypes.QueryClientStateResponse, err error) { + srch, dsth int64) (srcCsRes, dstCsRes *clienttypes.QueryClientStateResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { srcCsRes, err = src.QueryClientState(srch) @@ -132,10 +132,10 @@ func QueryClientStatePair( } // QueryClients queries all the clients! -func (c *Chain) QueryClients(offset, limit uint64) (*clientTypes.QueryClientStatesResponse, error) { - qc := clientTypes.NewQueryClient(c.CLIContext(0)) - res, err := qc.ClientStates(context.Background(), &clientTypes.QueryClientStatesRequest{ - Pagination: &query.PageRequest{ +func (c *Chain) QueryClients(offset, limit uint64) (*clienttypes.QueryClientStatesResponse, error) { + qc := clienttypes.NewQueryClient(c.CLIContext(0)) + res, err := qc.ClientStates(context.Background(), &clienttypes.QueryClientStatesRequest{ + Pagination: &querytypes.PageRequest{ Key: []byte(""), Offset: offset, Limit: limit, @@ -151,10 +151,10 @@ func (c *Chain) QueryClients(offset, limit uint64) (*clientTypes.QueryClientStat // QueryConnections gets any connections on a chain func (c *Chain) QueryConnections( - offset, limit uint64) (conns *connTypes.QueryConnectionsResponse, err error) { - qc := connTypes.NewQueryClient(c.CLIContext(0)) - res, err := qc.Connections(context.Background(), &connTypes.QueryConnectionsRequest{ - Pagination: &query.PageRequest{ + offset, limit uint64) (conns *conntypes.QueryConnectionsResponse, err error) { + qc := conntypes.NewQueryClient(c.CLIContext(0)) + res, err := qc.Connections(context.Background(), &conntypes.QueryConnectionsRequest{ + Pagination: &querytypes.PageRequest{ Key: []byte(""), Offset: offset, Limit: limit, @@ -166,13 +166,13 @@ func (c *Chain) QueryConnections( // QueryConnectionsUsingClient gets any connections that exist between chain and counterparty func (c *Chain) QueryConnectionsUsingClient( - height int64) (clientConns *connTypes.QueryClientConnectionsResponse, err error) { - return connUtils.QueryClientConnections(c.CLIContext(height), c.PathEnd.ClientID, true) + height int64) (clientConns *conntypes.QueryClientConnectionsResponse, err error) { + return connutils.QueryClientConnections(c.CLIContext(height), c.PathEnd.ClientID, true) } // QueryConnection returns the remote end of a given connection -func (c *Chain) QueryConnection(height int64) (*connTypes.QueryConnectionResponse, error) { - res, err := connUtils.QueryConnection(c.CLIContext(height), c.PathEnd.ConnectionID, true) +func (c *Chain) QueryConnection(height int64) (*conntypes.QueryConnectionResponse, error) { + res, err := connutils.QueryConnection(c.CLIContext(height), c.PathEnd.ConnectionID, true) if err != nil && strings.Contains(err.Error(), "not found") { return emptyConnRes, nil } else if err != nil { @@ -181,26 +181,26 @@ func (c *Chain) QueryConnection(height int64) (*connTypes.QueryConnectionRespons return res, nil } -var emptyConnRes = connTypes.NewQueryConnectionResponse( +var emptyConnRes = conntypes.NewQueryConnectionResponse( "uninitialized", - connTypes.NewConnectionEnd( - connTypes.UNINITIALIZED, + conntypes.NewConnectionEnd( + conntypes.UNINITIALIZED, "client", - connTypes.NewCounterparty( + conntypes.NewCounterparty( "client", "connection", - commitTypes.NewMerklePrefix([]byte{}), + committypes.NewMerklePrefix([]byte{}), ), []string{}, ), []byte{}, - clientTypes.NewHeight(0, 0), + clienttypes.NewHeight(0, 0), ) // QueryConnectionPair returns a pair of connection responses func QueryConnectionPair( src, dst *Chain, - srcH, dstH int64) (srcConn, dstConn *connTypes.QueryConnectionResponse, err error) { + srcH, dstH int64) (srcConn, dstConn *conntypes.QueryConnectionResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { srcConn, err = src.QueryConnection(srcH) @@ -221,11 +221,11 @@ func QueryConnectionPair( // QueryConnectionChannels queries the channels associated with a connection func (c *Chain) QueryConnectionChannels( connectionID string, - offset, limit uint64) (*chanTypes.QueryConnectionChannelsResponse, error) { - qc := chanTypes.NewQueryClient(c.CLIContext(0)) - return qc.ConnectionChannels(context.Background(), &chanTypes.QueryConnectionChannelsRequest{ + offset, limit uint64) (*chantypes.QueryConnectionChannelsResponse, error) { + qc := chantypes.NewQueryClient(c.CLIContext(0)) + return qc.ConnectionChannels(context.Background(), &chantypes.QueryConnectionChannelsRequest{ Connection: connectionID, - Pagination: &query.PageRequest{ + Pagination: &querytypes.PageRequest{ Key: []byte(""), Offset: offset, Limit: limit, @@ -235,8 +235,8 @@ func (c *Chain) QueryConnectionChannels( } // QueryChannel returns the channel associated with a channelID -func (c *Chain) QueryChannel(height int64) (chanRes *chanTypes.QueryChannelResponse, err error) { - res, err := chanUtils.QueryChannel(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, true) +func (c *Chain) QueryChannel(height int64) (chanRes *chantypes.QueryChannelResponse, err error) { + res, err := chanutils.QueryChannel(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, true) if err != nil && strings.Contains(err.Error(), "not found") { return emptyChannelRes, nil } else if err != nil { @@ -245,13 +245,13 @@ func (c *Chain) QueryChannel(height int64) (chanRes *chanTypes.QueryChannelRespo return res, nil } -var emptyChannelRes = chanTypes.NewQueryChannelResponse( +var emptyChannelRes = chantypes.NewQueryChannelResponse( "port", "channel", - chanTypes.NewChannel( - chanTypes.UNINITIALIZED, - chanTypes.UNORDERED, - chanTypes.NewCounterparty( + chantypes.NewChannel( + chantypes.UNINITIALIZED, + chantypes.UNORDERED, + chantypes.NewCounterparty( "port", "channel", ), @@ -259,11 +259,11 @@ var emptyChannelRes = chanTypes.NewQueryChannelResponse( "version", ), []byte{}, - clientTypes.NewHeight(0, 0), + clienttypes.NewHeight(0, 0), ) // QueryChannelPair returns a pair of channel responses -func QueryChannelPair(src, dst *Chain, srcH, dstH int64) (srcChan, dstChan *chanTypes.QueryChannelResponse, err error) { +func QueryChannelPair(src, dst *Chain, srcH, dstH int64) (srcChan, dstChan *chantypes.QueryChannelResponse, err error) { var eg = new(errgroup.Group) eg.Go(func() error { srcChan, err = src.QueryChannel(srcH) @@ -278,10 +278,10 @@ func QueryChannelPair(src, dst *Chain, srcH, dstH int64) (srcChan, dstChan *chan } // QueryChannels returns all the channels that are registered on a chain -func (c *Chain) QueryChannels(offset, limit uint64) (*chanTypes.QueryChannelsResponse, error) { - qc := chanTypes.NewQueryClient(c.CLIContext(0)) - res, err := qc.Channels(context.Background(), &chanTypes.QueryChannelsRequest{ - Pagination: &query.PageRequest{ +func (c *Chain) QueryChannels(offset, limit uint64) (*chantypes.QueryChannelsResponse, error) { + qc := chantypes.NewQueryClient(c.CLIContext(0)) + res, err := qc.Channels(context.Background(), &chantypes.QueryChannelsRequest{ + Pagination: &querytypes.PageRequest{ Key: []byte(""), Offset: offset, Limit: limit, @@ -292,9 +292,9 @@ func (c *Chain) QueryChannels(offset, limit uint64) (*chanTypes.QueryChannelsRes } // QueryChannelClient returns the client state of the client supporting a given channel -func (c *Chain) QueryChannelClient() (*chanTypes.QueryChannelClientStateResponse, error) { - qc := chanTypes.NewQueryClient(c.CLIContext(0)) - return qc.ChannelClientState(context.Background(), &chanTypes.QueryChannelClientStateRequest{ +func (c *Chain) QueryChannelClient(height int64) (*chantypes.QueryChannelClientStateResponse, error) { + qc := chantypes.NewQueryClient(c.CLIContext(height)) + return qc.ChannelClientState(context.Background(), &chantypes.QueryChannelClientStateRequest{ PortId: c.PathEnd.PortID, ChannelId: c.PathEnd.ChannelID, }) @@ -305,16 +305,16 @@ func (c *Chain) QueryChannelClient() (*chanTypes.QueryChannelClientStateResponse ///////////////////////////////////// // QueryDenomTrace takes a denom from IBC and queries the information about it -func (c *Chain) QueryDenomTrace(denom string) (*xferTypes.QueryDenomTraceResponse, error) { - return xferTypes.NewQueryClient(c.CLIContext(0)).DenomTrace(context.Background(), &xferTypes.QueryDenomTraceRequest{ +func (c *Chain) QueryDenomTrace(denom string) (*transfertypes.QueryDenomTraceResponse, error) { + return transfertypes.NewQueryClient(c.CLIContext(0)).DenomTrace(context.Background(), &transfertypes.QueryDenomTraceRequest{ Hash: denom, }) } // QueryDenomTraces returns all the denom traces from a given chain -func (c *Chain) QueryDenomTraces(offset, limit uint64) (*xferTypes.QueryDenomTracesResponse, error) { - return xferTypes.NewQueryClient(c.CLIContext(0)).DenomTraces(context.Background(), &xferTypes.QueryDenomTracesRequest{ - Pagination: &query.PageRequest{ +func (c *Chain) QueryDenomTraces(offset, limit uint64, height int64) (*transfertypes.QueryDenomTracesResponse, error) { + return transfertypes.NewQueryClient(c.CLIContext(height)).DenomTraces(context.Background(), &transfertypes.QueryDenomTracesRequest{ + Pagination: &querytypes.PageRequest{ Key: []byte(""), Offset: offset, Limit: limit, @@ -328,23 +328,23 @@ func (c *Chain) QueryDenomTraces(offset, limit uint64) (*xferTypes.QueryDenomTra ///////////////////////////////////// // QueryHistoricalInfo returns historical header data -func (c *Chain) QueryHistoricalInfo(height clientTypes.Height) (*stakingTypes.QueryHistoricalInfoResponse, error) { +func (c *Chain) QueryHistoricalInfo(height clienttypes.Height) (*stakingtypes.QueryHistoricalInfoResponse, error) { //TODO: use epoch number in query once SDK gets updated - qc := stakingTypes.NewQueryClient(c.CLIContext(int64(height.EpochHeight))) - return qc.HistoricalInfo(context.Background(), &stakingTypes.QueryHistoricalInfoRequest{ - Height: int64(height.EpochHeight), + qc := stakingtypes.NewQueryClient(c.CLIContext(int64(height.GetVersionHeight()))) + return qc.HistoricalInfo(context.Background(), &stakingtypes.QueryHistoricalInfoRequest{ + Height: int64(height.GetVersionHeight()), }) } // QueryValsetAtHeight returns the validator set at a given height -func (c *Chain) QueryValsetAtHeight(height clientTypes.Height) (*tmproto.ValidatorSet, error) { +func (c *Chain) QueryValsetAtHeight(height clienttypes.Height) (*tmproto.ValidatorSet, error) { res, err := c.QueryHistoricalInfo(height) if err != nil { return nil, err } // create tendermint ValidatorSet from SDK Validators - tmVals := stakingTypes.Validators(res.Hist.Valset).ToTmValidators() + tmVals := stakingtypes.Validators(res.Hist.Valset).ToTmValidators() tmValSet := &tmtypes.ValidatorSet{ Validators: tmVals, Proposer: tmVals[0], @@ -355,9 +355,9 @@ func (c *Chain) QueryValsetAtHeight(height clientTypes.Height) (*tmproto.Validat // QueryUnbondingPeriod returns the unbonding period of the chain func (c *Chain) QueryUnbondingPeriod() (time.Duration, error) { - req := stakingTypes.QueryParamsRequest{} + req := stakingtypes.QueryParamsRequest{} - queryClient := stakingTypes.NewQueryClient(c.CLIContext(0)) + queryClient := stakingtypes.NewQueryClient(c.CLIContext(0)) res, err := queryClient.Params(context.Background(), &req) if err != nil { @@ -367,10 +367,20 @@ func (c *Chain) QueryUnbondingPeriod() (time.Duration, error) { return res.Params.UnbondingTime, nil } +// QueryConsensusParams returns the consensus params +func (c *Chain) QueryConsensusParams() (*abci.ConsensusParams, error) { + rg, err := c.Client.Genesis(context.Background()) + if err != nil { + return nil, err + } + + return tmtypes.TM2PB.ConsensusParams(rg.Genesis.ConsensusParams), nil +} + // WaitForNBlocks blocks until the next block on a given chain func (c *Chain) WaitForNBlocks(n int64) error { var initial int64 - h, err := c.Client.Status() + h, err := c.Client.Status(context.Background()) if err != nil { return err } @@ -379,7 +389,7 @@ func (c *Chain) WaitForNBlocks(n int64) error { } initial = h.SyncInfo.LatestBlockHeight for { - h, err = c.Client.Status() + h, err = c.Client.Status(context.Background()) if err != nil { return err } @@ -391,24 +401,24 @@ func (c *Chain) WaitForNBlocks(n int64) error { } // QueryNextSeqRecv returns the next seqRecv for a configured channel -func (c *Chain) QueryNextSeqRecv(height int64) (recvRes *chanTypes.QueryNextSequenceReceiveResponse, err error) { - return chanUtils.QueryNextSequenceReceive(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, true) +func (c *Chain) QueryNextSeqRecv(height int64) (recvRes *chantypes.QueryNextSequenceReceiveResponse, err error) { + return chanutils.QueryNextSequenceReceive(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, true) } // QueryPacketCommitment returns the packet commitment proof at a given height func (c *Chain) QueryPacketCommitment( - height int64, seq uint64) (comRes *chanTypes.QueryPacketCommitmentResponse, err error) { - return chanUtils.QueryPacketCommitment(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, seq, true) + height int64, seq uint64) (comRes *chantypes.QueryPacketCommitmentResponse, err error) { + return chanutils.QueryPacketCommitment(c.CLIContext(height), c.PathEnd.PortID, c.PathEnd.ChannelID, seq, true) } // QueryPacketCommitments returns an array of packet commitment proofs func (c *Chain) QueryPacketCommitments( - offset, limit, height uint64) (comRes *chanTypes.QueryPacketCommitmentsResponse, err error) { - qc := chanTypes.NewQueryClient(c.CLIContext(int64(height))) - return qc.PacketCommitments(context.Background(), &chanTypes.QueryPacketCommitmentsRequest{ + offset, limit, height uint64) (comRes *chantypes.QueryPacketCommitmentsResponse, err error) { + qc := chantypes.NewQueryClient(c.CLIContext(int64(height))) + return qc.PacketCommitments(context.Background(), &chantypes.QueryPacketCommitmentsRequest{ PortId: c.PathEnd.PortID, ChannelId: c.PathEnd.ChannelID, - Pagination: &query.PageRequest{ + Pagination: &querytypes.PageRequest{ Offset: offset, Limit: limit, CountTotal: true, @@ -419,8 +429,8 @@ func (c *Chain) QueryPacketCommitments( // QueryUnrecievedPackets returns a list of unrelayed packet commitments func (c *Chain) QueryUnrecievedPackets(height uint64, seqs []uint64) ([]uint64, error) { - qc := chanTypes.NewQueryClient(c.CLIContext(int64(height))) - res, err := qc.UnreceivedPackets(context.Background(), &chanTypes.QueryUnreceivedPacketsRequest{ + qc := chantypes.NewQueryClient(c.CLIContext(int64(height))) + res, err := qc.UnreceivedPackets(context.Background(), &chantypes.QueryUnreceivedPacketsRequest{ PortId: c.PathEnd.PortID, ChannelId: c.PathEnd.ChannelID, PacketCommitmentSequences: seqs, @@ -430,8 +440,8 @@ func (c *Chain) QueryUnrecievedPackets(height uint64, seqs []uint64) ([]uint64, // QueryUnrelayedAcks returns a list of unrelayed packet acks func (c *Chain) QueryUnrelayedAcks(height uint64, seqs []uint64) ([]uint64, error) { - qc := chanTypes.NewQueryClient(c.CLIContext(int64(height))) - res, err := qc.UnrelayedAcks(context.Background(), &chanTypes.QueryUnrelayedAcksRequest{ + qc := chantypes.NewQueryClient(c.CLIContext(int64(height))) + res, err := qc.UnrelayedAcks(context.Background(), &chantypes.QueryUnrelayedAcksRequest{ PortId: c.PathEnd.PortID, ChannelId: c.PathEnd.ChannelID, PacketCommitmentSequences: seqs, @@ -446,7 +456,7 @@ func (c *Chain) QueryTx(hashHex string) (*ctypes.ResultTx, error) { return &ctypes.ResultTx{}, err } - return c.Client.Tx(hash, true) + return c.Client.Tx(context.Background(), hash, true) } // QueryTxs returns an array of transactions given a tag @@ -463,7 +473,7 @@ func (c *Chain) QueryTxs(height uint64, page, limit int, events []string) ([]*ct return nil, errors.New("limit must greater than 0") } - res, err := c.Client.TxSearch(strings.Join(events, " AND "), true, &page, &limit, "") + res, err := c.Client.TxSearch(context.Background(), strings.Join(events, " AND "), true, &page, &limit, "") if err != nil { return nil, err } @@ -478,7 +488,7 @@ func (c *Chain) QueryABCI(req abci.RequestQuery) (res abci.ResponseQuery, err er Prove: req.Prove, } - result, err := c.Client.ABCIQueryWithOptions(req.Path, req.Data, opts) + result, err := c.Client.ABCIQueryWithOptions(context.Background(), req.Path, req.Data, opts) if err != nil { // retry queries on EOF if strings.Contains(err.Error(), "EOF") { @@ -518,7 +528,7 @@ func (c *Chain) QueryWithData(p string, d []byte) (byt []byte, i int64, err erro // QueryLatestHeight queries the chain for the latest height and returns it func (c *Chain) QueryLatestHeight() (int64, error) { - res, err := c.Client.Status() + res, err := c.Client.Status(context.Background()) if err != nil { return -1, err } else if res.SyncInfo.CatchingUp { @@ -562,12 +572,12 @@ func (c *Chain) QueryHeaderAtHeight(height int64) (*tmclient.Header, error) { return nil, fmt.Errorf("must pass in valid height, %d not valid", height) } - res, err := c.Client.Commit(&height) + res, err := c.Client.Commit(context.Background(), &height) if err != nil { return nil, err } - val, err := c.Client.Validators(&height, &page, &perPage) + val, err := c.Client.Validators(context.Background(), &height, &page, &perPage) if err != nil { return nil, err } diff --git a/relayer/relayPackets.go b/relayer/relayPackets.go index b3fb9a0cb..5ca30f2ae 100644 --- a/relayer/relayPackets.go +++ b/relayer/relayPackets.go @@ -5,8 +5,8 @@ import ( retry "github.com/avast/retry-go" sdk "github.com/cosmos/cosmos-sdk/types" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" - chanTypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types" ) type relayPacket interface { @@ -22,7 +22,7 @@ type relayMsgTimeout struct { seq uint64 timeout uint64 timeoutStamp uint64 - dstRecvRes *chanTypes.QueryPacketCommitmentResponse + dstRecvRes *chantypes.QueryPacketCommitmentResponse pass bool } @@ -40,7 +40,7 @@ func (rp *relayMsgTimeout) Timeout() uint64 { } func (rp *relayMsgTimeout) FetchCommitResponse(src, dst *Chain, sh *SyncHeaders) (err error) { - var dstRecvRes *chanTypes.QueryPacketCommitmentResponse + var dstRecvRes *chantypes.QueryPacketCommitmentResponse // retry getting commit response until it succeeds if err = retry.Do(func() error { // NOTE: Timeouts currently only work with ORDERED channels for nwo @@ -70,15 +70,15 @@ func (rp *relayMsgTimeout) Msg(src, dst *Chain) sdk.Msg { if rp.dstRecvRes == nil { return nil } - return chanTypes.NewMsgTimeout( - chanTypes.NewPacket( + return chantypes.NewMsgTimeout( + chantypes.NewPacket( rp.packetData, rp.seq, dst.PathEnd.PortID, dst.PathEnd.ChannelID, src.PathEnd.PortID, src.PathEnd.ChannelID, - clientTypes.NewHeight(0, rp.timeout), + clienttypes.NewHeight(0, rp.timeout), rp.timeoutStamp, ), rp.seq, @@ -93,7 +93,7 @@ type relayMsgRecvPacket struct { seq uint64 timeout uint64 timeoutStamp uint64 - dstComRes *chanTypes.QueryPacketCommitmentResponse + dstComRes *chantypes.QueryPacketCommitmentResponse pass bool } @@ -122,17 +122,14 @@ func (rp *relayMsgRecvPacket) Timeout() uint64 { } func (rp *relayMsgRecvPacket) FetchCommitResponse(src, dst *Chain, sh *SyncHeaders) (err error) { - var dstCommitRes *chanTypes.QueryPacketCommitmentResponse + var dstCommitRes *chantypes.QueryPacketCommitmentResponse // retry getting commit response until it succeeds if err = retry.Do(func() error { dstCommitRes, err = dst.QueryPacketCommitment(sh.GetHeader(dst.ChainID).Header.Height-1, rp.seq) if err != nil { return err } else if dstCommitRes.Proof == nil || dstCommitRes.Commitment == nil { - if err := sh.Update(src); err != nil { - return err - } - if err := sh.Update(dst); err != nil { + if err = sh.Updates(src, dst); err != nil { return err } return fmt.Errorf("- [%s]@{%d} - Packet Commitment Proof is nil seq(%d)", @@ -152,17 +149,17 @@ func (rp *relayMsgRecvPacket) Msg(src, dst *Chain) sdk.Msg { if rp.dstComRes == nil { return nil } - packet := chanTypes.NewPacket( + packet := chantypes.NewPacket( rp.packetData, rp.seq, dst.PathEnd.PortID, dst.PathEnd.ChannelID, src.PathEnd.PortID, src.PathEnd.ChannelID, - clientTypes.NewHeight(0, rp.timeout), + clienttypes.NewHeight(0, rp.timeout), rp.timeoutStamp, ) - return chanTypes.NewMsgRecvPacket( + return chantypes.NewMsgRecvPacket( packet, rp.dstComRes.Proof, rp.dstComRes.ProofHeight, @@ -176,7 +173,7 @@ type relayMsgPacketAck struct { seq uint64 timeout uint64 timeoutStamp uint64 - dstComRes *chanTypes.QueryPacketCommitmentResponse + dstComRes *chantypes.QueryPacketCommitmentResponse } func (rp *relayMsgPacketAck) Data() []byte { @@ -190,15 +187,15 @@ func (rp *relayMsgPacketAck) Timeout() uint64 { } func (rp *relayMsgPacketAck) Msg(src, dst *Chain) sdk.Msg { - return chanTypes.NewMsgAcknowledgement( - chanTypes.NewPacket( + return chantypes.NewMsgAcknowledgement( + chantypes.NewPacket( rp.packetData, rp.seq, src.PathEnd.PortID, src.PathEnd.ChannelID, dst.PathEnd.PortID, dst.PathEnd.ChannelID, - clientTypes.NewHeight(0, rp.timeout), + clienttypes.NewHeight(0, rp.timeout), rp.timeoutStamp, ), rp.ack, @@ -209,7 +206,7 @@ func (rp *relayMsgPacketAck) Msg(src, dst *Chain) sdk.Msg { } func (rp *relayMsgPacketAck) FetchCommitResponse(src, dst *Chain, sh *SyncHeaders) (err error) { - var dstCommitRes *chanTypes.QueryPacketCommitmentResponse + var dstCommitRes *chantypes.QueryPacketCommitmentResponse if err = retry.Do(func() error { dstCommitRes, err = dst.QueryPacketCommitment(sh.GetHeader(dst.ChainID).Header.Height-1, rp.seq) if err != nil { diff --git a/relayer/verifier.go b/relayer/verifier.go index 322b8fa91..cbe31ed1d 100644 --- a/relayer/verifier.go +++ b/relayer/verifier.go @@ -1,6 +1,7 @@ package relayer import ( + "context" "errors" "fmt" "io/ioutil" @@ -8,7 +9,7 @@ import ( "path/filepath" "time" - tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" + tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types" dbm "github.com/tendermint/tm-db" retry "github.com/avast/retry-go" @@ -81,7 +82,7 @@ func (c *Chain) UpdateLightWithHeader() (*tmclient.Header, error) { return nil, lightError(err) } - sh, err := client.Update(time.Now()) + sh, err := client.Update(context.Background(), time.Now()) if err != nil { return nil, lightError(err) } @@ -132,11 +133,12 @@ func (c *Chain) LightClientWithoutTrust(db dbm.DB) (*light.Client, error) { return nil, err } - lb, err := prov.LightBlock(height) + lb, err := prov.LightBlock(context.Background(), height) if err != nil { return nil, err } return light.NewClient( + context.Background(), c.ChainID, light.TrustOptions{ Period: c.GetTrustingPeriod(), @@ -156,6 +158,7 @@ func (c *Chain) LightClientWithoutTrust(db dbm.DB) (*light.Client, error) { func (c *Chain) LightClientWithTrust(db dbm.DB, to light.TrustOptions) (*light.Client, error) { prov := c.LightHTTP() return light.NewClient( + context.Background(), c.ChainID, to, prov, @@ -242,6 +245,23 @@ func (c *Chain) ValidateTxResult(resTx *ctypes.ResultTx) (err error) { return resTx.Proof.Validate(check.Header.DataHash) } +// GetLatestLightHeights returns both the src and dst latest height in the local client +func GetLatestLightHeights(src, dst *Chain) (srch int64, dsth int64, err error) { + var eg = new(errgroup.Group) + eg.Go(func() error { + srch, err = src.GetLatestLightHeight() + return err + }) + eg.Go(func() error { + dsth, err = dst.GetLatestLightHeight() + return err + }) + if err = eg.Wait(); err != nil { + return + } + return +} + // GetLatestLightHeight uses the CLI utilities to pull the latest height from a given chain func (c *Chain) GetLatestLightHeight() (int64, error) { db, df, err := c.NewLightDB() diff --git a/scripts/one-chain b/scripts/one-chain index 3cd11129d..505ea91f0 100755 --- a/scripts/one-chain +++ b/scripts/one-chain @@ -1,5 +1,11 @@ #!/bin/sh -# USAGE: ./one-chain test-chain-id ./data 26657 26656 + +display_usage() { + echo "\nMissing $1 parameter. Please check if all parameters were specified." + echo "\nUsage: ./one-chain [CHAIN_ID] [CHAIN_DIR] [RPC_PORT] [P2P_PORT] [PROFILING_PORT] [GRPC_PORT]" + echo "\nExample: ./one-chain test-chain-id ./data 26657 26656 6060 9090 \n" + exit 1 +} CHAINID=$1 CHAINDIR=$2 @@ -9,55 +15,81 @@ PROFPORT=$5 GRPCPORT=$6 if [ -z "$1" ]; then - echo "Need to input chain id..." - exit 1 + display_usage "[CHAIN_ID]" fi if [ -z "$2" ]; then - echo "Need to input directory to create files in..." - exit 1 + display_usage "[CHAIN_DIR]" fi if [ -z "$3" ]; then - echo "Need to input rpc port (e.g. 26657)..." - exit 1 + display_usage "[RPC_PORT]" fi if [ -z "$4" ]; then - echo "Need to input p2p port (e.g. 26656)..." - exit 1 + display_usage "[P2P_PORT]" fi if [ -z "$5" ]; then - echo "Need to input profiling server port (e.g. 6060)..." - exit 1 + display_usage "[PROFILING_PORT]" fi if [ -z "$6" ]; then - echo "Need to input grpc server port (e.g. 9090)..." - exit 1 + display_usage "[GRPC_PORT]" +fi + +echo "Creating gaiad instance: home=$CHAINDIR | chain-id=$CHAINID | p2p=:$P2PPORT | rpc=:$RPCPORT | profiling=:$PROFPORT | grpc=:$GRPCPORT" + +# Add dir for chain, exit if error +if ! mkdir -p $CHAINDIR/$CHAINID 2>/dev/null; then + echo "Failed to create chain folder. Aborting..." + exit 1 fi -echo "Creating gaiad instance with home=$CHAINDIR chain-id=$CHAINID p2p=:$P2PPORT rpc=:$RPCPORT..." # Build genesis file incl account for passed address coins="100000000000stake,100000000000samoleans" + gaiad --home $CHAINDIR/$CHAINID --chain-id $CHAINID init $CHAINID &> /dev/null -gaiad --home $CHAINDIR/$CHAINID keys add validator --keyring-backend="test" > $CHAINDIR/$CHAINID/validator_seed.json 2> /dev/null +sleep 1 +gaiad --home $CHAINDIR/$CHAINID keys add validator --keyring-backend="test" --output json > $CHAINDIR/$CHAINID/validator_seed.json 2> /dev/null +sleep 1 gaiad --home $CHAINDIR/$CHAINID keys add user --keyring-backend="test" --output json > $CHAINDIR/$CHAINID/key_seed.json 2> /dev/null +sleep 1 gaiad --home $CHAINDIR/$CHAINID add-genesis-account $(gaiad --home $CHAINDIR/$CHAINID keys --keyring-backend="test" show user -a) $coins &> /dev/null +sleep 1 gaiad --home $CHAINDIR/$CHAINID add-genesis-account $(gaiad --home $CHAINDIR/$CHAINID keys --keyring-backend="test" show validator -a) $coins &> /dev/null +sleep 1 gaiad --home $CHAINDIR/$CHAINID gentx validator --keyring-backend="test" --chain-id $CHAINID &> /dev/null +sleep 1 gaiad --home $CHAINDIR/$CHAINID collect-gentxs &> /dev/null +sleep 1 -# Set proper defaults and change ports -# TODO: sed for linux -sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml -sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml -sed -i '' 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml -sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml -sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml -sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml -# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml +# Check platform +platform='unknown' +unamestr=`uname` +if [ "$unamestr" = 'Linux' ]; then + platform='linux' +fi + +# Set proper defaults and change ports (use a different sed for Mac or Linux) +echo "Change settings in config.toml file..." +if [ $platform = 'linux' ]; then + sed -i 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml + sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml + sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml + # sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml +else + sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i '' 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml + sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml + sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAINDIR/$CHAINID/config/config.toml + sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml + # sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml +fi # Start the gaia gaiad --home $CHAINDIR/$CHAINID start --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT" > $CHAINDIR/$CHAINID.log 2>&1 & \ No newline at end of file diff --git a/scripts/three-chainz b/scripts/three-chainz index bd060f453..3a062c840 100755 --- a/scripts/three-chainz +++ b/scripts/three-chainz @@ -78,5 +78,8 @@ echo "Generating gaia configurations..." mkdir -p $GAIA_DATA && cd $GAIA_DATA && cd ../ ./scripts/one-chain $chainid0 ./data 26657 26656 6060 9090 ./scripts/one-chain $chainid1 ./data 26557 26556 6061 9091 -./scripts/one-chain $chainid1 ./data 25557 25556 6062 9092 +./scripts/one-chain $chainid2 ./data 25557 25556 6062 9092 +[ -f $GAIA_DATA/$chainid0.log ] && echo "$chainid0 initialized. Watch file $GAIA_DATA/$chainid0.log to see its execution." +[ -f $GAIA_DATA/$chainid1.log ] && echo "$chainid1 initialized. Watch file $GAIA_DATA/$chainid1.log to see its execution." +[ -f $GAIA_DATA/$chainid1.log ] && echo "$chainid2 initialized. Watch file $GAIA_DATA/$chainid2.log to see its execution." diff --git a/scripts/two-chainz b/scripts/two-chainz index 8065eb233..1df2ee849 100755 --- a/scripts/two-chainz +++ b/scripts/two-chainz @@ -11,16 +11,16 @@ if [[ ! -d $GOPATH ]] || [[ ! -d $GOBIN ]] || [[ ! -x "$(which go)" ]]; then fi GAIA_REPO="$GOPATH/src/github.com/cosmos/gaia" -GAIA_BRANCH=gaiav3.0 +GAIA_BRANCH=stargate-4 GAIA_DATA="$(pwd)/data" -# ARGS: +# ARGS: # $1 -> local || remote, defaults to remote # Ensure user understands what will be deleted if [[ -d $GAIA_DATA ]] && [[ ! "$2" == "skip" ]]; then read -p "$0 will delete \$(pwd)/data folder. Do you wish to continue? (y/n): " -n 1 -r - echo + echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi @@ -59,14 +59,14 @@ if [[ -d $GAIA_REPO ]]; then if [[ ! "$(gaiad version --long 2>&1 | grep "commit:" | sed 's/commit: //g')" == "$(git rev-parse HEAD)" ]]; then echo "built version of gaiad commit doesn't match" exit 1 - fi + fi else echo "uncommited changes in $GAIA_REPO, please commit or stash before building" exit 1 fi - - fi -else + + fi +else echo "$GAIA_REPO doesn't exist, and you may not have have the gaia repo locally," echo "if you want to download gaia to your \$GOPATH try running the following command:" echo "mkdir -p $(dirname $GAIA_REPO) && git clone git@github.com:cosmos/gaia $GAIA_REPO" @@ -79,3 +79,6 @@ echo "Generating gaia configurations..." mkdir -p $GAIA_DATA && cd $GAIA_DATA && cd ../ ./scripts/one-chain $chainid0 ./data 26657 26656 6060 9090 ./scripts/one-chain $chainid1 ./data 26557 26556 6061 9091 + +[ -f $GAIA_DATA/$chainid0.log ] && echo "$chainid0 initialized. Watch file $GAIA_DATA/$chainid0.log to see its execution." +[ -f $GAIA_DATA/$chainid1.log ] && echo "$chainid1 initialized. Watch file $GAIA_DATA/$chainid1.log to see its execution." \ No newline at end of file diff --git a/test/test_chains.go b/test/test_chains.go index 2f7757ae3..3a7859cd5 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -55,7 +55,7 @@ func newTestChain(t *testing.T, tc testChain) *ry.Chain { ChainID: tc.chainID, RPCAddr: fmt.Sprintf("http://localhost:%s", port), AccountPrefix: tc.t.accountPrefix, - GasAdjustment: 1.0, + GasAdjustment: 1.3, TrustingPeriod: tc.t.trustingPeriod, } } diff --git a/test/test_queries.go b/test/test_queries.go index 150fb4acd..c2e76feb6 100644 --- a/test/test_queries.go +++ b/test/test_queries.go @@ -1,9 +1,11 @@ package test import ( + "context" "testing" - clientTypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" + "github.com/avast/retry-go" + clientypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" "github.com/stretchr/testify/require" ry "github.com/ovrclk/relayer/relayer" @@ -17,12 +19,23 @@ func testClientPair(t *testing.T, src, dst *ry.Chain) { // testClient queries client for existence of dst on src func testClient(t *testing.T, src, dst *ry.Chain) { - client, err := src.QueryClientState(0) + srch, err := src.GetLatestLightHeight() + require.NoError(t, err) + var ( + client *clientypes.QueryClientStateResponse + ) + retry.Do(func() error { + client, err = src.QueryClientState(srch) + if err != nil { + srch, _ = src.QueryLatestHeight() + } + return err + }) require.NoError(t, err) require.NotNil(t, client) - cs, err := clientTypes.UnpackClientState(client.ClientState) + cs, err := clientypes.UnpackClientState(client.ClientState) require.NoError(t, err) - require.Equal(t, cs.ClientType().String(), "tendermint") + require.Equal(t, cs.ClientType(), "Tendermint") } // testConnectionPair tests that the only connection on src and dst is between the two chains @@ -42,7 +55,7 @@ func testConnection(t *testing.T, src, dst *ry.Chain) { require.Equal(t, conns.Connections[0].Counterparty.GetConnectionID(), dst.PathEnd.ConnectionID) require.Equal(t, conns.Connections[0].State.String(), "STATE_OPEN") - h, err := src.Client.Status() + h, err := src.Client.Status(context.Background()) require.NoError(t, err) conn, err := src.QueryConnection(h.SyncInfo.LatestBlockHeight) @@ -69,7 +82,7 @@ func testChannel(t *testing.T, src, dst *ry.Chain) { require.Equal(t, chans.Channels[0].Counterparty.ChannelId, dst.PathEnd.ChannelID) require.Equal(t, chans.Channels[0].Counterparty.GetPortID(), dst.PathEnd.PortID) - h, err := src.Client.Status() + h, err := src.Client.Status(context.Background()) require.NoError(t, err) ch, err := src.QueryChannel(h.SyncInfo.LatestBlockHeight) diff --git a/testnets/README.md b/testnets/README.md index 03905da72..9140e5703 100644 --- a/testnets/README.md +++ b/testnets/README.md @@ -16,7 +16,7 @@ This is the second `relayer` testnet! I will be copying JSON files from the firs $ gaiad version --long name: gaia server_name: gaiad -client_name: gaiacli +client_name: gaiad version: 0.0.0-180-g50be36d commit: 50be36de941b9410a4b06ec9ce4288b1529c4bd4 build_tags: netgo,ledger @@ -91,10 +91,10 @@ gaiad init --chain-id $CHAINID $CHAINID sed -i 's#tcp://127.0.0.1:26657#tcp://0.0.0.0:26657#g' ~/.gaiad/config/config.toml sed -i "s/\"stake\"/\"$DENOM\"/g" ~/.gaiad/config/genesis.json sed -i 's/pruning = "syncable"/pruning = "nothing"/g' ~/.gaiad/config/app.toml -gaiacli keys add validator +gaiad keys add validator # Now its time to construct the genesis file -gaiad add-genesis-account $(gaiacli keys show validator -a) 100000000000$DENOM,10000000samoleans +gaiad add-genesis-account $(gaiad keys show validator -a) 100000000000$DENOM,10000000samoleans gaiad add-genesis-account $(rly chains addr $CHAINID) 10000000000000$DENOM,10000000samoleans gaiad gentx --name validator --amount 90000000000$DENOM gaiad collect-gentxs