From c378fb6f57efd0b25cfcd7f87c0fd409ac8c2ccc Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 5 Nov 2019 18:20:44 +0100 Subject: [PATCH] IBC demo fixes (#5267) * 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 * Apply suggestions from code review Co-Authored-By: Jack Zampolin * 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 * Update x/ibc/02-client/types/tendermint/consensus_state.go Co-Authored-By: Jack Zampolin * 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 :man_dancing: * WIP channel shake :man_dancing: * WIP channel shake :man_dancing: * WIP channel shake :man_dancing: * WIP channel shake :man_dancing: * WIP channel shake :man_dancing: * WIP channel shake :man_dancing: * 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 --- client/keys/add.go | 38 +++++++++++++++++++-- client/keys/root.go | 3 +- types/coin.go | 4 +-- x/ibc/04-channel/client/cli/tx.go | 49 ++++++++++++++------------- x/ibc/20-transfer/client/cli/query.go | 6 ++-- x/ibc/20-transfer/client/cli/tx.go | 8 ++--- x/ibc/20-transfer/module.go | 5 +++ x/ibc/client/cli/cli.go | 2 ++ 8 files changed, 79 insertions(+), 36 deletions(-) diff --git a/client/keys/add.go b/client/keys/add.go index 60f4dfe20060..9ef7f0531046 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -39,8 +39,42 @@ const ( DefaultKeyPass = "12345678" ) -// AddKeyCommand defines a keys command to add a generated or recovered private key to keybase. -func AddKeyCommand() *cobra.Command { +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], keys.CreateHDPath(0, 0).String(), keys.Secp256k1) + if err != nil { + return err + } + + return printCreate(cmd, info, false, "") + }, + } + return cmd +} + +func addKeyCommand() *cobra.Command { cmd := &cobra.Command{ Use: "add ", Short: "Add an encrypted private key (either newly generated or recovered), encrypt it, and save to disk", diff --git a/client/keys/root.go b/client/keys/root.go index b7f70059c015..7786070e9109 100644 --- a/client/keys/root.go +++ b/client/keys/root.go @@ -21,7 +21,7 @@ func Commands() *cobra.Command { } cmd.AddCommand( MnemonicKeyCommand(), - AddKeyCommand(), + addKeyCommand(), ExportKeyCommand(), ImportKeyCommand(), ListKeysCmd(), @@ -31,6 +31,7 @@ func Commands() *cobra.Command { UpdateKeyCommand(), ParseKeyStringCommand(), MigrateCommand(), + addKeyScriptingCommand(), ) cmd.PersistentFlags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend)) diff --git a/types/coin.go b/types/coin.go index 98eaa6b806df..a23e3962e37e 100644 --- a/types/coin.go +++ b/types/coin.go @@ -594,8 +594,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:]]*` diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index 833ed29af01c..265ec880d73a 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -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" @@ -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) @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/x/ibc/20-transfer/client/cli/query.go b/x/ibc/20-transfer/client/cli/query.go index 1795e1919edb..4be0103385ee 100644 --- a/x/ibc/20-transfer/client/cli/query.go +++ b/x/ibc/20-transfer/client/cli/query.go @@ -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 diff --git a/x/ibc/20-transfer/client/cli/tx.go b/x/ibc/20-transfer/client/cli/tx.go index 28870567b55c..13917f47a62d 100644 --- a/x/ibc/20-transfer/client/cli/tx.go +++ b/x/ibc/20-transfer/client/cli/tx.go @@ -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" @@ -26,7 +26,7 @@ var ( FlagNode2 = "node2" FlagFrom1 = "from1" FlagFrom2 = "from2" - FlagChainId2 = "chain-id2" + FlagChainID2 = "chain-id2" FlagSequence = "packet-sequence" FlagTimeout = "timeout" ) @@ -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) @@ -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 diff --git a/x/ibc/20-transfer/module.go b/x/ibc/20-transfer/module.go index 269be2377f6e..a1e12ec35d8f 100644 --- a/x/ibc/20-transfer/module.go +++ b/x/ibc/20-transfer/module.go @@ -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) +} diff --git a/x/ibc/client/cli/cli.go b/x/ibc/client/cli/cli.go index cc6bd3bd7822..4818d68008d6 100644 --- a/x/ibc/client/cli/cli.go +++ b/x/ibc/client/cli/cli.go @@ -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 }