From ae0629b74c626dd9269281c88c8c6eb514ceece9 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Wed, 10 Nov 2021 23:21:58 +0900 Subject: [PATCH 1/6] middleware support for ICS20 --- modules/apps/transfer/ibc_module.go | 34 ++++++++++++++++--- modules/apps/transfer/keeper/keeper.go | 4 ++- modules/apps/transfer/keeper/msg_server.go | 11 +++++- modules/apps/transfer/keeper/relay.go | 14 ++------ .../apps/transfer/types/expected_keepers.go | 6 +++- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index e81d9d933fc..7b7426bfe2a 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -19,6 +19,7 @@ import ( // IBCModule implements the ICS26 interface for transfer given the transfer keeper. type IBCModule struct { keeper keeper.Keeper + app porttypes.IBCModule } // NewIBCModule creates a new IBCModule given the keeper @@ -64,6 +65,11 @@ func ValidateTransferChannelParams( return nil } +// SetMiddleware sets ICS30 middleware +func (im IBCModule) SetMiddleware(app porttypes.IBCModule) { + im.app = app +} + // OnChanOpenInit implements the IBCModule interface func (im IBCModule) OnChanOpenInit( ctx sdk.Context, @@ -84,7 +90,13 @@ func (im IBCModule) OnChanOpenInit( return err } - return nil + if im.app == nil { + return nil + } + + // call underlying app's OnChanOpenInit callback with the appVersion + return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, + chanCap, counterparty, version) } // OnChanOpenTry implements the IBCModule interface @@ -131,7 +143,12 @@ func (im IBCModule) OnChanOpenAck( if counterpartyVersion != types.Version { return sdkerrors.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: %s, expected %s", counterpartyVersion, types.Version) } - return nil + + if im.app == nil { + return nil + } + // call underlying app's OnChanOpenAck callback with the counterparty app version. + return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion) } // OnChanOpenConfirm implements the IBCModule interface @@ -249,7 +266,12 @@ func (im IBCModule) OnAcknowledgementPacket( ) } - return nil + if im.app == nil { + return nil + } + + // call underlying app's OnAcknowledgementPacket callback. + return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) } // OnTimeoutPacket implements the IBCModule interface @@ -277,7 +299,11 @@ func (im IBCModule) OnTimeoutPacket( ), ) - return nil + if im.app == nil { + return nil + } + + return im.app.OnTimeoutPacket(ctx, packet, relayer) } // NegotiateAppVersion implements the IBCModule interface diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index f0533aa2e51..4b513ff0204 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -21,6 +21,7 @@ type Keeper struct { cdc codec.BinaryCodec paramSpace paramtypes.Subspace + ics4Wrapper types.ICS4Wrapper channelKeeper types.ChannelKeeper portKeeper types.PortKeeper authKeeper types.AccountKeeper @@ -31,7 +32,7 @@ type Keeper struct { // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, + ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { @@ -49,6 +50,7 @@ func NewKeeper( cdc: cdc, storeKey: key, paramSpace: paramSpace, + ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, authKeeper: authKeeper, diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 42b5b8f03b1..e3e86294f0b 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -2,6 +2,9 @@ package keeper import ( "context" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v2/modules/core/24-host" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types" @@ -19,8 +22,14 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. if err != nil { return nil, err } + + channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(msg.SourcePort, msg.SourceChannel)) + if !ok { + return nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } + if err := k.SendTransfer( - ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, + ctx, channelCap, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, ); err != nil { return nil, err } diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index f346bc3d976..a2c3c847a15 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "strings" "github.com/armon/go-metrics" @@ -12,7 +13,6 @@ import ( "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v2/modules/core/24-host" coretypes "github.com/cosmos/ibc-go/v2/modules/core/types" ) @@ -50,6 +50,7 @@ import ( // 6. B -> A : sender chain is sink zone. Denom upon receiving: 'denom' func (k Keeper) SendTransfer( ctx sdk.Context, + chanCap *capabilitytypes.Capability, sourcePort, sourceChannel string, token sdk.Coin, @@ -82,11 +83,6 @@ func (k Keeper) SendTransfer( // begin createOutgoingPacket logic // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay - channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) - if !ok { - return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") - } - // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic fullDenomPath := token.Denom @@ -158,10 +154,6 @@ func (k Keeper) SendTransfer( timeoutTimestamp, ) - if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil { - return err - } - defer func() { if token.Amount.IsInt64() { telemetry.SetGaugeWithLabels( @@ -178,7 +170,7 @@ func (k Keeper) SendTransfer( ) }() - return nil + return k.ics4Wrapper.SendPacket(ctx, chanCap, packet) } // OnRecvPacket processes a cross chain fungible token transfer. If the diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index fd0f7df76c3..01f660e6fea 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -24,11 +24,15 @@ type BankKeeper interface { SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } +// ICS4Wrapper defines the expected ICS4Wrapper for middleware +type ICS4Wrapper interface { + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error +} + // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error } // ClientKeeper defines the expected IBC client keeper From 9b4ac3605b45625858ac051b4c6f85ad409ee85c Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Tue, 16 Nov 2021 16:05:03 +0900 Subject: [PATCH 2/6] update tests --- .../apps/transfer/keeper/mbt_relay_test.go | 28 +++++++++++++------ modules/apps/transfer/keeper/relay_test.go | 15 +++++++--- testing/simapp/app.go | 4 +-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index fb22f29dfc4..2661a7897ca 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -7,6 +7,7 @@ package keeper_test import ( "encoding/json" "fmt" + host "github.com/cosmos/ibc-go/v2/modules/core/24-host" "io/ioutil" "strconv" "strings" @@ -337,16 +338,25 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { if !ok { panic("MBT failed to parse amount from string") } - err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( - suite.chainB.GetContext(), - tc.packet.SourcePort, - tc.packet.SourceChannel, - sdk.NewCoin(denom, amount), - sender, - tc.packet.Data.Receiver, - clienttypes.NewHeight(0, 110), - 0) + + channelCap, ok := suite.chainB.GetSimApp().ScopedTransferKeeper.GetCapability( + suite.chainB.GetContext(), host.ChannelCapabilityPath(tc.packet.SourcePort, tc.packet.SourceChannel)) + if !ok { + err = sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } else { + err = suite.chainB.GetSimApp().TransferKeeper.SendTransfer( + suite.chainB.GetContext(), + channelCap, + tc.packet.SourcePort, + tc.packet.SourceChannel, + sdk.NewCoin(denom, amount), + sender, + tc.packet.Data.Receiver, + clienttypes.NewHeight(0, 110), + 0) + } } + case "OnRecvPacket": err = suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, tc.packet.Data) case "OnTimeoutPacket": diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 697059bf629..cabe18ba1f5 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v2/testing/simapp" @@ -116,10 +117,16 @@ func (suite *KeeperTestSuite) TestSendTransfer() { suite.Require().NoError(err) // message committed } - err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( - suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, - suite.chainA.SenderAccount.GetAddress(), suite.chainB.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0, - ) + channelCap, ok := suite.chainA.GetSimApp().ScopedTransferKeeper.GetCapability( + suite.chainA.GetContext(), host.ChannelCapabilityPath(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)) + if !ok { + err = sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + } else { + err = suite.chainA.GetSimApp().TransferKeeper.SendTransfer( + suite.chainA.GetContext(), channelCap, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, amount, + suite.chainA.SenderAccount.GetAddress(), suite.chainB.SenderAccount.GetAddress().String(), clienttypes.NewHeight(0, 110), 0, + ) + } if tc.expPass { suite.Require().NoError(err) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 5c9eedf6767..6496d6db4f4 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -318,13 +318,13 @@ func NewSimApp( // Create Transfer Keepers app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) transferModule := transfer.NewAppModule(app.TransferKeeper) transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) // NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do - // note replicate if you do not need to test core IBC or light clients. + // not replicate if you do not need to test core IBC or light clients. mockModule := ibcmock.NewAppModule(scopedIBCMockKeeper, &app.IBCKeeper.PortKeeper) mockIBCModule := ibcmock.NewIBCModule(&ibcmock.MockIBCApp{}, scopedIBCMockKeeper) From e18c29f3468a9bf05d3e5d3283cf6434d8192bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= Date: Wed, 29 Dec 2021 15:59:42 +0100 Subject: [PATCH 3/6] fix and changelog --- CHANGELOG.md | 3 ++- modules/apps/transfer/ibc_module.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f977789ec8e..8c055c9b37c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#404](https://github.com/cosmos/ibc-go/pull/404) Bump Go version to 1.17 ### API Breaking - + +* (transfer) [\#533](https://github.com/cosmos/ibc-go/pull/533) Add ICS30 Middleware support to transfer module. * (core) [\#650](https://github.com/cosmos/ibc-go/pull/650) Modify `OnChanOpenTry` IBC application module callback to return the negotiated app version. The version passed into the `MsgChanOpenTry` has been deprecated and will be ignored by core IBC. * (core) [\#629](https://github.com/cosmos/ibc-go/pull/629) Removes the `GetProofSpecs` from the ClientState interface. This function was previously unused by core IBC. * (transfer) [\#517](https://github.com/cosmos/ibc-go/pull/517) Separates the ICS 26 callback functions from `AppModule` into a new type `IBCModule` for ICS 20 transfer. diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index 9272853458e..b9f34044dd2 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -62,7 +62,7 @@ func ValidateTransferChannelParams( } // SetMiddleware sets ICS30 middleware -func (im IBCModule) SetMiddleware(app porttypes.IBCModule) { +func (im *IBCModule) SetMiddleware(app porttypes.IBCModule) { im.app = app } From 5826f83de54d6705dbffcc56ce24585fe05bbf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= Date: Fri, 31 Dec 2021 15:32:39 +0100 Subject: [PATCH 4/6] test fixes --- .../controller/keeper/grpc_query.go | 1 + .../controller/keeper/relay.go | 4 ++-- .../host/keeper/grpc_query.go | 1 + .../apps/transfer/keeper/mbt_relay_test.go | 5 +++-- modules/apps/transfer/keeper/msg_server.go | 5 +++-- modules/apps/transfer/types/msgs.go | 2 +- modules/core/02-client/legacy/v100/store.go | 2 +- modules/core/02-client/types/msgs.go | 8 ++++---- modules/core/03-connection/types/msgs.go | 8 ++++---- modules/core/04-channel/keeper/keeper.go | 2 +- modules/core/04-channel/types/msgs.go | 20 +++++++++---------- modules/core/24-host/validate.go | 2 +- modules/core/keeper/msg_server.go | 8 ++++---- testing/simapp/params/proto.go | 1 + 14 files changed, 37 insertions(+), 32 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go b/modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go index deb5cfae106..3451105aaee 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" ) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index caf56bd430e..8d52e3fcf1d 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -49,8 +49,8 @@ func (k Keeper) createOutgoingPacket( return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", sourceChannel, sourcePort) } - // timeoutTimestamp is set to be a max number here so that we never recieve a timeout - // ics-27-1 uses ordered channels which can close upon recieving a timeout, which is an undesired effect + // timeoutTimestamp is set to be a max number here so that we never receive a timeout + // ics-27-1 uses ordered channels which can close upon receiving a timeout, which is an undesired effect const timeoutTimestamp = ^uint64(0) >> 1 // Shift the unsigned bit to satisfy hermes relayer timestamp conversion packet := channeltypes.NewPacket( diff --git a/modules/apps/27-interchain-accounts/host/keeper/grpc_query.go b/modules/apps/27-interchain-accounts/host/keeper/grpc_query.go index f2df68d5ca2..d60bf85aaf1 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/grpc_query.go +++ b/modules/apps/27-interchain-accounts/host/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" ) diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index e7d6dfad619..143aa824975 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -7,11 +7,12 @@ package keeper_test import ( "encoding/json" "fmt" - host "github.com/cosmos/ibc-go/v2/modules/core/24-host" "io/ioutil" "strconv" "strings" + host "github.com/cosmos/ibc-go/v3/modules/core/24-host" + "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" @@ -281,7 +282,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { panic(fmt.Errorf("Failed to read model-based test files: %w", err)) } for _, file_info := range files { - var tlaTestCases = []TlaOnRecvPacketTestCase{} + tlaTestCases := []TlaOnRecvPacketTestCase{} if !strings.HasSuffix(file_info.Name(), ".json") { continue } diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 7122203f6d5..b2c5ac15ebd 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -2,9 +2,10 @@ package keeper import ( "context" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v2/modules/core/24-host" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v3/modules/core/24-host" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index 75b29dbdfde..40a3f561937 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -15,7 +15,7 @@ const ( ) // NewMsgTransfer creates a new MsgTransfer instance -//nolint:interfacer + func NewMsgTransfer( sourcePort, sourceChannel string, token sdk.Coin, sender, receiver string, diff --git a/modules/core/02-client/legacy/v100/store.go b/modules/core/02-client/legacy/v100/store.go index f92aa224676..f49ef26b1b9 100644 --- a/modules/core/02-client/legacy/v100/store.go +++ b/modules/core/02-client/legacy/v100/store.go @@ -110,7 +110,7 @@ func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) return nil } -// migrateSolomachine migrates the solomachine from v1 to v2 solo machine protobuf defintion. +// migrateSolomachine migrates the solomachine from v1 to v2 solo machine protobuf definition. func migrateSolomachine(clientState *ClientState) *smtypes.ClientState { isFrozen := clientState.FrozenSequence != 0 consensusState := &smtypes.ConsensusState{ diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index 78e025e33cf..10f822672ca 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -29,7 +29,7 @@ var ( ) // NewMsgCreateClient creates a new MsgCreateClient instance -//nolint:interfacer + func NewMsgCreateClient( clientState exported.ClientState, consensusState exported.ConsensusState, signer string, ) (*MsgCreateClient, error) { @@ -102,7 +102,7 @@ func (msg MsgCreateClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) err } // NewMsgUpdateClient creates a new MsgUpdateClient instance -//nolint:interfacer + func NewMsgUpdateClient(id string, header exported.Header, signer string) (*MsgUpdateClient, error) { anyHeader, err := PackHeader(header) if err != nil { @@ -151,7 +151,7 @@ func (msg MsgUpdateClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) err } // NewMsgUpgradeClient creates a new MsgUpgradeClient instance -// nolint: interfacer + func NewMsgUpgradeClient(clientID string, clientState exported.ClientState, consState exported.ConsensusState, proofUpgradeClient, proofUpgradeConsState []byte, signer string) (*MsgUpgradeClient, error) { anyClient, err := PackClientState(clientState) @@ -227,7 +227,7 @@ func (msg MsgUpgradeClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) er } // NewMsgSubmitMisbehaviour creates a new MsgSubmitMisbehaviour instance. -//nolint:interfacer + func NewMsgSubmitMisbehaviour(clientID string, misbehaviour exported.Misbehaviour, signer string) (*MsgSubmitMisbehaviour, error) { anyMisbehaviour, err := PackMisbehaviour(misbehaviour) if err != nil { diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index d2041bd76ba..c87049abe20 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -22,7 +22,7 @@ var ( // NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance. It sets the // counterparty connection identifier to be empty. -//nolint:interfacer + func NewMsgConnectionOpenInit( clientID, counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix, @@ -71,7 +71,7 @@ func (msg MsgConnectionOpenInit) GetSigners() []sdk.AccAddress { } // NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance -//nolint:interfacer + func NewMsgConnectionOpenTry( previousConnectionID, clientID, counterpartyConnectionID, counterpartyClientID string, counterpartyClient exported.ClientState, @@ -168,7 +168,7 @@ func (msg MsgConnectionOpenTry) GetSigners() []sdk.AccAddress { } // NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance -//nolint:interfacer + func NewMsgConnectionOpenAck( connectionID, counterpartyConnectionID string, counterpartyClient exported.ClientState, proofTry, proofClient, proofConsensus []byte, @@ -249,7 +249,7 @@ func (msg MsgConnectionOpenAck) GetSigners() []sdk.AccAddress { } // NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance -//nolint:interfacer + func NewMsgConnectionOpenConfirm( connectionID string, proofAck []byte, proofHeight clienttypes.Height, signer string, diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 67396423d48..0259ec5feda 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -403,7 +403,7 @@ func (k Keeper) GetChannelClientState(ctx sdk.Context, portID, channelID string) return connection.ClientId, clientState, nil } -// GetConnection wraps the conenction keeper's GetConnection function. +// GetConnection wraps the connection keeper's GetConnection function. func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (exported.ConnectionI, error) { connection, found := k.connectionKeeper.GetConnection(ctx, connectionID) if !found { diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index b6e625ff32e..42b7e9aebcf 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -14,7 +14,7 @@ var _ sdk.Msg = &MsgChannelOpenInit{} // NewMsgChannelOpenInit creates a new MsgChannelOpenInit. It sets the counterparty channel // identifier to be empty. -// nolint:interfacer + func NewMsgChannelOpenInit( portID, version string, channelOrder Order, connectionHops []string, counterpartyPortID string, signer string, @@ -63,7 +63,7 @@ var _ sdk.Msg = &MsgChannelOpenTry{} // NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance // The version string is deprecated and will be ignored by core IBC. // It is left as an argument for go API backwards compatibility. -// nolint:interfacer + func NewMsgChannelOpenTry( portID, previousChannelID, version string, channelOrder Order, connectionHops []string, counterpartyPortID, counterpartyChannelID, counterpartyVersion string, @@ -128,7 +128,7 @@ func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgChannelOpenAck{} // NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance -// nolint:interfacer + func NewMsgChannelOpenAck( portID, channelID, counterpartyChannelID string, cpv string, proofTry []byte, proofHeight clienttypes.Height, signer string, @@ -180,7 +180,7 @@ func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgChannelOpenConfirm{} // NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance -// nolint:interfacer + func NewMsgChannelOpenConfirm( portID, channelID string, proofAck []byte, proofHeight clienttypes.Height, signer string, @@ -227,7 +227,7 @@ func (msg MsgChannelOpenConfirm) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgChannelCloseInit{} // NewMsgChannelCloseInit creates a new MsgChannelCloseInit instance -// nolint:interfacer + func NewMsgChannelCloseInit( portID string, channelID string, signer string, ) *MsgChannelCloseInit { @@ -265,7 +265,7 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgChannelCloseConfirm{} // NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance -// nolint:interfacer + func NewMsgChannelCloseConfirm( portID, channelID string, proofInit []byte, proofHeight clienttypes.Height, signer string, @@ -312,7 +312,7 @@ func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgRecvPacket{} // NewMsgRecvPacket constructs new MsgRecvPacket -// nolint:interfacer + func NewMsgRecvPacket( packet Packet, proofCommitment []byte, proofHeight clienttypes.Height, signer string, @@ -359,7 +359,7 @@ func (msg MsgRecvPacket) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgTimeout{} // NewMsgTimeout constructs new MsgTimeout -// nolint:interfacer + func NewMsgTimeout( packet Packet, nextSequenceRecv uint64, proofUnreceived []byte, proofHeight clienttypes.Height, signer string, @@ -401,7 +401,7 @@ func (msg MsgTimeout) GetSigners() []sdk.AccAddress { } // NewMsgTimeoutOnClose constructs new MsgTimeoutOnClose -// nolint:interfacer + func NewMsgTimeoutOnClose( packet Packet, nextSequenceRecv uint64, proofUnreceived, proofClose []byte, @@ -450,7 +450,7 @@ func (msg MsgTimeoutOnClose) GetSigners() []sdk.AccAddress { var _ sdk.Msg = &MsgAcknowledgement{} // NewMsgAcknowledgement constructs a new MsgAcknowledgement -// nolint:interfacer + func NewMsgAcknowledgement( packet Packet, ack, proofAcked []byte, diff --git a/modules/core/24-host/validate.go b/modules/core/24-host/validate.go index 7102e66b455..2f6a49b3637 100644 --- a/modules/core/24-host/validate.go +++ b/modules/core/24-host/validate.go @@ -36,7 +36,7 @@ var IsValidID = regexp.MustCompile(`^[a-zA-Z0-9\.\_\+\-\#\[\]\<\>]+$`).MatchStri // ValidateFn function type to validate path and identifier bytestrings type ValidateFn func(string) error -func defaultIdentifierValidator(id string, min, max int) error { //nolint:unparam +func defaultIdentifierValidator(id string, min, max int) error { if strings.TrimSpace(id) == "" { return sdkerrors.Wrap(ErrInvalidID, "identifier cannot be blank") } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index dbc4ac07812..4780fe3a488 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -256,7 +256,7 @@ func (k Keeper) ConnectionOpenConfirm(goCtx context.Context, msg *connectiontype // ChannelOpenInit defines a rpc handler method for MsgChannelOpenInit. // ChannelOpenInit will perform 04-channel checks, route to the application -// callback, and write an OpenInit channel into state upon successful exection. +// callback, and write an OpenInit channel into state upon successful execution. func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChannelOpenInit) (*channeltypes.MsgChannelOpenInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -294,7 +294,7 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan // ChannelOpenTry defines a rpc handler method for MsgChannelOpenTry. // ChannelOpenTry will perform 04-channel checks, route to the application -// callback, and write an OpenTry channel into state upon successful exection. +// callback, and write an OpenTry channel into state upon successful execution. func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChannelOpenTry) (*channeltypes.MsgChannelOpenTryResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -332,7 +332,7 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann // ChannelOpenAck defines a rpc handler method for MsgChannelOpenAck. // ChannelOpenAck will perform 04-channel checks, route to the application -// callback, and write an OpenAck channel into state upon successful exection. +// callback, and write an OpenAck channel into state upon successful execution. func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChannelOpenAck) (*channeltypes.MsgChannelOpenAckResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -368,7 +368,7 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann // ChannelOpenConfirm defines a rpc handler method for MsgChannelOpenConfirm. // ChannelOpenConfirm will perform 04-channel checks, route to the application -// callback, and write an OpenConfirm channel into state upon successful exection. +// callback, and write an OpenConfirm channel into state upon successful execution. func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgChannelOpenConfirm) (*channeltypes.MsgChannelOpenConfirmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/testing/simapp/params/proto.go b/testing/simapp/params/proto.go index 04aa524b900..a752d107907 100644 --- a/testing/simapp/params/proto.go +++ b/testing/simapp/params/proto.go @@ -1,3 +1,4 @@ +//go:build !test_amino // +build !test_amino package params From 13bb71e83bbb4092127cb6f544f726c7a685a4f2 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Sat, 1 Jan 2022 11:51:56 +0100 Subject: [PATCH 5/6] panic if middleware already set --- modules/apps/transfer/ibc_module.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/apps/transfer/ibc_module.go b/modules/apps/transfer/ibc_module.go index b9f34044dd2..7a80c7b817d 100644 --- a/modules/apps/transfer/ibc_module.go +++ b/modules/apps/transfer/ibc_module.go @@ -63,6 +63,9 @@ func ValidateTransferChannelParams( // SetMiddleware sets ICS30 middleware func (im *IBCModule) SetMiddleware(app porttypes.IBCModule) { + if im.app != nil { + panic("middleware already set for transfer app") + } im.app = app } From 4d8f264a392949f2873bd548a67df96ff107d2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= Date: Mon, 3 Jan 2022 12:18:44 +0100 Subject: [PATCH 6/6] fix --- modules/apps/transfer/keeper/relay.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 69a643cdea2..1222c8b2d38 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -2,9 +2,10 @@ package keeper import ( "fmt" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "strings" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,6 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v3/modules/core/24-host" coretypes "github.com/cosmos/ibc-go/v3/modules/core/types" ) @@ -51,7 +51,7 @@ import ( // 6. B -> A : sender chain is sink zone. Denom upon receiving: 'denom' func (k Keeper) SendTransfer( ctx sdk.Context, - chanCap *capabilitytypes.Capability, + chanCap *capabilitytypes.Capability, sourcePort, sourceChannel string, token sdk.Coin,