Skip to content

Commit

Permalink
Merge pull request #334 from cosmos/colin/329-handshake-refactor
Browse files Browse the repository at this point in the history
handshake refactor
  • Loading branch information
colin-axner committed Jan 5, 2021
2 parents db25632 + 465da7b commit 6ba534a
Show file tree
Hide file tree
Showing 40 changed files with 1,413 additions and 576 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/akash-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.14
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.15
id: go

# checkout relayer
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.14
- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: 1.14
go-version: 1.15

# setup gopath
- name: Set PATH
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gaia-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
# Install and setup go
- name: Set up Go 1.14
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.15
id: go

# checkout relayer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
version: latest
args: release --rm-dist --release-notes=../release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ get-chains: get-gaia get-akash

delete-chains:
@echo "Removing the ./chain-code/ directory..."
@rm -rf ./chain-code
@rm -rf ./chain-code
11 changes: 6 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ func cfgFilesAdd(dir string) (cfg *Config, err error) {
continue
}

if err = p.Validate(); err == nil {
fmt.Printf("added path %s...\n", pthName)
continue
} else if err != nil {
fmt.Printf("%s did not contain valid path config, skipping...\n", pth)
// TODO: Do bottom up validation
// For now, we assume that all chain files must have same filename as chain-id
// this is to ensure non-chain files (global config) does not get parsed into chain struct.
// Future work should implement bottom-up validation.
if c.ChainID != pthName {
fmt.Printf("Skipping non chain file: %s\n", f.Name())
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $ %s development faucet root /home/root ibc-1 testkey2 1000000stake`, appName, a
if err != nil {
return err
}
_, err = sdk.ParseCoin(args[4])
_, err = sdk.ParseCoinNormalized(args[4])
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ $ %s q clnt ibc-1 ibconeclient`, appName, appName, appName)),
return err
}

return chain.CLIContext(height).PrintOutput(res)
return chain.CLIContext(height).PrintProto(res)
},
}

Expand Down Expand Up @@ -546,7 +546,7 @@ $ %s q clnt-conns ibc-1 ibconeclient`, appName, appName, appName)),
return err
}

return chain.CLIContext(height).PrintOutput(res)
return chain.CLIContext(height).PrintProto(res)
},
}

Expand Down Expand Up @@ -582,7 +582,7 @@ $ %s q conn ibc-1 ibconeconn`, appName, appName)),
return err
}

return chain.CLIContext(height).PrintOutput(res)
return chain.CLIContext(height).PrintProto(res)
},
}

Expand Down Expand Up @@ -666,7 +666,7 @@ $ %s q chan ibc-1 ibconechannel transfer`, appName, appName, appName)),
return err
}

return chain.CLIContext(height).PrintOutput(res)
return chain.CLIContext(height).PrintProto(res)
},
}

Expand Down
108 changes: 27 additions & 81 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/cosmos/relayer/relayer"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -108,13 +107,8 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)),
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, consensusParams, chains[src].MustGetAddress())},
chains[dst].GetTrustingPeriod(), ubdPeriod, chains[src].MustGetAddress())},
chains[src], cmd)
},
}
Expand Down Expand Up @@ -179,38 +173,18 @@ $ %s tx raw conn-try ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`,
return err
}

// 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
dstConnState, err := chains[dst].QueryConnection(dsth.Header.Height - 1)
if err != nil {
return err
}

// We are querying the state of the client for src on dst and finding the height
dstClientStateRes, err := chains[dst].QueryClientState(dsth.Header.Height)
if err != nil {
return err
}
dstClientState, err := clienttypes.UnpackClientState(dstClientStateRes.ClientState)
updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}
dstCsHeight := dstClientState.GetLatestHeight()

// Then we need to query the consensus state for src at that height on dst
dstConsState, err := chains[dst].QueryClientConsensusState(dsth.Header.Height, dstCsHeight)
openTry, err := chains[src].PathEnd.ConnTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress())
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}
txs := []sdk.Msg{
chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()),
chains[src].PathEnd.ConnTry(chains[dst].PathEnd, dstClientStateRes, dstConnState,
dstConsState, chains[src].MustGetAddress()),
openTry,
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down Expand Up @@ -247,38 +221,19 @@ $ %s tx raw conn-ack ibc-0 ibc-1 ibconeclient ibczeroclient ibcconn1 ibcconn2`,
return err
}

// 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
dstState, err := chains[dst].QueryConnection(dsth.Header.Height - 1)
if err != nil {
return err
}

// We are querying the state of the client for src on dst and finding the height
dstClientStateResponse, err := chains[dst].QueryClientState(dsth.Header.Height)
updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}
dstClientState, _ := clienttypes.UnpackClientState(dstClientStateResponse.ClientState)
dstCsHeight := dstClientState.GetLatestHeight()

// Then we need to query the consensus state for src at that height on dst
dstConsState, err := chains[dst].QueryClientConsensusState(dsth.Header.Height, dstCsHeight)
openAck, err := chains[src].PathEnd.ConnAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress())
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}
txs := []sdk.Msg{
chains[src].PathEnd.ConnAck(
chains[dst].PathEnd,
dstClientStateResponse,
dstState, dstConsState,
chains[src].MustGetAddress()),
chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()),
openAck,
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down Expand Up @@ -364,20 +319,15 @@ $ %s tx raw conn-step ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`,
return err
}

msgs, err := chains[src].CreateConnectionStep(chains[dst])
if err != nil {
return err
}

if len(msgs.Src) > 0 {
if err = sendAndPrint(msgs.Src, chains[src], cmd); err != nil {
return err
}
} else if len(msgs.Dst) > 0 {
if err = sendAndPrint(msgs.Dst, chains[dst], cmd); err != nil {
_, _, modified, err := relayer.ExecuteConnectionStep(chains[src], chains[dst])
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
}
}
if err != nil {
return err
}

return nil
},
Expand Down Expand Up @@ -444,18 +394,19 @@ $ %s tx raw chan-try ibc-0 ibc-1 ibczeroclient ibcconn0 ibcchan1 ibcchan2 transf
return err
}

dstChanState, err := chains[dst].QueryChannel(dstHeader.Header.Height - 1)
updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
openTry, err := chains[src].PathEnd.ChanTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress())
if err != nil {
return err
}

txs := []sdk.Msg{
chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()),
chains[src].PathEnd.ChanTry(chains[dst].PathEnd, dstChanState, chains[src].MustGetAddress()),
openTry,
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down Expand Up @@ -494,18 +445,19 @@ $ %s tx raw chan-ack ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer transf
return err
}

dstChanState, err := chains[dst].QueryChannel(dstHeader.Header.Height - 1)
updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
openAck, err := chains[src].PathEnd.ChanAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1, chains[src].MustGetAddress())
if err != nil {
return err
}

txs := []sdk.Msg{
chains[src].PathEnd.UpdateClient(updateHeader, chains[src].MustGetAddress()),
chains[src].PathEnd.ChanAck(chains[dst].PathEnd, dstChanState, chains[src].MustGetAddress()),
openAck,
}

return sendAndPrint(txs, chains[src], cmd)
Expand Down Expand Up @@ -576,7 +528,6 @@ $ %s tx raw channel-step ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn
`, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
src, dst := args[0], args[1]
ordering := relayer.OrderFromString(args[10])
chains, err := config.Chains.Gets(src, dst)
if err != nil {
return err
Expand All @@ -590,20 +541,15 @@ $ %s tx raw channel-step ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn
return err
}

msgs, err := chains[src].CreateChannelStep(chains[dst], ordering)
if err != nil {
return err
}

if len(msgs.Src) > 0 {
if err = sendAndPrint(msgs.Src, chains[src], cmd); err != nil {
return err
}
} else if len(msgs.Dst) > 0 {
if err = sendAndPrint(msgs.Dst, chains[dst], cmd); err != nil {
_, _, modified, err := relayer.ExecuteChannelStep(chains[src], chains[dst])
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
}
}
if err != nil {
return err
}

return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/testnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $ %s tst faucet ibc-0 testkey 100000stake`, appName, appName)),
if err != nil {
return err
}
amount, err := sdk.ParseCoins(args[2])
amount, err := sdk.ParseCoinsNormalized(args[2])
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 6ba534a

Please sign in to comment.