Skip to content

Commit

Permalink
IBC demo fixes (#5267)
Browse files Browse the repository at this point in the history
* WIP refactor ICS03

* remove Mapping

* remove store accessors

* proposed refactor

* remove store accessors from ICS02

* refactor queriers, handler and clean keeper

* logger and tx long description

* ineffassign

* Apply suggestions from code review

Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com>

* Apply suggestions from code review

Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com>

* remove store accessors

* refactor handshake to update it to the latest ICS03 spec

* update handler and msgs

* add verification functions

* update verification

* ICS02 module.go

* top level x/ibc structure

* update connection queries

* update connection tx

* remove extra files

* refactor: remove store accessors, update keeper and types to match spec (WIP)

* update handshake and packet

* implement packet timeouts

* implement send and receive packet

* implement packet ACK

* update handler

* add channel errors

* channel querier

* update expected client keeper and export verification funcs

* ICS 05 Implementation

* release port and godocs

* Update x/ibc/02-client/client/cli/query.go

Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com>

* Update x/ibc/02-client/types/tendermint/consensus_state.go

Co-Authored-By: Jack Zampolin <jack.zampolin@gmail.com>

* address some of the review comments

* resolve some TODOs and address comments from review

* update connection versioning

* minor error updates

* update ICS04 with downstream changes

* Implement tx cli actions

* add MsgSendPacket handler; msg validation, errors and events

* update errors and add port Keeper to ibc Keeper

* minor UX improvements

* rename pkg

* fixes

* refactor ICS23

* cleanup types

* ICS 5 updates (#5222)

* Validate port identifiers

* Refactor to static bind

* Add comments

* Add 'GetPorts' query function

* rename pkg and fix import

* implement batch verification

* gosimple suggestion

* various fixes; remove legacy tests; remove commitment path query

* alias

* minor updates from ICS23

* renaming

* update verification and rename root funcs

* rm legacy tests; add query proofs support

* remove capability key generation and authentication logic

* move querier to x/ibc

* update query.go to use 'custom/...' query path

* add tests

* ICS 24 Implementation (#5229)

* add validation functions

* validate path in ics-23

* address @fede comments

* move errors into host package

* flatten ICS23 structure

* fix ApplyPrefix

* updates from ICS23 and ICS24

* msg.ValidateBasic and ADR09 evidence interface

* complete types testing

* delete empty test file

* remove ibc errors from core error package

* custom JSON marshaling; msg.ValidateBasic; renaming of variables

* minor update

* custom JSON marshaling

* use host validation for port ids

* downstream changes; custom marshal JSON; msg validation, and update errors

* update errors and aliases

* start batch-verify tests

* update msg validation and CLI UX

* minor changes on commitment types

* fix channel and packet check (#5243)

* R4R - Store consensus state correctly (#5242)

* store consensus state correctly

* fix client example

* update alias

* update alias

* update alias and keeper.GetPort()

* authenticate port ID; remove send packet msg from CLI

* comment out handlers

* add ibc module to simapp

* ICS20 implementation (#5204)

* add ibc bank mock

* modify handler

* import channel

* add receiving logic

* add cli proof handling

* modify cli

* modify receiver type

* modify errcode

* optimize codes

* add denom prefix when source is true

* refactor code

* error return

* switch ibc antehandler to decorator pattern

* fix name/comment

* ICS 20 implementation (#5250)

* move ics20 code to 20-transfer

* clean code

* fix compiling error

* add transfer module

* address ICS20 comments from review

* add routing callbacks

* clean code

* add missing err return

* modify err type

* modify err type

* add supply handling

* modify proof type

* add comments for msg and packet data

* add timeout supply handling

* modify module account name

* use supply keeper for burn and mint coins

* restructure keeper

* update alias and module.go

* golangci linter

* add ics20 handler to IBC handler

* update callbacks

* update ICS20 escrow address

* fix querier routes

* fix create client cli

* minor updates

* ibc querier test

* Refactor ibc/mock/bank into ICS 20 (#5264)

* Most of code port from mock module to ICS 20

* A few minor fixes

* Apply suggestions from code review

Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>

* Fix suggestions from autolinter

* Apply suggestions from code review

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Fix order of messages

* Add invalid height error code, check non-nil proof

* Fix linter error

* Return the underlying error

* Tendermint starts at height 1

* Apply suggestions from code review

* setup ics20 test suite

* add event to MsgRecvPacket

* update ibc keeper test to use test suite

* Add handshake commands

* WIP connection handshake

* WIP Connection Handshake

* use testsuite

* Add cliCtx.WaitForNBlocks

* fix connection handshake in progress

* fix connection handshake in progress

* Add print debugging (old-school)

* Add log line

* More debugging

* Set prove flag to true

* More debugging

* Use store query

* Fix query, hopefully

* Fix query path

* Hmm

* Fix context bug

* Generate & return & use consensus state proof

* Print debugging

* Add debugging

* Begin working on the channel creation command

* remove submodule prefix from keypath, fix addConnectionToClients to treat nil as empty array

* fix OpenConfirm, rm debugging code

* WIP channel shake 🕺

* WIP channel shake 🕺

* WIP channel shake 🕺

* WIP channel shake 🕺

* WIP channel shake 🕺

* WIP channel shake 🕺

* WIP channel shake 🕺

* Update bound port

* Add from flag to ICS 20 commands

* Undefine flag

* add debug

* Uncomment channel message handlers

* fix validatebasic identifier failure

* Fix printing

* add debug code

* CLI debugging

* fix counterpartyHops, channel handshake working w/o port

* Fix compilation error

* Push channel query command update

* Remove unused code

* Add gaiacli keys test

* Update error

* Add printf

* fix token restriciton

* comment out port

* fix querier to retrieve the next sequence

* Alter command to take arguments

* Name it packet-sequence

* add packet query utils

* Use the querier

* Packet is JSON

* printf the value

* fix query packet

* fix packet receive in progress

* lol

* export Packet fields, rename Packet.XXX() -> Packet.GetXXX()

* fix route

* add debug

* comment out port logic from packet.go

* token transfer now working

* fix client tx

* Integrate Evidence Implementation into ICS-02 (#5258)

* implement evidence in ics-02

* fix build errors and import cycles

* address fede comments

* remove unnecessary pubkey and fix init

* add tests

* Apply suggestions from code review

* clean up

* finish tendermint tests

* complete merge

* Add tests for msgs

* ICS02 changes

* upstream changes

* fix

* upstream changes

* fix cons state

* context changes

* fix cli tx

* upstream changes

* upstream changes

* upstream changes

* upstream changes

* more cleanup
  • Loading branch information
cwgoes authored and fedekunze committed Nov 5, 2019
1 parent bd85998 commit 4dda39e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 33 deletions.
35 changes: 35 additions & 0 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ const (
DefaultKeyPass = "12345678"
)

func addKeyScriptingCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "test [name] [mnemonic] [password]",
Short: "Add a recovered mnemonic to the keystore encrypt it, and save to disk, for testing",
Long: `Derive a new private key from an existing mnemonic file and encrypt to disk.
NOTE: This is insecure and only meant to be used during testing!!!! HERE BE DRAGONS!
`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
kb, err := NewKeyBaseFromHomeFlag()
if err != nil {
return err
}

_, err = kb.Get(args[0])
if err == nil {
return errors.New("key already exists, exiting")
}

if !bip39.IsMnemonicValid(args[1]) {
return errors.New("invalid mnemonic")
}

info, err := kb.CreateAccount(args[0], args[1], "", args[2], 0, 0)
if err != nil {
return err
}

return printCreate(cmd, info, false, "")
},
}
return cmd
}

func addKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "add <name>",
Expand Down
1 change: 1 addition & 0 deletions client/keys/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func Commands() *cobra.Command {
updateKeyCommand(),
parseKeyStringCommand(),
migrateCommand(),
addKeyScriptingCommand(),
)
return cmd
}
4 changes: 2 additions & 2 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ func (coins Coins) Sort() Coins {
// Parsing

var (
// Denominations can be 3 ~ 16 characters long.
reDnmString = `[a-z][a-z0-9]{2,15}`
// Denominations can be 3 ~ 32 characters long.
reDnmString = `[a-z][a-z0-9/]{2,31}`
reAmt = `[[:digit:]]+`
reDecAmt = `[[:digit:]]*\.[[:digit:]]+`
reSpc = `[[:space:]]*`
Expand Down
49 changes: 25 additions & 24 deletions x/ibc/04-channel/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -356,17 +357,17 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
WithCodec(cdc).
WithBroadcastMode(flags.BroadcastBlock)

// // get passphrase for key from1
// passphrase1, err := keys.GetPassphrase(from1)
// if err != nil {
// return err
// }
// get passphrase for key from1
passphrase1, err := keys.GetPassphrase(from1)
if err != nil {
return err
}

// // get passphrase for key from2
// passphrase2, err := keys.GetPassphrase(from2)
// if err != nil {
// return err
// }
// get passphrase for key from2
passphrase2, err := keys.GetPassphrase(from2)
if err != nil {
return err
}

// TODO: check state and if not Idle continue existing process
viper.Set(flags.FlagChainID, cid1)
Expand All @@ -375,8 +376,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err := utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenInit})
if err != nil {
res, err := utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenInit}, passphrase1)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -395,8 +396,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -411,8 +412,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenTry})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgOpenTry}, passphrase2)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -431,8 +432,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgUpdateClient})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgUpdateClient}, passphrase1)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -448,8 +449,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenAck})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenAck}, passphrase1)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -468,8 +469,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2)
if err != nil || !res.IsOK() {
return err
}

Expand All @@ -484,8 +485,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm})
if err != nil {
res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm}, passphrase2)
if err != nil || !res.IsOK() {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions x/ibc/20-transfer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

// GetTxCmd returns the transaction commands for IBC fungible token transfer
func GetQueryCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
// GetQueryCmd returns the query commands for IBC fungible token transfer
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
queryCmd := &cobra.Command{
Use: "transfer",
Short: "IBC fungible token transfer query subcommands",
}

queryCmd.AddCommand(
GetCmdQueryNextSequence(cdc, storeKey),
GetCmdQueryNextSequence(cdc, queryRoute),
)

return queryCmd
Expand Down
8 changes: 4 additions & 4 deletions x/ibc/20-transfer/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
clientutils "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
channelutils "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment"
Expand All @@ -26,7 +26,7 @@ var (
FlagNode2 = "node2"
FlagFrom1 = "from1"
FlagFrom2 = "from2"
FlagChainId2 = "chain-id2"
FlagChainID2 = "chain-id2"
FlagSequence = "packet-sequence"
FlagTimeout = "timeout"
)
Expand Down Expand Up @@ -96,7 +96,7 @@ func GetMsgRecvPacketCmd(cdc *codec.Codec) *cobra.Command {

node2 := viper.GetString(FlagNode2)
cid1 := viper.GetString(flags.FlagChainID)
cid2 := viper.GetString(FlagChainId2)
cid2 := viper.GetString(FlagChainID2)
cliCtx2 := context.NewCLIContextIBC(cliCtx.GetFromAddress().String(), cid2, node2).
WithCodec(cdc).
WithBroadcastMode(flags.BroadcastBlock)
Expand Down Expand Up @@ -143,7 +143,7 @@ func GetMsgRecvPacketCmd(cdc *codec.Codec) *cobra.Command {
cmd = client.PostCommands(cmd)[0]
cmd.Flags().Bool(FlagSource, false, "Pass flag for sending token from the source chain")
cmd.Flags().String(FlagNode2, "tcp://localhost:26657", "RPC port for the second chain")
cmd.Flags().String(FlagChainId2, "", "chain-id for the second chain")
cmd.Flags().String(FlagChainID2, "", "chain-id for the second chain")
cmd.Flags().String(FlagSequence, "", "sequence for the packet")
cmd.Flags().String(FlagTimeout, "", "timeout for the packet")
return cmd
Expand Down
5 changes: 5 additions & 0 deletions x/ibc/20-transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ func Name() string {
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetTxCmd(cdc)
}

// GetQueryCmd returns the root tx command for the IBC transfer.
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
return cli.GetQueryCmd(cdc, queryRoute)
}
2 changes: 2 additions & 0 deletions x/ibc/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
ibcQueryCmd.AddCommand(client.GetCommands(
ibcclient.GetQueryCmd(cdc, queryRoute),
connection.GetQueryCmd(cdc, queryRoute),
channel.GetQueryCmd(cdc, queryRoute),
transfer.GetQueryCmd(cdc, queryRoute),
)...)
return ibcQueryCmd
}

0 comments on commit 4dda39e

Please sign in to comment.