Skip to content

Commit

Permalink
IBC v1.0.0 (#5245)
Browse files Browse the repository at this point in the history
* applying review in progress

* apply review - make querier interface

* fix cli errors

* fix dependency

* fix dependency

* reflect method name change

* revise querier interface to work both on cli & store

* revise querier interface to work both on cli & store

* revise querier interface to work both on cli & store

* reflect downstream change

* fix cli

* reflect downstream changes

* reflect downstream changes

* fix from address in tx cli

* fix cli in progress(squash later)

* fix cli

* remove timeout, add channel cli

* fix golangci

* fix cli

* Clean up

* fix mock cli in progress

* finalize cleanup, mock cli wip

* add cli for mocksend

* fix handler

* rm commented lines

* address review in progress

* address review, rm cleanup/closing

* rename mock packages

* fix interface for gaia

* rename Path -> Prefix

* Store accessor upstream changes (#5119)

* Store accessor upstream changes (#5119)

* add comments, reformat merkle querier

* rm merkle/utils

* ICS 23 upstream changes (#5120)

* ICS 23 upstream changes (#5120)

* update Value

* update test

* fix

* ICS 02 upstream changes (#5122)

* ICS 02 upstream changes (#5122)

* ICS 03 upstream changes (#5123)

* ICS 03 upstream changes (#5123)

* update test

* cleanup types and submodule

* more cleanup and godocs

* remove counterPartyManager/State and cleanup

* implement SubmitMisbehaviour and refactor

* errors

* events

* fix test

* refactors

* 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

* 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

* finish tendermint tests

* complete merge

* Add tests for msgs

* upstream changes

* fix

* upstream changes

* fix cons state

* context changes

* fix cli tx

* upstream changes

* upstream changes

* upstream changes

* upstream changes
  • Loading branch information
fedekunze authored Nov 5, 2019
1 parent 87d09fd commit bd85998
Show file tree
Hide file tree
Showing 32 changed files with 1,569 additions and 40 deletions.
24 changes: 16 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
ibctransfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
Expand Down Expand Up @@ -54,16 +56,18 @@ var (
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
ibctransfer.GetModuleAccountName(): {supply.Minter, supply.Burner},
}
)

Expand Down Expand Up @@ -101,6 +105,7 @@ type SimApp struct {
GovKeeper gov.Keeper
CrisisKeeper crisis.Keeper
ParamsKeeper params.Keeper
IBCKeeper ibc.Keeper

// the module manager
mm *module.Manager
Expand All @@ -123,7 +128,7 @@ func NewSimApp(

keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey)
gov.StoreKey, params.StoreKey, ibc.StoreKey)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

app := &SimApp{
Expand Down Expand Up @@ -172,6 +177,8 @@ func NewSimApp(
staking.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

app.IBCKeeper = ibc.NewKeeper(app.cdc, keys[ibc.StoreKey], ibc.DefaultCodespace, app.BankKeeper, app.SupplyKeeper)

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
Expand All @@ -185,6 +192,7 @@ func NewSimApp(
distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.StakingKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
ibc.NewAppModule(app.IBCKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -200,7 +208,7 @@ func NewSimApp(
auth.ModuleName, distr.ModuleName, staking.ModuleName,
bank.ModuleName, slashing.ModuleName, gov.ModuleName,
mint.ModuleName, supply.ModuleName, crisis.ModuleName,
genutil.ModuleName,
ibc.ModuleName, genutil.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
9 changes: 9 additions & 0 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ type TxResponse struct {
Events StringEvents `json:"events,omitempty"`
}

func (res TxResponse) IsOK() bool {
for _, lg := range res.Logs {
if !lg.Success {
return false
}
}
return true
}

// NewResponseResultTx returns a TxResponse given a ResultTx from tendermint
func NewResponseResultTx(res *ctypes.ResultTx, tx Tx, timestamp string) TxResponse {
if res == nil {
Expand Down
39 changes: 39 additions & 0 deletions x/auth/client/utils/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,45 @@ func CompleteAndBroadcastTxCLI(txBldr authtypes.TxBuilder, cliCtx context.CLICon
return cliCtx.PrintOutput(res)
}

// CompleteAndBroadcastTx implements a utility function that facilitates
// sending a series of messages in a signed transaction given a TxBuilder and a
// QueryContext. It ensures that the account exists, has a proper number and
// sequence set. In addition, it builds and signs a transaction non-interactively
// with the supplied messages. Finally, it broadcasts the signed transaction to a node.
func CompleteAndBroadcastTx(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg, passphrase string) (sdk.TxResponse, error) {
var res sdk.TxResponse
txBldr, err := PrepareTxBuilder(txBldr, cliCtx)
if err != nil {
return res, err
}

fromName := cliCtx.GetFromName()

if txBldr.SimulateAndExecute() || cliCtx.Simulate {
txBldr, err = EnrichWithGas(txBldr, cliCtx, msgs)
if err != nil {
return res, err
}

gasEst := GasEstimateResponse{GasEstimate: txBldr.Gas()}
_, _ = fmt.Fprintf(os.Stderr, "%s\n", gasEst.String())
}

// build and sign the transaction
txBytes, err := txBldr.BuildAndSign(fromName, passphrase, msgs)
if err != nil {
return res, err
}

// broadcast to a Tendermint node
res, err = cliCtx.BroadcastTx(txBytes)
if err != nil {
return res, err
}

return res, err
}

// EnrichWithGas calculates the gas estimate that would be consumed by the
// transaction and set the transaction's respective value accordingly.
func EnrichWithGas(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (authtypes.TxBuilder, error) {
Expand Down
66 changes: 45 additions & 21 deletions x/ibc/03-connection/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -349,6 +350,18 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
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
}

viper.Set(flags.FlagChainID, cid1)
msgOpenInit := types.NewMsgConnectionOpenInit(
connID1, clientID1, connID2, clientID2,
Expand All @@ -359,11 +372,14 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenInit})
if err != nil {
fmt.Printf("%v <- %-14v", cid1, msgOpenInit.Type())
res, err := utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenInit}, passphrase1)
if err != nil || !res.IsOK() {
return err
}

fmt.Printf(" [OK] txid(%v) client(%v) conn(%v)\n", res.TxHash, clientID1, connID1)

// Another block has to be passed after msgOpenInit is committed
// to retrieve the correct proofs
// TODO: Modify this to actually check two blocks being processed, and
Expand All @@ -383,11 +399,12 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient})
if err != nil {
fmt.Printf("%v <- %-14v", cid2, msgUpdateClient.Type())
res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2)
if err != nil || !res.IsOK() {
return err
}
fmt.Printf(" [OK] client(%v)\n", clientID1)
fmt.Printf(" [OK] txid(%v) client(%v)\n", res.TxHash, clientID1)

// Fetch proofs from cid1
viper.Set(flags.FlagChainID, cid1)
Expand All @@ -409,12 +426,14 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenTry})
if err != nil {
fmt.Printf("%v <- %-14v", cid2, msgOpenTry.Type())

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

fmt.Printf(" [OK] client(%v) connection(%v)\n", clientID2, connID2)
fmt.Printf(" [OK] txid(%v) client(%v) connection(%v)\n", res.TxHash, clientID2, connID2)

// Another block has to be passed after msgOpenInit is committed
// to retrieve the correct proofs
Expand All @@ -435,11 +454,11 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
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
}
fmt.Printf(" [OK] client(%v)\n", clientID2)
fmt.Printf(" [OK] txid(%v) client(%v)\n", res.TxHash, clientID2)

// Fetch proofs from cid2
viper.Set(flags.FlagChainID, cid2)
Expand All @@ -461,11 +480,13 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenAck})
if err != nil {
fmt.Printf("%v <- %-14v", cid1, msgOpenAck.Type())

res, err = utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenAck}, passphrase1)
if err != nil || !res.IsOK() {
return err
}
fmt.Printf(" [OK] connection(%v)\n", connID1)
fmt.Printf(" [OK] txid(%v) connection(%v)\n", res.TxHash, connID1)

// Another block has to be passed after msgOpenInit is committed
// to retrieve the correct proofs
Expand All @@ -486,13 +507,14 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient})
if err != nil {
fmt.Printf("%v <- %-14v", cid2, msgUpdateClient.Type())

res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2)
if err != nil || !res.IsOK() {
return err
}
fmt.Printf(" [OK] client(%v)\n", clientID1)
fmt.Printf(" [OK] txid(%v) client(%v)\n", res.TxHash, clientID1)

// Fetch proof from cid1
viper.Set(flags.FlagChainID, cid1)
proofs, err = queryProofs(ctx1.WithHeight(header.Height-1), connID1, storeKey)
if err != nil {
Expand All @@ -507,11 +529,13 @@ func GetCmdHandshakeState(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}

err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm})
if err != nil {
fmt.Printf("%v <- %-14v", cid1, msgOpenConfirm.Type())

res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm}, passphrase2)
if err != nil || !res.IsOK() {
return err
}
fmt.Printf(" [OK] connection(%v)\n", connID2)
fmt.Printf(" [OK] txid(%v) connection(%v)\n", res.TxHash, connID2)

return nil
},
Expand Down
62 changes: 62 additions & 0 deletions x/ibc/20-transfer/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package transfer

// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types

import (
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
)

const (
DefaultPacketTimeout = keeper.DefaultPacketTimeout
DefaultCodespace = types.DefaultCodespace
CodeInvalidAddress = types.CodeInvalidAddress
CodeErrSendPacket = types.CodeErrSendPacket
CodeInvalidPacketData = types.CodeInvalidPacketData
CodeInvalidChannelOrder = types.CodeInvalidChannelOrder
CodeInvalidPort = types.CodeInvalidPort
CodeInvalidVersion = types.CodeInvalidVersion
AttributeKeyReceiver = types.AttributeKeyReceiver
SubModuleName = types.SubModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QuerierRoute = types.QuerierRoute
BoundPortID = types.BoundPortID
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
RegisterCodec = types.RegisterCodec
ErrInvalidAddress = types.ErrInvalidAddress
ErrSendPacket = types.ErrSendPacket
ErrInvalidPacketData = types.ErrInvalidPacketData
ErrInvalidChannelOrder = types.ErrInvalidChannelOrder
ErrInvalidPort = types.ErrInvalidPort
ErrInvalidVersion = types.ErrInvalidVersion
GetEscrowAddress = types.GetEscrowAddress
GetDenomPrefix = types.GetDenomPrefix
GetModuleAccountName = types.GetModuleAccountName
NewMsgTransfer = types.NewMsgTransfer

// variable aliases
ModuleCdc = types.ModuleCdc
AttributeValueCategory = types.AttributeValueCategory
)

type (
Keeper = keeper.Keeper
BankKeeper = types.BankKeeper
ChannelKeeper = types.ChannelKeeper
ClientKeeper = types.ClientKeeper
ConnectionKeeper = types.ConnectionKeeper
SupplyKeeper = types.SupplyKeeper
MsgTransfer = types.MsgTransfer
MsgRecvPacket = types.MsgRecvPacket
PacketData = types.PacketData
PacketDataAlias = types.PacketDataAlias
)
Loading

0 comments on commit bd85998

Please sign in to comment.