Skip to content

Commit

Permalink
Merge PR #34: IBC Connection commands
Browse files Browse the repository at this point in the history
* Update to latest ibc-alpha

* Fix build

* Validate header locally

* Fetch next validator set

* Fix minor typo

* Query latest height from client state

* Debuggin 🐛 🔍 👢

* Update to latest SDK

* Merge PR #37: Play with the verifier

* Use light client API directly

* Remove all direct store access

* Add some comments and fix two-chainz

* Update to latest SDK

* Merge PR #38: verifier: update to the latest Tendermint light client

* refactor UpdateLiteDBsToLatestHeaders

* refactor GetLatestHeaders

* use channel

* close channel via defer

* update verifier to the latest lite version

ValidateBasic was removed because lite does this.

Co-authored-by: Jack Zampolin <[email protected]>

Co-authored-by: Jack Zampolin <[email protected]>
Co-authored-by: Anton Kaliaev <[email protected]>

* Update sdk version

* Update twochains to run create and update client

* Add ability to print transaction before sending

* Call ValidateBasic() on header

* Merge PR #44: Fix hanging errors

* Back to current versions of the SDK and TM, working clients, WIP connections

* New error

* Update two chains to take us to error

* Results from debugging with Chris and Aditya

* Working connection-step and expanded ci-chains test

* --pruning=nothing on ci-chains.sh

* Update upstream version

* Merge PR #45: Working Connection handshake

Co-authored-by: Christopher Goes <[email protected]>
Co-authored-by: Anton Kaliaev <[email protected]>
  • Loading branch information
3 people authored Mar 10, 2020
1 parent 8e79ed1 commit 053298f
Show file tree
Hide file tree
Showing 14 changed files with 753 additions and 303 deletions.
69 changes: 53 additions & 16 deletions ci-chains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ $GAIACLI config --home ibc0/n0/gaiacli/ node http://localhost:26657
$GAIACLI config --home ibc1/n0/gaiacli/ node http://localhost:26557

echo "Starting Gaiad instances..."
nohup $GAIAD --home ibc0/n0/gaiad start > ibc0.log &
nohup $GAIAD --home ibc1/n0/gaiad start > ibc1.log &
nohup $GAIAD --home ibc0/n0/gaiad start --pruning=nothing > ibc0.log &
nohup $GAIAD --home ibc1/n0/gaiad start --pruning=nothing > ibc1.log &

echo "Adding gaiacli keys to the relayer"
$RELAYER --home $RLY_CONF keys restore ibc0 testkey "$(jq -r '.secret' ibc0/n0/gaiacli/key_seed.json)" -a
Expand All @@ -49,30 +49,67 @@ $RELAYER --home $RLY_CONF keys restore ibc1 testkey "$(jq -r '.secret' ibc1/n0/g
echo "Wait for first block"
sleep 12

# VARIABLES FOR CHAINS
c0=ibc0
c1=ibc1
c0cl=ibconeclient
c1cl=ibczeroclient
c0conn=connectionidtest
c1conn=connectionidtest
c0conn2=connectionidtwo
c1conn2=connectionidtwo

echo "Check account balances"
$RELAYER --home $RLY_CONF q account ibc0
$RELAYER --home $RLY_CONF q account ibc1
$RELAYER --home $RLY_CONF q account $c0
$RELAYER --home $RLY_CONF q account $c1

echo "Initialize lite clients"
$RELAYER --home $RLY_CONF lite init ibc0 -f
$RELAYER --home $RLY_CONF lite init ibc1 -f
$RELAYER --home $RLY_CONF lite init $c0 -f
$RELAYER --home $RLY_CONF lite init $c1 -f

echo "Create clients"
$RELAYER --home $RLY_CONF tx client ibc0 ibc1 ibconeclient
$RELAYER --home $RLY_CONF tx client ibc1 ibc0 ibczeroclient
$RELAYER --home $RLY_CONF tx client $c0 $c1 $c0cl
$RELAYER --home $RLY_CONF tx client $c1 $c0 $c1cl

echo "Query headers"
$RELAYER --home $RLY_CONF q header ibc0
$RELAYER --home $RLY_CONF q header ibc0
$RELAYER --home $RLY_CONF q header $c0
$RELAYER --home $RLY_CONF q header $c0

echo "Query node-state"
$RELAYER --home $RLY_CONF q node-state ibc0
$RELAYER --home $RLY_CONF q node-state ibc0
$RELAYER --home $RLY_CONF q node-state $c0
$RELAYER --home $RLY_CONF q node-state $c0

echo "Querying client states"
$RELAYER --home $RLY_CONF q client ibc0 ibconeclient
$RELAYER --home $RLY_CONF q client ibc1 ibczeroclient
$RELAYER --home $RLY_CONF q client $c0 $c0cl
$RELAYER --home $RLY_CONF q client $c1 $c1cl

echo "Querying clients"
$RELAYER --home $RLY_CONF q clients ibc0
$RELAYER --home $RLY_CONF q clients ibc1
$RELAYER --home $RLY_CONF q clients $c0
$RELAYER --home $RLY_CONF q clients $c1

echo "Creating connection in steps"
sleep 5
$RELAYER --home $RLY_CONF tx connection-step $c0 $c1 $c0cl $c1cl $c0conn $c1conn
sleep 5
$RELAYER --home $RLY_CONF tx connection-step $c0 $c1 $c0cl $c1cl $c0conn $c1conn
sleep 5
$RELAYER --home $RLY_CONF tx connection-step $c0 $c1 $c0cl $c1cl $c0conn $c1conn
sleep 5
$RELAYER --home $RLY_CONF tx connection-step $c0 $c1 $c0cl $c1cl $c0conn $c1conn

echo "Creating raw connection"
$RELAYER --home $RLY_CONF tx raw conn-init $c0 $c1 $c0cl $c1cl $c0conn2 $c1conn2
sleep 5
$RELAYER --home $RLY_CONF tx raw conn-try $c1 $c0 $c1cl $c0cl $c1conn2 $c0conn2
sleep 5
$RELAYER --home $RLY_CONF tx raw conn-ack $c0 $c1 $c0cl $c1cl $c0conn2 $c1conn2
sleep 5
$RELAYER --home $RLY_CONF tx raw conn-confirm $c1 $c0 $c1cl $c0cl $c1conn2 $c0conn2

echo "Querying connections"
$RELAYER --home $RLY_CONF q connection $c0 $c0conn
$RELAYER --home $RLY_CONF q connection $c0 $c0conn2
$RELAYER --home $RLY_CONF q connection $c1 $c0conn
$RELAYER --home $RLY_CONF q connection $c1 $c0conn2
$RELAYER --home $RLY_CONF q connections $c0 $c0cl
$RELAYER --home $RLY_CONF q connections $c1 $c1cl
46 changes: 43 additions & 3 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/relayer/relayer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
Expand All @@ -19,6 +21,7 @@ var (
flagFlags = "flags"
flagTimeout = "timeout"
flagConfig = "config"
flagPrintTx = "print-tx"
)

func liteFlags(cmd *cobra.Command) *cobra.Command {
Expand All @@ -39,6 +42,12 @@ func paginationFlags(cmd *cobra.Command) *cobra.Command {
return cmd
}

func transactionFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagPrintTx, "p", false, "pass flag to print transactions before sending")
viper.BindPFlag(flagPrintTx, cmd.Flags().Lookup(flagPrintTx))
return outputFlags(cmd)
}

func outputFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagText, "t", false, "pass flag to force text output")
cmd.Flags().BoolP(flags.FlagIndentResponse, "i", false, "indent json output")
Expand All @@ -54,7 +63,7 @@ func addressFlag(cmd *cobra.Command) *cobra.Command {
}

func timeoutFlag(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(flagTimeout, "t", "8s", "timeout between relayer runs")
cmd.Flags().StringP(flagTimeout, "o", "8s", "timeout between relayer runs")
viper.BindPFlag(flagTimeout, cmd.Flags().Lookup(flagTimeout))
return cmd
}
Expand All @@ -79,11 +88,11 @@ func PrintOutput(toPrint interface{}, cmd *cobra.Command) error {
text, indent bool
)

text, err = cmd.Flags().GetBool("text")
text, err = cmd.Flags().GetBool(flagText)
if err != nil {
return err
}
indent, err = cmd.Flags().GetBool("indent")
indent, err = cmd.Flags().GetBool(flags.FlagIndentResponse)
if err != nil {
return err
}
Expand All @@ -104,3 +113,34 @@ func PrintOutput(toPrint interface{}, cmd *cobra.Command) error {
fmt.Println(string(out))
return nil
}

// PrintTxs prints transactions prior to sending if the flag has been passed in
func PrintTxs(toPrint interface{}, cmd *cobra.Command) error {
print, err := cmd.Flags().GetBool(flagPrintTx)
if err != nil {
return err
}

if print {
err = PrintOutput(toPrint, cmd)
if err != nil {
return err
}
}

return nil
}

// SendAndPrint sends the transaction with printing options from the CLI
func SendAndPrint(txs []sdk.Msg, chain *relayer.Chain, cmd *cobra.Command) (err error) {
if err = PrintTxs(txs, cmd); err != nil {
return err
}

res, err := chain.SendMsgs(txs)
if err != nil {
return err
}

return PrintOutput(res, cmd)
}
4 changes: 2 additions & 2 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func queryConnectionsUsingClient() *cobra.Command {
return err
}

if err := chain.PathConnection("passesvalidation", args[1]); err != nil {
if err := chain.PathConnection(args[1], "passesvalidation"); err != nil {
return chain.ErrCantSetPath(relayer.CONNPATH, err)
}

Expand All @@ -232,7 +232,7 @@ func queryConnectionsUsingClient() *cobra.Command {
return err
}

return PrintOutput(res, cmd)
return PrintOutput(res.ConnectionPaths, cmd)
},
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
codecstd "github.com/cosmos/cosmos-sdk/codec/std"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/simapp"
simappcodec "github.com/cosmos/cosmos-sdk/simapp/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting"
Expand All @@ -40,7 +40,7 @@ var (
config *Config
defaultHome = os.ExpandEnv("$HOME/.relayer")
cdc *codec.Codec
appCodec *simappcodec.Codec
appCodec *codecstd.Codec
)

func init() {
Expand All @@ -64,9 +64,9 @@ func init() {

// This is a bit of a cheat :shushing_face:
// TODO: Remove cdc in favor of appCodec once all modules are migrated.
cdc = simappcodec.MakeCodec(simapp.ModuleBasics)
cdc = codecstd.MakeCodec(simapp.ModuleBasics)

appCodec = simappcodec.NewAppCodec(cdc)
appCodec = codecstd.NewAppCodec(cdc)

cdc = codec.New()
sdk.RegisterCodec(cdc)
Expand Down
Loading

0 comments on commit 053298f

Please sign in to comment.