From 0a3b4be7f5cc3d8d1ec975068fa02d6a0d953faf Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Fri, 18 Oct 2024 14:15:48 +0300 Subject: [PATCH] chore: remove packet-server. (#7481) * chore: remove packet-server. * chore: remove commented out test funcs. --- modules/apps/callbacks/testing/simapp/app.go | 8 - modules/core/04-channel/keeper/keeper.go | 28 -- modules/core/04-channel/keeper/keeper_test.go | 77 --- modules/core/keeper/keeper.go | 28 +- modules/core/keeper/msg_server.go | 44 +- modules/core/keeper/msg_server_test.go | 431 ----------------- modules/core/packet-server/keeper/keeper.go | 68 --- modules/core/packet-server/keeper/relay.go | 398 ---------------- modules/core/packet-server/types/channel.go | 34 -- .../core/packet-server/types/channel.pb.go | 444 ------------------ .../core/packet-server/types/channel_test.go | 94 ---- modules/core/packet-server/types/errors.go | 10 - .../packet-server/types/expected_keepers.go | 58 --- modules/core/packet-server/types/keys.go | 11 - .../08-wasm/testing/simapp/app.go | 10 - proto/ibc/core/packetserver/v1/channel.proto | 26 - testing/simapp/app.go | 10 - testing/testing_app.go | 2 - 18 files changed, 16 insertions(+), 1765 deletions(-) delete mode 100644 modules/core/packet-server/keeper/keeper.go delete mode 100644 modules/core/packet-server/keeper/relay.go delete mode 100644 modules/core/packet-server/types/channel.go delete mode 100644 modules/core/packet-server/types/channel.pb.go delete mode 100644 modules/core/packet-server/types/channel_test.go delete mode 100644 modules/core/packet-server/types/errors.go delete mode 100644 modules/core/packet-server/types/expected_keepers.go delete mode 100644 modules/core/packet-server/types/keys.go delete mode 100644 proto/ibc/core/packetserver/v1/channel.proto diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 734089f645d..d73bcbcb648 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -120,7 +120,6 @@ import ( porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" @@ -194,7 +193,6 @@ type SimApp struct { GroupKeeper groupkeeper.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper CircuitKeeper circuitkeeper.Keeper - PacketServer *packetserverkeeper.Keeper // mock contract keeper used for testing MockContractKeeper *ContractKeeper @@ -376,7 +374,6 @@ func NewSimApp( app.IBCKeeper = ibckeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) // NOTE: The mock ContractKeeper is only created for testing. // Real applications should not use the mock ContractKeeper @@ -1005,11 +1002,6 @@ func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper { return app.IBCKeeper } -// GetPacketServer implements the TestingApp interface -func (app *SimApp) GetPacketServer() *packetserverkeeper.Keeper { - return app.PacketServer -} - // GetTxConfig implements the TestingApp interface. func (app *SimApp) GetTxConfig() client.TxConfig { return app.txConfig diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 8e8bff09e3b..1dddc74e126 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -21,10 +21,8 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" - commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" - packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) var _ porttypes.ICS4Wrapper = (*Keeper)(nil) @@ -826,29 +824,3 @@ func (k *Keeper) PruneAcknowledgements(ctx context.Context, portID, channelID st return totalPruned, totalRemaining, nil } - -// GetV2Channel returns a version 2 channel for the given port and channel ID -// by converting the v1 channel into a version 2 channel -func (k *Keeper) GetV2Channel(ctx context.Context, portID, channelID string) (packetserver.Channel, bool) { - channel, ok := k.GetChannel(ctx, portID, channelID) - if !ok { - return packetserver.Channel{}, false - } - // Do not allow channel to be converted into a version 2 counterparty - // if the channel is not OPEN or if it is ORDERED - if channel.State != types.OPEN || channel.Ordering == types.ORDERED { - return packetserver.Channel{}, false - } - connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) - if !ok { - return packetserver.Channel{}, false - } - merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte("")) - - channelv2 := packetserver.Channel{ - CounterpartyChannelId: channel.Counterparty.ChannelId, - ClientId: connection.ClientId, - MerklePathPrefix: merklePathPrefix, - } - return channelv2, true -} diff --git a/modules/core/04-channel/keeper/keeper_test.go b/modules/core/04-channel/keeper/keeper_test.go index ca57cf1c70a..ff343faa1e8 100644 --- a/modules/core/04-channel/keeper/keeper_test.go +++ b/modules/core/04-channel/keeper/keeper_test.go @@ -11,10 +11,8 @@ import ( transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" ) @@ -549,81 +547,6 @@ func (suite *KeeperTestSuite) TestUnsetParams() { }) } -func (suite *KeeperTestSuite) TestGetV2Channel() { - var path *ibctesting.Path - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "success", - func() {}, - true, - }, - { - "failure: channel not found", - func() { - path.EndpointA.ChannelID = "" - }, - false, - }, - { - "failure: channel not OPEN", - func() { - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN }) - }, - false, - }, - { - "failure: channel is ORDERED", - func() { - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.Ordering = types.ORDERED }) - }, - false, - }, - { - "failure: connection not found", - func() { - path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops = []string{ibctesting.InvalidID} }) - }, - false, - }, - } - - for _, tc := range testCases { - tc := tc - - suite.Run(tc.name, func() { - suite.SetupTest() // reset - - // create a previously existing path on chainA to change the identifiers - // between the path between chainA and chainB - path1 := ibctesting.NewPath(suite.chainA, suite.chainC) - path1.Setup() - - path = ibctesting.NewPath(suite.chainA, suite.chainB) - path.Setup() - - tc.malleate() - - channel, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetV2Channel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - - if tc.expPass { - suite.Require().True(found) - - merklePath := commitmentv2types.NewMerklePath([]byte("ibc"), []byte("")) - expChannel := packetservertypes.NewChannel(path.EndpointA.ClientID, path.EndpointB.ChannelID, merklePath) - suite.Require().Equal(channel, expChannel) - } else { - suite.Require().False(found) - suite.Require().Equal(channel, packetservertypes.Channel{}) - } - }) - } -} - func (suite *KeeperTestSuite) TestPruneAcknowledgements() { var ( path *ibctesting.Path diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index a26fbcef482..7f5831d18b9 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -17,18 +17,16 @@ import ( portkeeper "github.com/cosmos/ibc-go/v9/modules/core/05-port/keeper" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" "github.com/cosmos/ibc-go/v9/modules/core/api" - packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" "github.com/cosmos/ibc-go/v9/modules/core/types" ) // Keeper defines each ICS keeper for IBC type Keeper struct { - ClientKeeper *clientkeeper.Keeper - ConnectionKeeper *connectionkeeper.Keeper - ChannelKeeper *channelkeeper.Keeper - ChannelKeeperV2 *channelkeeperv2.Keeper - PacketServerKeeper *packetserver.Keeper - PortKeeper *portkeeper.Keeper + ClientKeeper *clientkeeper.Keeper + ConnectionKeeper *connectionkeeper.Keeper + ChannelKeeper *channelkeeper.Keeper + ChannelKeeperV2 *channelkeeperv2.Keeper + PortKeeper *portkeeper.Keeper cdc codec.BinaryCodec @@ -53,18 +51,16 @@ func NewKeeper( connectionKeeper := connectionkeeper.NewKeeper(cdc, storeService, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper() channelKeeper := channelkeeper.NewKeeper(cdc, storeService, clientKeeper, connectionKeeper) - packetKeeper := packetserver.NewKeeper(cdc, storeService, channelKeeper, clientKeeper) channelKeeperV2 := channelkeeperv2.NewKeeper(cdc, storeService, clientKeeper, channelKeeper, connectionKeeper) return &Keeper{ - cdc: cdc, - ClientKeeper: clientKeeper, - ConnectionKeeper: connectionKeeper, - ChannelKeeper: channelKeeper, - ChannelKeeperV2: channelKeeperV2, - PacketServerKeeper: packetKeeper, - PortKeeper: portKeeper, - authority: authority, + cdc: cdc, + ClientKeeper: clientKeeper, + ConnectionKeeper: connectionKeeper, + ChannelKeeper: channelKeeper, + ChannelKeeperV2: channelKeeperV2, + PortKeeper: portKeeper, + authority: authority, } } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 7b987945e61..2faf86fc01f 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -3,7 +3,6 @@ package keeper import ( "context" "errors" - "fmt" errorsmod "cosmossdk.io/errors" @@ -391,7 +390,6 @@ func (k *Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Ms // RecvPacket defines a rpc handler method for MsgRecvPacket. func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error) { - var packetHandler PacketHandler ctx := sdk.UnwrapSDKContext(goCtx) relayer, err := sdk.AccAddressFromBech32(msg.Signer) @@ -400,12 +398,6 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion) - if err != nil { - ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.DestinationPort, "channel-id", msg.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router cbs, ok := k.PortKeeper.Route(msg.Packet.DestinationPort) if !ok { @@ -418,7 +410,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack // If the packet was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := packetHandler.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) + channelVersion, err := k.ChannelKeeper.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) switch err { case nil: @@ -449,7 +441,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack // NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the // acknowledgement is nil. if ack != nil { - if err := packetHandler.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil { + if err := k.ChannelKeeper.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil { return nil, err } } @@ -463,7 +455,6 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack // Timeout defines a rpc handler method for MsgTimeout. func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*channeltypes.MsgTimeoutResponse, error) { - var packetHandler PacketHandler ctx := sdk.UnwrapSDKContext(goCtx) relayer, err := sdk.AccAddressFromBech32(msg.Signer) @@ -472,12 +463,6 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion) - if err != nil { - ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { @@ -490,7 +475,7 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (* // If the timeout was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := packetHandler.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv) + channelVersion, err := k.ChannelKeeper.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv) switch err { case nil: @@ -572,7 +557,6 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime // Acknowledgement defines a rpc handler method for MsgAcknowledgement. func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAcknowledgement) (*channeltypes.MsgAcknowledgementResponse, error) { - var packetHandler PacketHandler ctx := sdk.UnwrapSDKContext(goCtx) relayer, err := sdk.AccAddressFromBech32(msg.Signer) @@ -581,12 +565,6 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck return nil, errorsmod.Wrap(err, "Invalid address for msg Signer") } - packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion) - if err != nil { - ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id")) - return nil, errorsmod.Wrap(err, "could not retrieve module from port-id") - } - // Retrieve callbacks from router cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort) if !ok { @@ -599,7 +577,7 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck // If the acknowledgement was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - channelVersion, err := packetHandler.AcknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) + channelVersion, err := k.ChannelKeeper.AcknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight) switch err { case nil: @@ -998,17 +976,3 @@ func (k *Keeper) UpdateChannelParams(goCtx context.Context, msg *channeltypes.Ms return &channeltypes.MsgUpdateParamsResponse{}, nil } - -// getPacketHandlerAndModule returns the appropriate packet handler -// given the protocol version. An error is returned if the protocol -// version is not supported. -func (k *Keeper) getPacketHandlerAndModule(protocolVersion channeltypes.IBCVersion) (PacketHandler, error) { - switch protocolVersion { - case channeltypes.IBC_VERSION_UNSPECIFIED, channeltypes.IBC_VERSION_1: - return k.ChannelKeeper, nil - case channeltypes.IBC_VERSION_2: - return k.PacketServerKeeper, nil - default: - return nil, fmt.Errorf("unsupported protocol %s", protocolVersion) - } -} diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 693e93d8c50..72b5f5a71b0 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -216,173 +216,6 @@ func (suite *KeeperTestSuite) TestHandleRecvPacket() { } } -// tests the IBC handler receiving a packet using V2 protocol -// func (suite *KeeperTestSuite) TestRecvPacketV2() { -// var ( -// packet channeltypes.Packet -// path *ibctesting.Path -// ) - -// testCases := []struct { -// name string -// malleate func() -// expErr error -// expRevert bool -// async bool // indicate no ack written -// replay bool // indicate replay (no-op) -// }{ -// { -// "success", -// func() { -// path.SetupV2() - -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibctesting.MockPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// }, -// nil, -// false, -// false, -// false, -// }, -// { -// "success: OnRecvPacket callback returns error acknowledgement", -// func() { -// path.SetupV2() - -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibctesting.MockFailPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockFailPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// }, -// nil, -// true, -// false, -// false, -// }, -// { -// "success: async acknowledgement", -// func() { -// path.SetupV2() - -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibcmock.MockAsyncPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibcmock.MockAsyncPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// }, -// nil, -// false, -// true, -// false, -// }, -// { -// "success no-op: packet already received (replay)", -// func() { -// // mock will panic if application callback is called twice on the same packet -// path.SetupV2() - -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibctesting.MockPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// err = path.EndpointB.RecvPacket(packet) -// suite.Require().NoError(err) -// }, -// nil, -// false, -// false, -// true, -// }, -// { -// "channel does not exist", -// func() { -// // any non-nil value of packet is valid -// suite.Require().NotNil(packet) -// }, -// packetservertypes.ErrChannelNotFound, -// false, -// false, -// false, -// }, -// { -// "packet not sent", -// func() { -// path.SetupV2() -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// }, -// fmt.Errorf("receive packet verification failed"), -// false, -// false, -// false, -// }, -// } - -// for _, tc := range testCases { -// tc := tc - -// suite.Run(tc.name, func() { -// suite.SetupTest() // reset -// path = ibctesting.NewPath(suite.chainA, suite.chainB) - -// tc.malleate() - -// var ( -// proof []byte -// proofHeight clienttypes.Height -// ) -// // get proof of packet commitment from chainA -// packetKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) -// if path.EndpointA.ClientID != "" { -// proof, proofHeight = path.EndpointA.QueryProof(packetKey) -// } - -// ctx := suite.chainB.GetContext() -// msg := channeltypes.NewMsgRecvPacket(packet, proof, proofHeight, suite.chainB.SenderAccount.GetAddress().String()) -// res, err := suite.chainB.App.GetIBCKeeper().RecvPacket(ctx, msg) - -// events := ctx.EventManager().Events() - -// if tc.expErr == nil { -// suite.Require().NoError(err) - -// // replay should not fail since it will be treated as a no-op -// _, err := suite.chainB.App.GetIBCKeeper().RecvPacket(suite.chainB.GetContext(), msg) -// suite.Require().NoError(err) - -// if tc.expRevert { -// // context events should contain error events -// suite.Require().Contains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) -// suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent()) -// } else { -// if tc.replay { -// // context should not contain application events -// suite.Require().NotContains(events, ibcmock.NewMockRecvPacketEvent()) -// suite.Require().NotContains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) -// } else { -// // context events should contain application events -// suite.Require().Contains(events, ibcmock.NewMockRecvPacketEvent()) -// } -// } - -// // verify if ack was written -// ack, found := suite.chainB.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) - -// if tc.async { -// suite.Require().Nil(ack) -// suite.Require().False(found) -// } else { -// suite.Require().NotNil(ack) -// suite.Require().True(found) -// } -// } else { -// suite.Require().ErrorContains(err, tc.expErr.Error()) -// suite.Require().Nil(res) -// } -// }) -// } -// } - func (suite *KeeperTestSuite) TestRecoverClient() { var msg *clienttypes.MsgRecoverClient @@ -616,133 +449,6 @@ func (suite *KeeperTestSuite) TestHandleAcknowledgePacket() { } } -// tests the IBC handler acknowledgement of a packet using protocol version V2 -// func (suite *KeeperTestSuite) TestAcknowledgePacketV2() { -// var ( -// packet channeltypes.Packet -// signer string -// path *ibctesting.Path -// ) - -// testCases := []struct { -// name string -// malleate func() -// expError error -// replay bool // indicate replay (no-op) -// }{ -// { -// "success", -// func() {}, -// nil, -// false, -// }, -// { -// "invalid signer", -// func() { -// signer = "invalid-signer" -// }, -// errors.New("Invalid address for msg Signer"), -// false, -// }, -// { -// "port route does not exist", -// func() { -// packet.SourcePort = "invalid-port" -// }, -// porttypes.ErrInvalidRoute, -// false, -// }, -// { -// "acknowledge packet fails in packet handler", -// func() { -// packet.SourceChannel = "invalid-client" -// }, -// packetservertypes.ErrChannelNotFound, -// false, -// }, -// { -// "successful no-op: - packet already acknowledged (replay)", -// func() { -// err := path.EndpointA.AcknowledgePacket(packet, ibctesting.MockAcknowledgement) -// suite.Require().NoError(err) -// }, -// nil, -// true, -// }, -// { -// "application callback returns error", -// func() { -// suite.chainA.GetSimApp().IBCMockModule.IBCApp.OnAcknowledgementPacket = func(ctx context.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress) error { -// return fmt.Errorf("mock app callback failed") -// } -// }, -// fmt.Errorf("mock app callback failed"), -// false, -// }, -// } - -// for _, tc := range testCases { -// tc := tc - -// suite.Run(tc.name, func() { -// suite.SetupTest() // reset -// signer = suite.chainA.SenderAccount.GetAddress().String() - -// path = ibctesting.NewPath(suite.chainA, suite.chainB) -// path.SetupV2() - -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibctesting.MockPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// err = path.EndpointB.RecvPacket(packet) -// suite.Require().NoError(err) - -// tc.malleate() - -// var ( -// proof []byte -// proofHeight clienttypes.Height -// ) -// packetKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) -// proof, proofHeight = path.EndpointB.QueryProof(packetKey) - -// msg := channeltypes.NewMsgAcknowledgement(packet, ibcmock.MockAcknowledgement.Acknowledgement(), proof, proofHeight, signer) - -// ctx := suite.chainA.GetContext() -// res, err := suite.chainA.App.GetIBCKeeper().Acknowledgement(ctx, msg) - -// events := ctx.EventManager().Events() - -// if tc.expError == nil { -// suite.Require().NoError(err) - -// // verify packet commitment was deleted on source chain -// has := suite.chainA.App.GetIBCKeeper().ChannelKeeper.HasPacketCommitment(suite.chainA.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) -// suite.Require().False(has) - -// if tc.replay { -// // context should not contain application events -// suite.Require().NotContains(events, ibcmock.NewMockAckPacketEvent()) -// suite.Require().Equal(channeltypes.NOOP, res.Result) -// } else { -// // context events should contain application events -// suite.Require().Contains(events, ibcmock.NewMockAckPacketEvent()) -// suite.Require().Equal(channeltypes.SUCCESS, res.Result) - -// // replay should not error as it is treated as a no-op -// res, err = suite.chainA.App.GetIBCKeeper().Acknowledgement(suite.chainA.GetContext(), msg) -// suite.Require().NoError(err) -// suite.Require().Equal(channeltypes.NOOP, res.Result) -// } -// } else { -// suite.Require().ErrorContains(err, tc.expError.Error()) -// suite.Require().Nil(res) -// } -// }) -// } -// } - // tests the IBC handler timing out a packet on ordered and unordered channels. // It verifies that the deletion of a packet commitment occurs. It tests // high level properties like ordering and basic sanity checks. More @@ -901,143 +607,6 @@ func (suite *KeeperTestSuite) TestHandleTimeoutPacket() { } } -// tests the IBC handler timing out a packet for the V2 protocol. -// It verifies that the deletion of a packet commitment occurs. More -// rigorous testing of 'TimeoutPacket' and 'TimeoutExecuted' can be found in -// the packet-server/keeper/keeper_test.go. -// func (suite *KeeperTestSuite) TestTimeoutPacketV2() { -// var ( -// packet channeltypes.Packet -// packetKey []byte -// path *ibctesting.Path -// ) - -// testCases := []struct { -// name string -// malleate func() -// expErr error -// noop bool // indicate no-op -// }{ -// { -// "success", -// func() { -// path.SetupV2() - -// timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext()) -// timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().UnixNano()) - -// // create packet commitment -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, timeoutTimestamp, ibcmock.Version, ibctesting.MockPacketData) -// suite.Require().NoError(err) - -// // need to update chainA client to prove missing ack -// err = path.EndpointA.UpdateClient() -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, timeoutTimestamp, ibcmock.Version) -// packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) -// }, -// nil, -// false, -// }, -// { -// "success: timeout out of order packet", -// func() { -// // setup uses an UNORDERED channel -// path.SetupV2() - -// // attempts to timeout the last packet sent without timing out the first packet -// // packet sequences begin at 1 -// for i := uint64(1); i < maxSequence; i++ { -// timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext()) - -// // create packet commitment -// sequence, err := path.EndpointA.SendPacketV2(timeoutHeight, 0, ibcmock.Version, ibctesting.MockPacketData) -// suite.Require().NoError(err) - -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, 0, ibcmock.Version) -// } - -// err := path.EndpointA.UpdateClient() -// suite.Require().NoError(err) - -// packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) -// }, -// nil, -// false, -// }, -// { -// "success no-op: packet not sent", func() { -// path.SetupV2() -// packet = channeltypes.NewPacketWithVersion(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(0, 1), 0, ibcmock.Version) -// packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) -// }, -// nil, -// true, -// }, -// { -// "channel does not exist", -// func() { -// // any non-nil value of packet is valid -// suite.Require().NotNil(packet) - -// packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) -// }, -// packetservertypes.ErrChannelNotFound, -// false, -// }, -// } - -// for _, tc := range testCases { -// tc := tc - -// suite.Run(tc.name, func() { -// suite.SetupTest() // reset -// path = ibctesting.NewPath(suite.chainA, suite.chainB) - -// tc.malleate() - -// var ( -// proof []byte -// proofHeight clienttypes.Height -// ) -// if path.EndpointB.ClientID != "" { -// proof, proofHeight = path.EndpointB.QueryProof(packetKey) -// } - -// ctx := suite.chainA.GetContext() -// msg := channeltypes.NewMsgTimeout(packet, 1, proof, proofHeight, suite.chainA.SenderAccount.GetAddress().String()) -// res, err := suite.chainA.App.GetIBCKeeper().Timeout(ctx, msg) - -// events := ctx.EventManager().Events() - -// if tc.expErr == nil { -// suite.Require().NoError(err) - -// // replay should not return an error as it is treated as a no-op -// _, err := suite.chainA.App.GetIBCKeeper().Timeout(suite.chainA.GetContext(), msg) -// suite.Require().NoError(err) - -// // verify packet commitment was deleted on source chain -// has := suite.chainA.App.GetIBCKeeper().ChannelKeeper.HasPacketCommitment(suite.chainA.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) -// suite.Require().False(has) - -// if tc.noop { -// // context should not contain application events -// suite.Require().NotContains(events, ibcmock.NewMockTimeoutPacketEvent()) -// } else { -// // context should contain application events -// suite.Require().Contains(events, ibcmock.NewMockTimeoutPacketEvent()) -// } - -// } else { -// suite.Require().ErrorIs(err, tc.expErr) -// suite.Require().Nil(res) -// } -// }) -// } -// } - // tests the IBC handler timing out a packet via channel closure on ordered // and unordered channels. It verifies that the deletion of a packet // commitment occurs. It tests high level properties like ordering and basic diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go deleted file mode 100644 index eeeeec5aa3e..00000000000 --- a/modules/core/packet-server/keeper/keeper.go +++ /dev/null @@ -1,68 +0,0 @@ -package keeper - -import ( - "context" - "fmt" - - corestore "cosmossdk.io/core/store" - "cosmossdk.io/log" - "cosmossdk.io/store/prefix" - storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" - - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" -) - -// Keeper defines the packet keeper. It wraps the client and channel keepers. -// It does not manage its own store. -type Keeper struct { - cdc codec.BinaryCodec - storeService corestore.KVStoreService - ChannelKeeper types.ChannelKeeper - ClientKeeper types.ClientKeeper -} - -// NewKeeper creates a new packet keeper -func NewKeeper(cdc codec.BinaryCodec, storeService corestore.KVStoreService, channelKeeper types.ChannelKeeper, clientKeeper types.ClientKeeper) *Keeper { - return &Keeper{ - cdc: cdc, - storeService: storeService, - ChannelKeeper: channelKeeper, - ClientKeeper: clientKeeper, - } -} - -// Logger returns a module-specific logger. -func (Keeper) Logger(ctx context.Context) log.Logger { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - return sdkCtx.Logger().With("module", "x/"+exported.ModuleName+"/"+types.SubModuleName) -} - -func (k Keeper) ChannelStore(ctx context.Context, channelID string) storetypes.KVStore { - channelPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyChannelStorePrefix, channelID)) - return prefix.NewStore(runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)), channelPrefix) -} - -// SetChannel sets the Channel for a given client identifier. -func (k *Keeper) SetChannel(ctx context.Context, clientID string, channel types.Channel) { - bz := k.cdc.MustMarshal(&channel) - k.ChannelStore(ctx, clientID).Set([]byte(types.ChannelKey), bz) -} - -// GetChannel gets the Channel for a given client identifier. -func (k *Keeper) GetChannel(ctx context.Context, clientID string) (types.Channel, bool) { - store := k.ChannelStore(ctx, clientID) - bz := store.Get([]byte(types.ChannelKey)) - if len(bz) == 0 { - return types.Channel{}, false - } - - var channel types.Channel - k.cdc.MustUnmarshal(bz, &channel) - return channel, true -} diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go deleted file mode 100644 index 334ea601a03..00000000000 --- a/modules/core/packet-server/keeper/relay.go +++ /dev/null @@ -1,398 +0,0 @@ -package keeper - -import ( - "bytes" - "context" - "strconv" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" - channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" -) - -// SendPacket implements the packet sending logic required by a packet handler. -// It will generate a packet and store the commitment hash if all arguments provided are valid. -// The destination channel will be filled in using the channel information. -// The next sequence send will be initialized if this is the first packet sent for the given client. -func (k Keeper) SendPacket( - ctx context.Context, - sourceChannel string, - sourcePort string, - destPort string, - timeoutHeight clienttypes.Height, - timeoutTimestamp uint64, - version string, - data []byte, -) (uint64, error) { - // Lookup channel associated with our source channel to retrieve the destination channel - channel, ok := k.GetChannel(ctx, sourceChannel) - if !ok { - // If the channel is not found, attempt to retrieve a v1 channel from the channel keeper - // if it exists, then we will convert it to a v2 channel and store it in the packet server keeper - // for future use. - if channel, ok = k.ChannelKeeper.GetV2Channel(ctx, sourcePort, sourceChannel); ok { - // we can key on just the source channel here since channel ids are globally unique - k.SetChannel(ctx, sourceChannel, channel) - } else { - // if neither a channel v2 nor channel v1 is found then simply return an error - return 0, errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel) - } - } - destChannel := channel.CounterpartyChannelId - clientID := channel.ClientId - - // retrieve the sequence send for this channel - // if no packets have been sent yet, initialize the sequence to 1. - sequence, found := k.ChannelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) - if !found { - sequence = 1 - } - - // construct packet from given fields and channel state - packet := channeltypes.NewPacketWithVersion(data, sequence, sourcePort, sourceChannel, - destPort, destChannel, timeoutHeight, timeoutTimestamp, version) - - if err := packet.ValidateBasic(); err != nil { - return 0, errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "constructed packet failed basic validation: %v", err) - } - - // check that the client of counterparty chain is still active - if status := k.ClientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { - return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) - } - - // retrieve latest height and timestamp of the client of counterparty chain - latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, clientID) - if latestHeight.IsZero() { - return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", clientID) - } - - latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientID, latestHeight) - if err != nil { - return 0, err - } - - // check if packet is timed out on the receiving chain - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if timeout.Elapsed(latestHeight, latestTimestamp) { - return 0, errorsmod.Wrap(timeout.ErrTimeoutElapsed(latestHeight, latestTimestamp), "invalid packet timeout") - } - - commitment := channeltypes.CommitPacket(packet) - - // bump the sequence and set the packet commitment so it is provable by the counterparty - k.ChannelKeeper.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) - k.ChannelKeeper.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) - - k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - channelkeeper.EmitSendPacketEvent(ctx, packet, nil, timeoutHeight) - - return sequence, nil -} - -// RecvPacket implements the packet receiving logic required by a packet handler. -// The packet is checked for correctness including asserting that the packet was -// sent and received on clients which are counterparties for one another. -// If the packet has already been received a no-op error is returned. -// The packet handler will verify that the packet has not timed out and that the -// counterparty stored a packet commitment. If successful, a packet receipt is stored -// to indicate to the counterparty successful delivery. -func (k Keeper) RecvPacket( - ctx context.Context, - packet channeltypes.Packet, - proof []byte, - proofHeight exported.Height, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - - // packetv2 := convert(packet) - - // Lookup channel associated with our channel and ensure - // that the packet was indeed sent by our channel. - channel, ok := k.GetChannel(ctx, packet.DestinationChannel) - if !ok { - // If the channel is not found, attempt to retrieve a v1 channel from the channel keeper - // if it exists, then we will convert it to a v2 channel and store it in the packet server keeper - // for future use. - if channel, ok = k.ChannelKeeper.GetV2Channel(ctx, packet.DestinationPort, packet.DestinationChannel); ok { - // we can key on just the destination channel here since channel ids are globally unique - k.SetChannel(ctx, packet.DestinationChannel, channel) - } else { - // if neither a channel v1 nor channel v1 is found then simply return an error - return "", errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) - } - } - - if channel.CounterpartyChannelId != packet.SourceChannel { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, packet.SourceChannel) - } - clientID := channel.ClientId - - // check if packet timed out by comparing it with the latest height of the chain - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(sdkCtx.BlockTime().UnixNano()) - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if timeout.Elapsed(selfHeight, selfTimestamp) { - return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") - } - - // REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received - // on unordered channels. Packet receipts must not be pruned, unless it has been marked stale - // by the increase of the recvStartSequence. - _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - if found { - channelkeeper.EmitRecvPacketEvent(ctx, packet, nil) - // This error indicates that the packet has already been relayed. Core IBC will - // treat this error as a no-op in order to prevent an entire relay transaction - // from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg - } - - path := host.PacketCommitmentKey(packet.SourcePort, packet.SourceChannel, packet.Sequence) - merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) - - commitment := channeltypes.CommitPacket(packet) - - if err := k.ClientKeeper.VerifyMembership( - ctx, - clientID, - proofHeight, - 0, 0, - proof, - merklePath, - commitment, - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) - } - - // Set Packet Receipt to prevent timeout from occurring on counterparty - k.ChannelKeeper.SetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - - k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - channelkeeper.EmitRecvPacketEvent(ctx, packet, nil) - - return packet.AppVersion, nil -} - -// WriteAcknowledgement implements the async acknowledgement writing logic required by a packet handler. -// The packet is checked for correctness including asserting that the packet was -// sent and received on clients which are counterparties for one another. -// If no acknowledgement exists for the given packet, then a commitment of the acknowledgement -// is written into state. -func (k Keeper) WriteAcknowledgement( - ctx context.Context, - packetI exported.PacketI, - ack exported.Acknowledgement, -) error { - packet, ok := packetI.(channeltypes.Packet) - if !ok { - return errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "expected type %T, got %T", &channeltypes.Packet{}, packetI) - } - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return channeltypes.ErrInvalidPacket - } - - // Lookup channel associated with our channel and ensure - // that the packet was indeed sent by our counterparty. - channel, ok := k.GetChannel(ctx, packet.DestinationChannel) - if !ok { - return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) - } - if channel.CounterpartyChannelId != packet.SourceChannel { - return errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, packet.SourceChannel) - } - - // NOTE: IBC app modules might have written the acknowledgement synchronously on - // the OnRecvPacket callback so we need to check if the acknowledgement is already - // set on the store and return an error if so. - if k.ChannelKeeper.HasPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) { - return channeltypes.ErrAcknowledgementExists - } - - if _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence); !found { - return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet") - } - - if ack == nil { - return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") - } - - bz := ack.Acknowledgement() - if len(bz) == 0 { - return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") - } - - k.ChannelKeeper.SetPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence, channeltypes.CommitAcknowledgement(bz)) - - k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - channelkeeper.EmitWriteAcknowledgementEvent(ctx, packet, nil, bz) - - return nil -} - -// AcknowledgePacket implements the acknowledgement processing logic required by a packet handler. -// The packet is checked for correctness including asserting that the packet was -// sent and received on clients which are counterparties for one another. -// If no packet commitment exists, a no-op error is returned, otherwise -// the acknowledgement provided is verified to have been stored by the counterparty. -// If successful, the packet commitment is deleted and the packet has completed its lifecycle. -func (k Keeper) AcknowledgePacket( - ctx context.Context, - packet channeltypes.Packet, - acknowledgement []byte, - proofAcked []byte, - proofHeight exported.Height, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - - // Lookup counterparty associated with our channel and ensure - // that the packet was indeed sent by our counterparty. - channel, ok := k.GetChannel(ctx, packet.SourceChannel) - if !ok { - return "", errorsmod.Wrap(types.ErrChannelNotFound, packet.SourceChannel) - } - - if channel.CounterpartyChannelId != packet.DestinationChannel { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) - } - clientID := channel.ClientId - - commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - if len(commitment) == 0 { - channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, nil) - - // This error indicates that the acknowledgement has already been relayed - // or there is a misconfigured relayer attempting to prove an acknowledgement - // for a packet never sent. Core IBC will treat this error as a no-op in order to - // prevent an entire relay transaction from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg - } - - packetCommitment := channeltypes.CommitPacket(packet) - - // verify we sent the packet and haven't cleared it out yet - if !bytes.Equal(commitment, packetCommitment) { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) - } - - path := host.PacketAcknowledgementKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) - - if err := k.ClientKeeper.VerifyMembership( - ctx, - clientID, - proofHeight, - 0, 0, - proofAcked, - merklePath, - channeltypes.CommitAcknowledgement(acknowledgement), - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) - } - - k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - - k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "src_port", packet.GetSourcePort(), "src_channel", packet.GetSourceChannel(), "dst_port", packet.GetDestPort(), "dst_channel", packet.GetDestChannel()) - - channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, nil) - - return packet.AppVersion, nil -} - -// TimeoutPacket implements the timeout logic required by a packet handler. -// The packet is checked for correctness including asserting that the packet was -// sent and received on clients which are counterparties for one another. -// If no packet commitment exists, a no-op error is returned, otherwise -// an absence proof of the packet receipt is performed to ensure that the packet -// was never delivered to the counterparty. If successful, the packet commitment -// is deleted and the packet has completed its lifecycle. -func (k Keeper) TimeoutPacket( - ctx context.Context, - packet channeltypes.Packet, - proof []byte, - proofHeight exported.Height, - _ uint64, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - // Lookup channel associated with our channel and ensure - // that the packet was indeed sent by our counterparty. - channel, ok := k.GetChannel(ctx, packet.SourceChannel) - if !ok { - return "", errorsmod.Wrap(types.ErrChannelNotFound, packet.SourceChannel) - } - - if channel.CounterpartyChannelId != packet.DestinationChannel { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) - } - clientID := channel.ClientId - - // check that timeout height or timeout timestamp has passed on the other end - proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientID, proofHeight) - if err != nil { - return "", err - } - - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if !timeout.Elapsed(proofHeight.(clienttypes.Height), proofTimestamp) { - return "", errorsmod.Wrap(timeout.ErrTimeoutNotReached(proofHeight.(clienttypes.Height), proofTimestamp), "packet timeout not reached") - } - - // check that the commitment has not been cleared and that it matches the packet sent by relayer - commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - - if len(commitment) == 0 { - channelkeeper.EmitTimeoutPacketEvent(ctx, packet, nil) - // This error indicates that the timeout has already been relayed - // or there is a misconfigured relayer attempting to prove a timeout - // for a packet never sent. Core IBC will treat this error as a no-op in order to - // prevent an entire relay transaction from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg - } - - packetCommitment := channeltypes.CommitPacket(packet) - // verify we sent the packet and haven't cleared it out yet - if !bytes.Equal(commitment, packetCommitment) { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) - } - - // verify packet receipt absence - path := host.PacketReceiptKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) - - if err := k.ClientKeeper.VerifyNonMembership( - ctx, - clientID, - proofHeight, - 0, 0, - proof, - merklePath, - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) - } - - // delete packet commitment to prevent replay - k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - - k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - channelkeeper.EmitTimeoutPacketEvent(ctx, packet, nil) - - return packet.AppVersion, nil -} diff --git a/modules/core/packet-server/types/channel.go b/modules/core/packet-server/types/channel.go deleted file mode 100644 index 3a45be384fb..00000000000 --- a/modules/core/packet-server/types/channel.go +++ /dev/null @@ -1,34 +0,0 @@ -package types - -import ( - errorsmod "cosmossdk.io/errors" - - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" -) - -// NewChannel creates a new Channel instance -func NewChannel(clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath) Channel { - return Channel{ - ClientId: clientID, - CounterpartyChannelId: counterpartyChannelID, - MerklePathPrefix: merklePathPrefix, - } -} - -// Validate validates the Channel -func (c Channel) Validate() error { - if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return err - } - - if err := host.ChannelIdentifierValidator(c.CounterpartyChannelId); err != nil { - return err - } - - if err := c.MerklePathPrefix.ValidateAsPrefix(); err != nil { - return errorsmod.Wrap(ErrInvalidChannel, err.Error()) - } - - return nil -} diff --git a/modules/core/packet-server/types/channel.pb.go b/modules/core/packet-server/types/channel.pb.go deleted file mode 100644 index 91dfcd17df5..00000000000 --- a/modules/core/packet-server/types/channel.pb.go +++ /dev/null @@ -1,444 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/core/packetserver/v1/channel.proto - -package types - -import ( - fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Channel defines the channel end on a chain that is implementing the version 2 IBC protocol -// Each side will maintain its own Channel to create an IBC channel -// The channel will be referenced by a channelID which will be used to send packets -// to the counterparty -// The channel will contain the client identifier that will provide proof verification for the channel -// and the counterparty channel identifier that the other channel end will be using -// to send packets to our channel end. -type Channel struct { - // the client identifier of the light client representing the counterparty chain - ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` - // the counterparty identifier that must be used by the packet - CounterpartyChannelId string `protobuf:"bytes,2,opt,name=counterparty_channel_id,json=counterpartyChannelId,proto3" json:"counterparty_channel_id,omitempty"` - // the key path used to store packet flow messages that the counterparty - // will use to send to us. In backwards compatible cases, we will append the channelID and sequence in order to create - // the final path. - MerklePathPrefix v2.MerklePath `protobuf:"bytes,3,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` -} - -func (m *Channel) Reset() { *m = Channel{} } -func (m *Channel) String() string { return proto.CompactTextString(m) } -func (*Channel) ProtoMessage() {} -func (*Channel) Descriptor() ([]byte, []int) { - return fileDescriptor_740f6a3702ba2291, []int{0} -} -func (m *Channel) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Channel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Channel.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Channel) XXX_Merge(src proto.Message) { - xxx_messageInfo_Channel.Merge(m, src) -} -func (m *Channel) XXX_Size() int { - return m.Size() -} -func (m *Channel) XXX_DiscardUnknown() { - xxx_messageInfo_Channel.DiscardUnknown(m) -} - -var xxx_messageInfo_Channel proto.InternalMessageInfo - -func (m *Channel) GetClientId() string { - if m != nil { - return m.ClientId - } - return "" -} - -func (m *Channel) GetCounterpartyChannelId() string { - if m != nil { - return m.CounterpartyChannelId - } - return "" -} - -func (m *Channel) GetMerklePathPrefix() v2.MerklePath { - if m != nil { - return m.MerklePathPrefix - } - return v2.MerklePath{} -} - -func init() { - proto.RegisterType((*Channel)(nil), "ibc.core.packetserver.v1.Channel") -} - -func init() { - proto.RegisterFile("ibc/core/packetserver/v1/channel.proto", fileDescriptor_740f6a3702ba2291) -} - -var fileDescriptor_740f6a3702ba2291 = []byte{ - // 309 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xcf, 0x4a, 0xc3, 0x30, - 0x1c, 0xc7, 0x1b, 0x15, 0x75, 0xf5, 0x22, 0x45, 0x71, 0x4c, 0x88, 0x63, 0x07, 0xdd, 0x65, 0x09, - 0x9b, 0x20, 0x08, 0x9e, 0xe6, 0x69, 0x07, 0x61, 0xec, 0xb0, 0x83, 0x97, 0xd2, 0xa6, 0x3f, 0xdb, - 0xb0, 0xa6, 0x09, 0x69, 0x16, 0xdc, 0x5b, 0xf8, 0x34, 0x3e, 0xc3, 0x8e, 0x3b, 0x7a, 0x12, 0xd9, - 0x5e, 0x44, 0xfa, 0x87, 0xd2, 0x5b, 0xf2, 0xcb, 0x27, 0x9f, 0x7c, 0xf3, 0x75, 0xef, 0x79, 0xc8, - 0x28, 0x93, 0x1a, 0xa8, 0x0a, 0xd8, 0x0a, 0x4c, 0x0e, 0xda, 0x82, 0xa6, 0x76, 0x4c, 0x59, 0x12, - 0x64, 0x19, 0xa4, 0x44, 0x69, 0x69, 0xa4, 0xd7, 0xe5, 0x21, 0x23, 0x05, 0x47, 0xda, 0x1c, 0xb1, - 0xe3, 0xde, 0x55, 0x2c, 0x63, 0x59, 0x42, 0xb4, 0x58, 0x55, 0x7c, 0xef, 0xa1, 0xf1, 0x32, 0x29, - 0x04, 0x37, 0x02, 0x32, 0x43, 0xed, 0xa4, 0xb5, 0xab, 0xc0, 0xc1, 0x37, 0x72, 0xcf, 0x5e, 0xab, - 0xa7, 0xbc, 0x5b, 0xb7, 0xc3, 0x52, 0x0e, 0x99, 0xf1, 0x79, 0xd4, 0x45, 0x7d, 0x34, 0xec, 0x2c, - 0xce, 0xab, 0xc1, 0x2c, 0xf2, 0x9e, 0xdc, 0x1b, 0x26, 0xd7, 0x99, 0x01, 0xad, 0x02, 0x6d, 0x36, - 0x7e, 0x9d, 0xaf, 0x40, 0x8f, 0x4a, 0xf4, 0xba, 0x7d, 0x5c, 0x2b, 0x67, 0x91, 0xb7, 0x74, 0x3d, - 0x01, 0x7a, 0x95, 0x82, 0xaf, 0x02, 0x93, 0xf8, 0x4a, 0xc3, 0x07, 0xff, 0xec, 0x1e, 0xf7, 0xd1, - 0xf0, 0x62, 0x32, 0x20, 0xcd, 0xb7, 0x5a, 0xc1, 0xec, 0x84, 0xbc, 0x95, 0x37, 0xe6, 0x81, 0x49, - 0xa6, 0x27, 0xdb, 0xdf, 0x3b, 0x67, 0x71, 0x29, 0x9a, 0xc9, 0xbc, 0x34, 0x4c, 0x97, 0xdb, 0x3d, - 0x46, 0xbb, 0x3d, 0x46, 0x7f, 0x7b, 0x8c, 0xbe, 0x0e, 0xd8, 0xd9, 0x1d, 0xb0, 0xf3, 0x73, 0xc0, - 0xce, 0xfb, 0x4b, 0xcc, 0x4d, 0xb2, 0x0e, 0x0b, 0x25, 0x65, 0x32, 0x17, 0x32, 0xa7, 0x3c, 0x64, - 0xa3, 0x58, 0x52, 0xfb, 0x4c, 0x85, 0x8c, 0xd6, 0x29, 0xe4, 0xed, 0xce, 0x47, 0x75, 0xe9, 0x66, - 0xa3, 0x20, 0x0f, 0x4f, 0xcb, 0x5e, 0x1e, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x94, 0x68, 0x6c, - 0x3f, 0x9a, 0x01, 0x00, 0x00, -} - -func (m *Channel) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Channel) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Channel) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintChannel(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - if len(m.CounterpartyChannelId) > 0 { - i -= len(m.CounterpartyChannelId) - copy(dAtA[i:], m.CounterpartyChannelId) - i = encodeVarintChannel(dAtA, i, uint64(len(m.CounterpartyChannelId))) - i-- - dAtA[i] = 0x12 - } - if len(m.ClientId) > 0 { - i -= len(m.ClientId) - copy(dAtA[i:], m.ClientId) - i = encodeVarintChannel(dAtA, i, uint64(len(m.ClientId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintChannel(dAtA []byte, offset int, v uint64) int { - offset -= sovChannel(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Channel) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ClientId) - if l > 0 { - n += 1 + l + sovChannel(uint64(l)) - } - l = len(m.CounterpartyChannelId) - if l > 0 { - n += 1 + l + sovChannel(uint64(l)) - } - l = m.MerklePathPrefix.Size() - n += 1 + l + sovChannel(uint64(l)) - return n -} - -func sovChannel(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozChannel(x uint64) (n int) { - return sovChannel(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Channel) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChannel - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Channel: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Channel: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChannel - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthChannel - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthChannel - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyChannelId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChannel - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthChannel - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthChannel - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CounterpartyChannelId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MerklePathPrefix", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowChannel - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthChannel - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthChannel - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipChannel(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthChannel - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipChannel(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChannel - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChannel - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowChannel - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthChannel - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupChannel - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthChannel - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthChannel = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowChannel = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupChannel = fmt.Errorf("proto: unexpected end of group") -) diff --git a/modules/core/packet-server/types/channel_test.go b/modules/core/packet-server/types/channel_test.go deleted file mode 100644 index f5d6948a23b..00000000000 --- a/modules/core/packet-server/types/channel_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" - ibctesting "github.com/cosmos/ibc-go/v9/testing" -) - -func TestValidateChannel(t *testing.T) { - testCases := []struct { - name string - clientID string - channelID string - merklePathPrefix commitmenttypes.MerklePath - expError error - }{ - { - "success", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte("ibc")), - nil, - }, - { - "success with multiple element prefix", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte("ibc"), []byte("address")), - nil, - }, - { - "success with multiple element prefix, last prefix empty", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")), - nil, - }, - { - "success with single empty key prefix", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte("")), - nil, - }, - { - "failure: invalid client id", - "", - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte("ibc")), - host.ErrInvalidID, - }, - { - "failure: invalid channel id", - ibctesting.FirstClientID, - "", - commitmenttypes.NewMerklePath([]byte("ibc")), - host.ErrInvalidID, - }, - { - "failure: empty merkle path prefix", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath(), - types.ErrInvalidChannel, - }, - { - "failure: empty key in merkle path prefix first element", - ibctesting.FirstClientID, - ibctesting.FirstChannelID, - commitmenttypes.NewMerklePath([]byte(""), []byte("ibc")), - types.ErrInvalidChannel, - }, - } - - for _, tc := range testCases { - tc := tc - - channel := types.NewChannel(tc.clientID, tc.channelID, tc.merklePathPrefix) - err := channel.Validate() - - expPass := tc.expError == nil - if expPass { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - require.ErrorIs(t, err, tc.expError) - } - } -} diff --git a/modules/core/packet-server/types/errors.go b/modules/core/packet-server/types/errors.go deleted file mode 100644 index 1c2d5cb3481..00000000000 --- a/modules/core/packet-server/types/errors.go +++ /dev/null @@ -1,10 +0,0 @@ -package types - -import ( - errorsmod "cosmossdk.io/errors" -) - -var ( - ErrInvalidChannel = errorsmod.Register(SubModuleName, 1, "invalid channel") - ErrChannelNotFound = errorsmod.Register(SubModuleName, 2, "channel not found") -) diff --git a/modules/core/packet-server/types/expected_keepers.go b/modules/core/packet-server/types/expected_keepers.go deleted file mode 100644 index 1fa932c4efd..00000000000 --- a/modules/core/packet-server/types/expected_keepers.go +++ /dev/null @@ -1,58 +0,0 @@ -package types - -import ( - "context" - - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v9/modules/core/exported" -) - -type ChannelKeeper interface { - // SetPacketCommitment writes the commitment hash under the commitment path - // This is a public path that is standardized by the IBC specification - SetPacketCommitment(ctx context.Context, portID string, channelID string, sequence uint64, commitment []byte) - - // GetPacketCommitment returns the packet commitment hash under the commitment path - GetPacketCommitment(ctx context.Context, portID string, channelID string, sequence uint64) []byte - - // DeletePacketCommitment deletes the packet commitment hash under the commitment path - DeletePacketCommitment(ctx context.Context, portID string, channelID string, sequence uint64) - - // SetNextSequenceSend writes the next send sequence under the sequence path - // This is a public path that is standardized by the IBC specification - SetNextSequenceSend(ctx context.Context, portID, channelID string, sequence uint64) - - // GetNextSequenceSend returns the next send sequence from the sequence path - GetNextSequenceSend(ctx context.Context, portID, channelID string) (uint64, bool) - - // SetPacketReceipt writes the packet receipt under the receipt path - // This is a public path that is standardized by the IBC specification - SetPacketReceipt(ctx context.Context, portID, channelID string, sequence uint64) - - // GetPacketReceipt returns the packet receipt from the packet receipt path - GetPacketReceipt(ctx context.Context, portID, channelID string, sequence uint64) (string, bool) - - // HasPacketAcknowledgement check if the packet ack hash is already on the store - HasPacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64) bool - - // SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path - // This is a public path that is standardized by the IBC specification - SetPacketAcknowledgement(ctx context.Context, portID, channelID string, sequence uint64, ackHash []byte) - - // GetV2Channel returns a version 2 channel for a given portID and channel ID - GetV2Channel(ctx context.Context, portID, channelID string) (Channel, bool) -} - -type ClientKeeper interface { - // VerifyMembership retrieves the light client module for the clientID and verifies the proof of the existence of a key-value pair at a specified height. - VerifyMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error - // VerifyNonMembership retrieves the light client module for the clientID and verifies the absence of a given key at a specified height. - VerifyNonMembership(ctx context.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error - // GetClientStatus returns the status of a client given the client ID - GetClientStatus(ctx context.Context, clientID string) exported.Status - // GetClientLatestHeight returns the latest height of a client given the client ID - GetClientLatestHeight(ctx context.Context, clientID string) clienttypes.Height - // GetClientTimestampAtHeight returns the timestamp for a given height on the client - // given its client ID and height - GetClientTimestampAtHeight(ctx context.Context, clientID string, height exported.Height) (uint64, error) -} diff --git a/modules/core/packet-server/types/keys.go b/modules/core/packet-server/types/keys.go deleted file mode 100644 index d1426569d57..00000000000 --- a/modules/core/packet-server/types/keys.go +++ /dev/null @@ -1,11 +0,0 @@ -package types - -const ( - // SubModuleName defines the IBC packet server name. - SubModuleName = "packetserver" - - // ChannelKey is the key used to store channel in the client store. - // the channel key is imported from types instead of host because - // the channel key is not a part of the ics-24 host specification - ChannelKey = "channel" -) diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index aa725076150..6c63e87e97e 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -128,7 +128,6 @@ import ( porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" @@ -203,7 +202,6 @@ type SimApp struct { GroupKeeper groupkeeper.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper CircuitKeeper circuitkeeper.Keeper - PacketServer *packetserverkeeper.Keeper // make IBC modules public for test purposes // these modules are never directly routed to by the IBC Router @@ -384,9 +382,6 @@ func NewSimApp( appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - // setup packet server keeper for Eureka tests - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) - govConfig := govtypes.DefaultConfig() /* Example of setting gov params: @@ -1056,11 +1051,6 @@ func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper { return app.IBCKeeper } -// GetPacketServer implements the TestingApp interface -func (app *SimApp) GetPacketServer() *packetserverkeeper.Keeper { - return app.PacketServer -} - // GetWasmKeeper implements the TestingApp interface. func (app *SimApp) GetWasmKeeper() wasmkeeper.Keeper { return app.WasmClientKeeper diff --git a/proto/ibc/core/packetserver/v1/channel.proto b/proto/ibc/core/packetserver/v1/channel.proto deleted file mode 100644 index 8ff15c78023..00000000000 --- a/proto/ibc/core/packetserver/v1/channel.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; - -package ibc.core.packetserver.v1; - -option go_package = "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"; - -import "gogoproto/gogo.proto"; -import "ibc/core/commitment/v2/commitment.proto"; - -// Channel defines the channel end on a chain that is implementing the version 2 IBC protocol -// Each side will maintain its own Channel to create an IBC channel -// The channel will be referenced by a channelID which will be used to send packets -// to the counterparty -// The channel will contain the client identifier that will provide proof verification for the channel -// and the counterparty channel identifier that the other channel end will be using -// to send packets to our channel end. -message Channel { - // the client identifier of the light client representing the counterparty chain - string client_id = 1; - // the counterparty identifier that must be used by the packet - string counterparty_channel_id = 2; - // the key path used to store packet flow messages that the counterparty - // will use to send to us. In backwards compatible cases, we will append the channelID and sequence in order to create - // the final path. - ibc.core.commitment.v2.MerklePath merkle_path_prefix = 3 [(gogoproto.nullable) = false]; -} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index d9b5cc38ea0..6ac8d9a87aa 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -108,7 +108,6 @@ import ( ibcapi "github.com/cosmos/ibc-go/v9/modules/core/api" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" @@ -175,7 +174,6 @@ type SimApp struct { ICAHostKeeper icahostkeeper.Keeper TransferKeeper ibctransferkeeper.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper - PacketServer *packetserverkeeper.Keeper // make IBC modules public for test purposes // these modules are never directly routed to by the IBC Router @@ -343,9 +341,6 @@ func NewSimApp( appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - // Setup packet server to call on Eureka tests - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) - govConfig := govtypes.DefaultConfig() /* Example of setting gov params: @@ -944,11 +939,6 @@ func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper { return app.IBCKeeper } -// GetPacketServer implements the TestingApp interface -func (app *SimApp) GetPacketServer() *packetserverkeeper.Keeper { - return app.PacketServer -} - // GetTxConfig implements the TestingApp interface. func (app *SimApp) GetTxConfig() client.TxConfig { return app.txConfig diff --git a/testing/testing_app.go b/testing/testing_app.go index b25630622a7..bdb99ec35fc 100644 --- a/testing/testing_app.go +++ b/testing/testing_app.go @@ -28,7 +28,6 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/ibc-go/v9/modules/core/keeper" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" "github.com/cosmos/ibc-go/v9/testing/simapp" ibctestingtypes "github.com/cosmos/ibc-go/v9/testing/types" ) @@ -43,7 +42,6 @@ type TestingApp interface { GetStakingKeeper() ibctestingtypes.StakingKeeper GetIBCKeeper() *keeper.Keeper GetTxConfig() client.TxConfig - GetPacketServer() *packetserverkeeper.Keeper // Implemented by SimApp AppCodec() codec.Codec