diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index 5de0570cd18..cb90333b30a 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -32,7 +32,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine" ibctmtypes "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -70,7 +70,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, testutil.TestEncodingConfig) { connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry) ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry) wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry) - packetservertypes.RegisterInterfaces(cfg.InterfaceRegistry) + channeltypesv2.RegisterInterfaces(cfg.InterfaceRegistry) // all other types upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry) diff --git a/modules/core/packet-server/client/cli/cli.go b/modules/core/04-channel/v2/client/cli/cli.go similarity index 67% rename from modules/core/packet-server/client/cli/cli.go rename to modules/core/04-channel/v2/client/cli/cli.go index 5c5a897b0f9..69952be9f81 100644 --- a/modules/core/packet-server/client/cli/cli.go +++ b/modules/core/04-channel/v2/client/cli/cli.go @@ -5,14 +5,14 @@ import ( "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) -// GetQueryCmd returns the query commands for the IBC packet-server. +// GetQueryCmd returns the query commands for the IBC channel/v2. func GetQueryCmd() *cobra.Command { queryCmd := &cobra.Command{ Use: types.SubModuleName, - Short: "IBC packet-server query subcommands", + Short: "IBC channel/v2 query subcommands", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -25,18 +25,19 @@ func GetQueryCmd() *cobra.Command { return queryCmd } -// NewTxCmd returns the command to submit transactions defined for the IBC packet-server. +// NewTxCmd returns the command to submit transactions defined for IBC channel/v2. func NewTxCmd() *cobra.Command { txCmd := &cobra.Command{ Use: types.SubModuleName, - Short: "IBC packet-server transaction subcommands", + Short: "IBC channel/v2 transaction subcommands", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } txCmd.AddCommand( - newProvideCounterpartyCmd(), + newCreateChannelTxCmd(), + newProvideCounterpartyTxCmd(), ) return txCmd diff --git a/modules/core/packet-server/client/cli/query.go b/modules/core/04-channel/v2/client/cli/query.go similarity index 55% rename from modules/core/packet-server/client/cli/query.go rename to modules/core/04-channel/v2/client/cli/query.go index 82e87400007..3521430d225 100644 --- a/modules/core/packet-server/client/cli/query.go +++ b/modules/core/04-channel/v2/client/cli/query.go @@ -9,28 +9,28 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) -// getCmdQueryChannel defines the command to query the client information (creator and channel) for the given client ID. +// getCmdQueryChannel defines the command to query the channel information (creator and channel) for the given channel ID. func getCmdQueryChannel() *cobra.Command { cmd := &cobra.Command{ - Use: "client [client-id]", - Short: "Query the information of a client.", - Long: "Query the client information (creator and channel) for the provided client ID.", - Example: fmt.Sprintf("%s query %s %s client [client-id]", version.AppName, exported.ModuleName, types.SubModuleName), + Use: "channel [channel-id]", + Short: "Query the information of a channel.", + Long: "Query the channel information (creator and channel) for the provided channel ID.", + Example: fmt.Sprintf("%s query %s %s channel [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - clientID := args[0] + channelID := args[0] queryClient := types.NewQueryClient(clientCtx) - req := &types.QueryChannelRequest{ChannelId: clientID} + req := &types.QueryChannelRequest{ChannelId: channelID} res, err := queryClient.Channel(cmd.Context(), req) if err != nil { diff --git a/modules/core/04-channel/v2/client/cli/tx.go b/modules/core/04-channel/v2/client/cli/tx.go new file mode 100644 index 00000000000..418f01815e7 --- /dev/null +++ b/modules/core/04-channel/v2/client/cli/tx.go @@ -0,0 +1,93 @@ +package cli + +import ( + "encoding/hex" + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// newCreateChannelTxCmd defines the command to create an IBC channel/v2. +func newCreateChannelTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-channel [client-identifier] [merkle-path-prefix]", + Args: cobra.ExactArgs(2), + Short: "create an IBC channel/v2", + Long: `Creates an IBC channel/v2 using the client identifier representing the counterparty chain and the hex-encoded merkle path prefix under which the counterparty stores packet flow information.`, + Example: fmt.Sprintf("%s tx %s %s create-channel 07-tendermint-0 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + clientID := args[0] + merklePathPrefix, err := parseMerklePathPrefix(args[2]) + if err != nil { + return err + } + + msg := types.NewMsgCreateChannel(clientID, merklePathPrefix, clientCtx.GetFromAddress().String()) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// newProvideCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel. +func newProvideCounterpartyTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]", + Args: cobra.ExactArgs(2), + Short: "provide the counterparty channel id to an IBC channel", + Long: `Provide the counterparty channel id to an IBC channel specified by its channel ID.`, + Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + channelID := args[0] + counterpartyChannelID := args[1] + + msg := types.MsgProvideCounterparty{ + ChannelId: channelID, + CounterpartyChannelId: counterpartyChannelID, + Signer: clientCtx.GetFromAddress().String(), + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath. +func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) { + var keyPath [][]byte + hexPrefixes := strings.Split(merklePathPrefixString, ",") + for _, hexPrefix := range hexPrefixes { + prefix, err := hex.DecodeString(hexPrefix) + if err != nil { + return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err) + } + keyPath = append(keyPath, prefix) + } + + return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil +} diff --git a/modules/core/04-channel/v2/keeper/events.go b/modules/core/04-channel/v2/keeper/events.go index 9d90ff5b36e..720fb93e11b 100644 --- a/modules/core/04-channel/v2/keeper/events.go +++ b/modules/core/04-channel/v2/keeper/events.go @@ -3,6 +3,8 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) @@ -25,3 +27,24 @@ func EmitAcknowledgePacketEvents(ctx context.Context, packet channeltypesv2.Pack func EmitTimeoutPacketEvents(ctx context.Context, packet channeltypesv2.Packet) { // TODO: https://github.com/cosmos/ibc-go/issues/7386 } + +// EmitWriteAcknowledgementEvents emits events for WriteAcknowledgement. +func EmitWriteAcknowledgementEvents(ctx context.Context, packet channeltypesv2.Packet, ack channeltypesv2.Acknowledgement) { + // TODO: https://github.com/cosmos/ibc-go/issues/7386 +} + +// EmitCreateChannelEvent emits a channel create event. +func (*Keeper) EmitCreateChannelEvent(ctx context.Context, channelID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + channeltypesv2.EventTypeCreateChannel, + sdk.NewAttribute(channeltypesv2.AttributeKeyChannelID, channelID), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, channeltypesv2.AttributeValueCategory), + ), + }) +} diff --git a/modules/core/packet-server/keeper/grpc_query.go b/modules/core/04-channel/v2/keeper/grpc_query.go similarity index 90% rename from modules/core/packet-server/keeper/grpc_query.go rename to modules/core/04-channel/v2/keeper/grpc_query.go index bc0182180bf..10343b516ab 100644 --- a/modules/core/packet-server/keeper/grpc_query.go +++ b/modules/core/04-channel/v2/keeper/grpc_query.go @@ -10,13 +10,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "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/packet-server/types" ) var _ types.QueryServer = (*queryServer)(nil) -// queryServer implements the packet-server types.QueryServer interface. +// queryServer implements the channel/v2 types.QueryServer interface. type queryServer struct { *Keeper } diff --git a/modules/core/packet-server/keeper/grpc_query_test.go b/modules/core/04-channel/v2/keeper/grpc_query_test.go similarity index 78% rename from modules/core/packet-server/keeper/grpc_query_test.go rename to modules/core/04-channel/v2/keeper/grpc_query_test.go index 79a2987c789..ad50fe3c6ba 100644 --- a/modules/core/packet-server/keeper/grpc_query_test.go +++ b/modules/core/04-channel/v2/keeper/grpc_query_test.go @@ -6,9 +6,9 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/keeper" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -28,8 +28,8 @@ func (suite *KeeperTestSuite) TestQueryChannel() { "success", func() { ctx := suite.chainA.GetContext() - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCreator(ctx, ibctesting.FirstChannelID, expCreator) - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetChannel(ctx, ibctesting.FirstChannelID, expChannel) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(ctx, ibctesting.FirstChannelID, expCreator) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(ctx, ibctesting.FirstChannelID, expChannel) req = &types.QueryChannelRequest{ ChannelId: ibctesting.FirstChannelID, @@ -42,7 +42,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() { func() { expCreator = "" - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID, expChannel) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID, expChannel) req = &types.QueryChannelRequest{ ChannelId: ibctesting.FirstChannelID, @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() { func() { expChannel = types.Channel{} - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expCreator) + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expCreator) req = &types.QueryChannelRequest{ ChannelId: ibctesting.FirstChannelID, @@ -100,7 +100,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() { tc.malleate() - queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.PacketServerKeeper) + queryServer := keeper.NewQueryServer(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeperV2) res, err := queryServer.Channel(suite.chainA.GetContext(), req) expPass := tc.expError == nil diff --git a/modules/core/04-channel/v2/keeper/keeper.go b/modules/core/04-channel/v2/keeper/keeper.go index 0d2d00a6da9..0880ed7b6e0 100644 --- a/modules/core/04-channel/v2/keeper/keeper.go +++ b/modules/core/04-channel/v2/keeper/keeper.go @@ -79,6 +79,29 @@ func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channe return channel, true } +// GetCreator returns the creator of the channel. +func (k *Keeper) GetCreator(ctx context.Context, channelID string) (string, bool) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + bz := k.ChannelStore(sdkCtx, channelID).Get([]byte(types.CreatorKey)) + if len(bz) == 0 { + return "", false + } + + return string(bz), true +} + +// SetCreator sets the creator of the channel. +func (k *Keeper) SetCreator(ctx context.Context, channelID, creator string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + k.ChannelStore(sdkCtx, channelID).Set([]byte(types.CreatorKey), []byte(creator)) +} + +// DeleteCreator deletes the creator associated with the channel. +func (k *Keeper) DeleteCreator(ctx context.Context, channelID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 + k.ChannelStore(sdkCtx, channelID).Delete([]byte(types.CreatorKey)) +} + // GetPacketReceipt returns the packet receipt from the packet receipt path based on the channelID and sequence. func (k *Keeper) GetPacketReceipt(ctx context.Context, channelID string, sequence uint64) ([]byte, bool) { store := k.storeService.OpenKVStore(ctx) @@ -112,6 +135,16 @@ func (k *Keeper) SetPacketReceipt(ctx context.Context, channelID string, sequenc } } +// GetPacketAcknowledgement fetches the packet acknowledgement from the store. +func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) []byte { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(hostv2.PacketAcknowledgementKey(channelID, sequence)) + if err != nil { + panic(err) + } + return bz +} + // SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path // This is a public path that is standardized by the IBC V2 specification. func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64, ackHash []byte) { @@ -123,13 +156,7 @@ func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, channelID string, // HasPacketAcknowledgement check if the packet ack hash is already on the store. func (k *Keeper) HasPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) bool { - store := k.storeService.OpenKVStore(ctx) - found, err := store.Has(hostv2.PacketAcknowledgementKey(channelID, sequence)) - if err != nil { - panic(err) - } - - return found + return len(k.GetPacketAcknowledgement(ctx, channelID, sequence)) > 0 } // GetPacketCommitment returns the packet commitment hash under the commitment path. diff --git a/modules/core/04-channel/v2/keeper/keeper_test.go b/modules/core/04-channel/v2/keeper/keeper_test.go index 80363d813d7..3521e3c789f 100644 --- a/modules/core/04-channel/v2/keeper/keeper_test.go +++ b/modules/core/04-channel/v2/keeper/keeper_test.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channeltypes2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -107,3 +108,46 @@ func (suite *KeeperTestSuite) TestAliasV1Channel() { }) } } + +func (suite *KeeperTestSuite) TestSetChannel() { + merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) + channel := channeltypes2.Channel{ + ClientId: ibctesting.FirstClientID, + MerklePathPrefix: merklePathPrefix, + } + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID, channel) + + retrievedChannel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID) + suite.Require().True(found, "GetChannel does not return channel") + suite.Require().Equal(channel, retrievedChannel, "Channel retrieved not equal") + + // No channel stored under other channel identifier. + retrievedChannel, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.SecondChannelID) + suite.Require().False(found, "GetChannel unexpectedly returned a channel") + suite.Require().Equal(channeltypes2.Channel{}, retrievedChannel, "Channel retrieved not empty") +} + +func (suite *KeeperTestSuite) TestSetCreator() { + expectedCreator := "test-creator" + + // Set the creator for the client + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expectedCreator) + + // Retrieve the creator from the store + retrievedCreator, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + + // Verify that the retrieved creator matches the expected creator + suite.Require().True(found, "GetCreator did not return stored creator") + suite.Require().Equal(expectedCreator, retrievedCreator, "Creator is not retrieved correctly") + + // Verify that the creator is deleted from the store + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID) + suite.Require().False(found, "GetCreator unexpectedly returned a creator") + suite.Require().Empty(retrievedCreator, "Creator is not empty") + + // Verify non stored creator is not found + retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.SecondChannelID) + suite.Require().False(found, "GetCreator unexpectedly returned a creator") + suite.Require().Empty(retrievedCreator, "Creator is not empty") +} diff --git a/modules/core/04-channel/v2/keeper/msg_server.go b/modules/core/04-channel/v2/keeper/msg_server.go index 740ebb02daa..1d8add950d4 100644 --- a/modules/core/04-channel/v2/keeper/msg_server.go +++ b/modules/core/04-channel/v2/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "slices" errorsmod "cosmossdk.io/errors" @@ -9,6 +10,9 @@ import ( channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" + telemetryv2 "github.com/cosmos/ibc-go/v9/modules/core/internal/v2/telemetry" ) var _ channeltypesv2.MsgServer = &Keeper{} @@ -62,29 +66,25 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *channeltypesv2.MsgAck return nil, errorsmod.Wrap(err, "acknowledge packet verification failed") } - _ = relayer + recvResults := make(map[string]channeltypesv2.RecvPacketResult) + for _, r := range msg.Acknowledgement.AcknowledgementResults { + recvResults[r.AppName] = r.RecvPacketResult + } - // TODO: implement once app router is wired up. - // https://github.com/cosmos/ibc-go/issues/7384 - // for _, pd := range msg.PacketData { - // cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort) - // err := cbs.OnSendPacket(ctx, msg.SourceId, sequence, msg.TimeoutTimestamp, pd, signer) - // if err != nil { - // return nil, err - // } - // } + for _, pd := range msg.Packet.Data { + cbs := k.Router.Route(pd.SourcePort) + err := cbs.OnAcknowledgementPacket(ctx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, recvResults[pd.DestinationPort].Acknowledgement, relayer) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed OnAcknowledgementPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, msg.Packet.SourceChannel, msg.Packet.DestinationChannel) + } + } - return nil, nil + return &channeltypesv2.MsgAcknowledgementResponse{Result: channeltypesv1.SUCCESS}, nil } // RecvPacket implements the PacketMsgServer RecvPacket method. func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPacket) (*channeltypesv2.MsgRecvPacketResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - err := k.recvPacket(ctx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) - if err != nil { - sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "dest-channel", msg.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "send packet failed")) - return nil, errorsmod.Wrapf(err, "receive packet failed for source id: %s and destination id: %s", msg.Packet.SourceChannel, msg.Packet.DestinationChannel) - } signer, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { @@ -92,28 +92,79 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack return nil, errorsmod.Wrap(err, "invalid address for msg Signer") } - _ = signer + // Perform TAO verification + // + // If the packet was already received, perform a no-op + // Use a cached context to prevent accidental state changes + cacheCtx, writeFn := sdkCtx.CacheContext() + err = k.recvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight) + + switch err { + case nil: + writeFn() + case channeltypesv1.ErrNoOpMsg: + // no-ops do not need event emission as they will be ignored + sdkCtx.Logger().Debug("no-op on redundant relay", "source-channel", msg.Packet.SourceChannel) + return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.NOOP}, nil + default: + sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "receive packet verification failed")) + return nil, errorsmod.Wrap(err, "receive packet verification failed") + } + + // build up the recv results for each application callback. + ack := channeltypesv2.Acknowledgement{ + AcknowledgementResults: []channeltypesv2.AcknowledgementResult{}, + } + + for _, pd := range msg.Packet.Data { + // Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful. + cacheCtx, writeFn = sdkCtx.CacheContext() + cb := k.Router.Route(pd.DestinationPort) + res := cb.OnRecvPacket(cacheCtx, msg.Packet.SourceChannel, msg.Packet.DestinationChannel, pd, signer) + + if res.Status != channeltypesv2.PacketStatus_Failure { + // write application state changes for asynchronous and successful acknowledgements + writeFn() + } else { + // Modify events in cached context to reflect unsuccessful acknowledgement + sdkCtx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) + } + + ack.AcknowledgementResults = append(ack.AcknowledgementResults, channeltypesv2.AcknowledgementResult{ + AppName: pd.DestinationPort, + RecvPacketResult: res, + }) + } + + // note this should never happen as the packet data would have had to be empty. + if len(ack.AcknowledgementResults) == 0 { + sdkCtx.Logger().Error("receive packet failed", "source-channel", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "invalid acknowledgement results")) + return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.FAILURE}, errorsmod.Wrapf(err, "receive packet failed source-channel %s invalid acknowledgement results", msg.Packet.SourceChannel) + } + + // NOTE: TBD how we will handle async acknowledgements with more than one packet data. + isAsync := slices.ContainsFunc(ack.AcknowledgementResults, func(ackResult channeltypesv2.AcknowledgementResult) bool { + return ackResult.RecvPacketResult.Status == channeltypesv2.PacketStatus_Async + }) + + if !isAsync { + // Set packet acknowledgement only if the acknowledgement is not async. + // NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the + // acknowledgement is async. + if err := k.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil { + return nil, err + } + } - // TODO: implement once app router is wired up. - // https://github.com/cosmos/ibc-go/issues/7384 - // for _, pd := range packet.PacketData { - // cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort) - // err := cbs.OnRecvPacket(ctx, packet, msg.ProofCommitment, msg.ProofHeight, signer) - // if err != nil { - // return nil, err - // } - // } + defer telemetryv2.ReportRecvPacket(msg.Packet) + sdkCtx.Logger().Info("receive packet callback succeeded", "source-channel", msg.Packet.SourceChannel, "dest-channel", msg.Packet.DestinationChannel, "result", channeltypesv1.SUCCESS.String()) return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.SUCCESS}, nil } // Timeout implements the PacketMsgServer Timeout method. func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout) (*channeltypesv2.MsgTimeoutResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - if err := k.timeoutPacket(ctx, timeout.Packet, timeout.ProofUnreceived, timeout.ProofHeight); err != nil { - sdkCtx.Logger().Error("Timeout packet failed", "source-channel", timeout.Packet.SourceChannel, "destination-channel", timeout.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "timeout packet failed")) - return nil, errorsmod.Wrapf(err, "send packet failed for source id: %s and destination id: %s", timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel) - } signer, err := sdk.AccAddressFromBech32(timeout.Signer) if err != nil { @@ -121,17 +172,74 @@ func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout return nil, errorsmod.Wrap(err, "invalid address for msg Signer") } - _ = signer + cacheCtx, writeFn := sdkCtx.CacheContext() + if err := k.timeoutPacket(cacheCtx, timeout.Packet, timeout.ProofUnreceived, timeout.ProofHeight); err != nil { + sdkCtx.Logger().Error("Timeout packet failed", "source-channel", timeout.Packet.SourceChannel, "destination-channel", timeout.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "timeout packet failed")) + return nil, errorsmod.Wrapf(err, "timeout packet failed for source id: %s and destination id: %s", timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel) + } + + switch err { + case nil: + writeFn() + case channeltypesv1.ErrNoOpMsg: + // no-ops do not need event emission as they will be ignored + sdkCtx.Logger().Debug("no-op on redundant relay", "source-channel", timeout.Packet.SourceChannel) + return &channeltypesv2.MsgTimeoutResponse{Result: channeltypesv1.NOOP}, nil + default: + sdkCtx.Logger().Error("timeout failed", "source-channel", timeout.Packet.SourceChannel, "error", errorsmod.Wrap(err, "timeout packet verification failed")) + return nil, errorsmod.Wrap(err, "timeout packet verification failed") + } - // TODO: implement once app router is wired up. - // https://github.com/cosmos/ibc-go/issues/7384 - // for _, pd := range timeout.Packet.Data { - // cbs := k.PortKeeper.AppRouter.Route(pd.SourcePort) - // err := cbs.OnTimeoutPacket(timeout.Packet.SourceChannel, timeout.Packet.TimeoutTimestamp, signer) - // if err != nil { - // return err, err - // } - // } + for _, pd := range timeout.Packet.Data { + cbs := k.Router.Route(pd.SourcePort) + err := cbs.OnTimeoutPacket(ctx, timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel, pd, signer) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed OnTimeoutPacket for source port %s, source channel %s, destination channel %s", pd.SourcePort, timeout.Packet.SourceChannel, timeout.Packet.DestinationChannel) + } + } return &channeltypesv2.MsgTimeoutResponse{Result: channeltypesv1.SUCCESS}, nil } + +// CreateChannel defines a rpc handler method for MsgCreateChannel +func (k *Keeper) CreateChannel(goCtx context.Context, msg *channeltypesv2.MsgCreateChannel) (*channeltypesv2.MsgCreateChannelResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + channelID := k.channelKeeperV1.GenerateChannelIdentifier(ctx) + + // Initialize channel with empty counterparty channel identifier. + channel := channeltypesv2.NewChannel(msg.ClientId, "", msg.MerklePathPrefix) + k.SetChannel(ctx, channelID, channel) + k.SetCreator(ctx, channelID, msg.Signer) + k.SetNextSequenceSend(ctx, channelID, 1) + + k.EmitCreateChannelEvent(goCtx, channelID) + + return &channeltypesv2.MsgCreateChannelResponse{ChannelId: channelID}, nil +} + +// ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. +func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *channeltypesv2.MsgProvideCounterparty) (*channeltypesv2.MsgProvideCounterpartyResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + creator, found := k.GetCreator(ctx, msg.ChannelId) + if !found { + return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set") + } + + if creator != msg.Signer { + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "channel creator (%s) must match signer (%s)", creator, msg.Signer) + } + + channel, ok := k.GetChannel(ctx, msg.ChannelId) + if !ok { + return nil, errorsmod.Wrapf(channeltypesv2.ErrInvalidChannel, "channel must exist for channel id %s", msg.ChannelId) + } + + channel.CounterpartyChannelId = msg.CounterpartyChannelId + k.SetChannel(ctx, msg.ChannelId, channel) + // Delete client creator from state as it is not needed after this point. + k.DeleteCreator(ctx, msg.ChannelId) + + return &channeltypesv2.MsgProvideCounterpartyResponse{}, nil +} diff --git a/modules/core/04-channel/v2/keeper/msg_server_test.go b/modules/core/04-channel/v2/keeper/msg_server_test.go index 1f4aabd1c86..e9cd0e562cb 100644 --- a/modules/core/04-channel/v2/keeper/msg_server_test.go +++ b/modules/core/04-channel/v2/keeper/msg_server_test.go @@ -2,13 +2,17 @@ package keeper_test import ( "context" + "errors" "fmt" + "time" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ibctesting "github.com/cosmos/ibc-go/v9/testing" "github.com/cosmos/ibc-go/v9/testing/mock" mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" @@ -16,9 +20,10 @@ import ( func (suite *KeeperTestSuite) TestMsgSendPacket() { var ( - path *ibctesting.Path - msg *channeltypesv2.MsgSendPacket - expectedPacket channeltypesv2.Packet + path *ibctesting.Path + expectedPacket channeltypesv2.Packet + timeoutTimestamp uint64 + packetData channeltypesv2.PacketData ) testCases := []struct { @@ -35,7 +40,7 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { name: "failure: timeout elapsed", malleate: func() { // ensure a message timeout. - msg.TimeoutTimestamp = uint64(1) + timeoutTimestamp = uint64(1) }, expError: channeltypesv1.ErrTimeoutElapsed, }, @@ -58,14 +63,14 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { { name: "failure: counterparty not found", malleate: func() { - msg.SourceChannel = "foo" + path.EndpointA.ChannelID = ibctesting.InvalidID }, expError: channeltypesv1.ErrChannelNotFound, }, { name: "failure: route to non existing app", malleate: func() { - msg.PacketData[0].SourcePort = "foo" + packetData.SourcePort = "foo" }, expError: fmt.Errorf("no route for foo"), }, @@ -80,19 +85,19 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { path = ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupV2() - timeoutTimestamp := suite.chainA.GetTimeoutTimestamp() - msg = channeltypesv2.NewMsgSendPacket(path.EndpointA.ChannelID, timeoutTimestamp, suite.chainA.SenderAccount.GetAddress().String(), mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)) + timeoutTimestamp = suite.chainA.GetTimeoutTimestamp() + packetData = mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB) - expectedPacket = channeltypesv2.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)) + expectedPacket = channeltypesv2.NewPacket(1, path.EndpointA.ChannelID, path.EndpointB.ChannelID, timeoutTimestamp, packetData) tc.malleate() - res, err := path.EndpointA.Chain.SendMsgs(msg) + packet, err := path.EndpointA.MsgSendPacket(timeoutTimestamp, packetData) expPass := tc.expError == nil if expPass { suite.Require().NoError(err) - suite.Require().NotNil(res) + suite.Require().NotEmpty(packet) ck := path.EndpointA.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2 @@ -104,6 +109,8 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { suite.Require().True(ok) suite.Require().Equal(uint64(2), nextSequenceSend, "next sequence send was not incremented correctly") + suite.Require().Equal(expectedPacket, packet) + } else { suite.Require().Error(err) ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError) @@ -111,3 +118,413 @@ func (suite *KeeperTestSuite) TestMsgSendPacket() { }) } } + +func (suite *KeeperTestSuite) TestMsgRecvPacket() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + expectedAck channeltypesv2.Acknowledgement + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + expError: nil, + }, + { + name: "success: failed recv result", + malleate: func() { + failedRecvResult := channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Failure, + Acknowledgement: mock.MockFailPacketData, + } + + // a failed ack should be returned by the application. + expectedAck.AcknowledgementResults[0].RecvPacketResult = failedRecvResult + + path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult { + return failedRecvResult + } + }, + }, + { + name: "success: async recv result", + malleate: func() { + asyncResult := channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Async, + Acknowledgement: nil, + } + + // an async ack should be returned by the application. + expectedAck.AcknowledgementResults[0].RecvPacketResult = asyncResult + + path.EndpointB.Chain.GetSimApp().MockModuleV2B.IBCApp.OnRecvPacket = func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult { + return asyncResult + } + }, + }, + { + name: "success: NoOp", + malleate: func() { + suite.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(suite.chainB.GetContext(), packet.SourceChannel, packet.Sequence) + expectedAck = channeltypesv2.Acknowledgement{} + }, + }, + { + name: "failure: counterparty not found", + malleate: func() { + // change the destination id to a non-existent channel. + packet.DestinationChannel = ibctesting.InvalidID + }, + expError: channeltypesv2.ErrChannelNotFound, + }, + { + name: "failure: invalid proof", + malleate: func() { + // proof verification fails because the packet commitment is different due to a different sequence. + packet.Sequence = 10 + }, + expError: commitmenttypes.ErrInvalidProof, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + timeoutTimestamp := suite.chainA.GetTimeoutTimestamp() + + var err error + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)) + suite.Require().NoError(err) + + // default expected ack is a single successful recv result for moduleB. + expectedAck = channeltypesv2.Acknowledgement{ + AcknowledgementResults: []channeltypesv2.AcknowledgementResult{ + { + AppName: mockv2.ModuleNameB, + RecvPacketResult: channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Success, + Acknowledgement: mock.MockPacketData, + }, + }, + }, + } + + tc.malleate() + + err = path.EndpointB.MsgRecvPacket(packet) + + ck := path.EndpointB.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2 + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + + // packet receipt should be written + _, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), packet.SourceChannel, packet.Sequence) + suite.Require().True(ok) + + ackWritten := ck.HasPacketAcknowledgement(path.EndpointB.Chain.GetContext(), packet.DestinationChannel, packet.Sequence) + + if len(expectedAck.AcknowledgementResults) == 0 || expectedAck.AcknowledgementResults[0].RecvPacketResult.Status == channeltypesv2.PacketStatus_Async { + // ack should not be written for async app or if the packet receipt was already present. + suite.Require().False(ackWritten) + } else { // successful or failed acknowledgement + // ack should be written for synchronous app (default mock application behaviour). + suite.Require().True(ackWritten) + expectedBz := channeltypesv2.CommitAcknowledgement(expectedAck) + + actualAckBz := ck.GetPacketAcknowledgement(path.EndpointB.Chain.GetContext(), packet.DestinationChannel, packet.Sequence) + suite.Require().Equal(expectedBz, actualAckBz) + } + + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError) + _, ok := ck.GetPacketReceipt(path.EndpointB.Chain.GetContext(), packet.SourceChannel, packet.Sequence) + suite.Require().False(ok) + } + }) + } +} + +func (suite *KeeperTestSuite) TestProvideCounterparty() { + var ( + path *ibctesting.Path + msg *channeltypesv2.MsgProvideCounterparty + ) + cases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() { + // set it before handler + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), msg.ChannelId, channeltypesv2.NewChannel(path.EndpointA.ClientID, "", ibctesting.MerklePath)) + }, + nil, + }, + { + "failure: signer does not match creator", + func() { + msg.Signer = path.EndpointB.Chain.SenderAccount.GetAddress().String() + }, + ibcerrors.ErrUnauthorized, + }, + /* // Account sequence mismatch, expected 5, got 6. :thinking: + { + "failure: counterparty does not already exists", + func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(channeltypesv2.ChannelKey)) + }, + channeltypesv2.ErrInvalidChannel, + }, + */ + } + + for _, tc := range cases { + tc := tc + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupClients() + + suite.Require().NoError(path.EndpointA.CreateChannel()) + suite.Require().NoError(path.EndpointB.CreateChannel()) + + signer := path.EndpointA.Chain.SenderAccount.GetAddress().String() + msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer) + + tc.malleate() + + res, err := path.EndpointA.Chain.SendMsgs(msg) + + expPass := tc.expError == nil + if expPass { + suite.Require().NotNil(res) + suite.Require().Nil(err) + + // Assert counterparty channel id filled in and creator deleted + channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().True(found) + suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID) + + _, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().False(found) + + seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID) + suite.Require().True(found) + suite.Require().Equal(seq, uint64(1)) + } else { + suite.Require().Error(err) + } + } +} + +func (suite *KeeperTestSuite) TestMsgAcknowledgement() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + ack channeltypesv2.Acknowledgement + ) + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "success: NoOp", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeletePacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + + // Modify the callback to return an error. + // This way, we can verify that the callback is not executed in a No-op case. + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.PacketData, []byte, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + }, + { + name: "failure: callback fails", + malleate: func() { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnAcknowledgementPacket = func(context.Context, string, string, channeltypesv2.PacketData, []byte, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: mock.MockApplicationCallbackError, + }, + { + name: "failure: counterparty not found", + malleate: func() { + // change the source id to a non-existent channel. + packet.SourceChannel = "not-existent-channel" + }, + expError: channeltypesv2.ErrChannelNotFound, + }, + { + name: "failure: invalid commitment", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence, []byte("foo")) + }, + expError: channeltypesv2.ErrInvalidPacket, + }, + { + name: "failure: failed membership verification", + malleate: func() { + ack.AcknowledgementResults[0].RecvPacketResult.Acknowledgement = mock.MockFailPacketData + }, + expError: errors.New("failed packet acknowledgement verification"), + }, + } + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + timeoutTimestamp := suite.chainA.GetTimeoutTimestamp() + + var err error + // Send packet from A to B + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)) + suite.Require().NoError(err) + + err = path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + + // Construct expected acknowledgement + ack = channeltypesv2.Acknowledgement{ + AcknowledgementResults: []channeltypesv2.AcknowledgementResult{ + { + AppName: mockv2.ModuleNameB, + RecvPacketResult: channeltypesv2.RecvPacketResult{ + Status: channeltypesv2.PacketStatus_Success, + Acknowledgement: mock.MockPacketData, + }, + }, + }, + } + + tc.malleate() + + // Finally, acknowledge the packet on A + err = path.EndpointA.MsgAcknowledgePacket(packet, ack) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestMsgTimeout() { + var ( + path *ibctesting.Path + packet channeltypesv2.Packet + ) + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: no-op", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeletePacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence) + + // Modify the callback to return a different error. + // This way, we can verify that the callback is not executed in a No-op case. + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.PacketData, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: channeltypesv1.ErrNoOpMsg, + }, + { + name: "failure: callback fails", + malleate: func() { + path.EndpointA.Chain.GetSimApp().MockModuleV2A.IBCApp.OnTimeoutPacket = func(context.Context, string, string, channeltypesv2.PacketData, sdk.AccAddress) error { + return mock.MockApplicationCallbackError + } + }, + expError: mock.MockApplicationCallbackError, + }, + { + name: "failure: channel not found", + malleate: func() { + // change the source id to a non-existent channel. + packet.SourceChannel = "not-existent-channel" + }, + expError: channeltypesv2.ErrChannelNotFound, + }, + { + name: "failure: invalid commitment", + malleate: func() { + suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetPacketCommitment(suite.chainA.GetContext(), packet.SourceChannel, packet.Sequence, []byte("foo")) + }, + expError: channeltypesv2.ErrInvalidPacket, + }, + { + name: "failure: unable to timeout if packet has been received", + malleate: func() { + err := path.EndpointB.MsgRecvPacket(packet) + suite.Require().NoError(err) + }, + expError: commitmenttypes.ErrInvalidProof, + }, + } + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + path = ibctesting.NewPath(suite.chainA, suite.chainB) + path.SetupV2() + + // Send packet from A to B + timeoutTimestamp := suite.chainA.GetTimeoutTimestamp() + mockData := mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB) + + var err error + packet, err = path.EndpointA.MsgSendPacket(timeoutTimestamp, mockData) + suite.Require().NoError(err) + suite.Require().NotEmpty(packet) + + tc.malleate() + + suite.coordinator.IncrementTimeBy(time.Hour * 20) + suite.Require().NoError(path.EndpointA.UpdateClient()) + + err = path.EndpointA.MsgTimeoutPacket(packet) + + expPass := tc.expError == nil + if expPass { + suite.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err) + } + }) + } +} diff --git a/modules/core/04-channel/v2/keeper/packet.go b/modules/core/04-channel/v2/keeper/packet.go index 7885ff7107a..90b7bbd7ff8 100644 --- a/modules/core/04-channel/v2/keeper/packet.go +++ b/modules/core/04-channel/v2/keeper/packet.go @@ -14,7 +14,6 @@ import ( channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) // sendPacket constructs a packet from the input arguments, writes a packet commitment to state @@ -31,18 +30,19 @@ func (k *Keeper) sendPacket( // TODO: figure out how aliasing will work when more than one packet data is sent. channel, ok = k.convertV1Channel(ctx, data[0].SourcePort, sourceChannel) if !ok { - return 0, "", errorsmod.Wrap(types.ErrChannelNotFound, sourceChannel) + return 0, "", errorsmod.Wrap(channeltypesv2.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.GetNextSequenceSend(ctx, sourceChannel) if !found { - sequence = 1 + return 0, "", errorsmod.Wrapf( + channeltypesv2.ErrSequenceSendNotFound, + "source channel: %s", sourceChannel, + ) } // construct packet from given fields and channel state @@ -68,7 +68,7 @@ func (k *Keeper) sendPacket( return 0, "", err } - timeout := channeltypesv2.TimeoutTimestampToNanos(timeoutTimestamp) + timeout := channeltypesv2.TimeoutTimestampToNanos(packet.TimeoutTimestamp) if timeout < latestTimestamp { return 0, "", errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "latest timestamp: %d, timeout timestamp: %d", latestTimestamp, packet.TimeoutTimestamp) } @@ -104,12 +104,12 @@ func (k *Keeper) recvPacket( // TODO: figure out how aliasing will work when more than one packet data is sent. channel, ok = k.convertV1Channel(ctx, packet.Data[0].DestinationPort, packet.DestinationChannel) if !ok { - return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) + return errorsmod.Wrap(channeltypesv2.ErrChannelNotFound, packet.DestinationChannel) } } if channel.CounterpartyChannelId != packet.SourceChannel { - return channeltypes.ErrInvalidChannelIdentifier + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, packet.SourceChannel) } clientID := channel.ClientId @@ -118,7 +118,7 @@ func (k *Keeper) recvPacket( sdkCtx := sdk.UnwrapSDKContext(ctx) currentTimestamp := uint64(sdkCtx.BlockTime().Unix()) timeout := channeltypesv2.TimeoutTimestampToNanos(packet.TimeoutTimestamp) - if timeout >= currentTimestamp { + if timeout <= currentTimestamp { return errorsmod.Wrapf(channeltypes.ErrTimeoutElapsed, "current timestamp: %d, timeout timestamp: %d", currentTimestamp, packet.GetTimeoutTimestamp()) } @@ -134,7 +134,7 @@ func (k *Keeper) recvPacket( } path := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) commitment := channeltypesv2.CommitPacket(packet) @@ -147,7 +147,7 @@ func (k *Keeper) recvPacket( merklePath, commitment, ); err != nil { - return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationChannel) + return errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) } // Set Packet Receipt to prevent timeout from occurring on counterparty @@ -160,14 +160,56 @@ func (k *Keeper) recvPacket( return nil } +// WriteAcknowledgement writes the acknowledgement to the store. +func (k Keeper) WriteAcknowledgement( + ctx context.Context, + packet channeltypesv2.Packet, + ack channeltypesv2.Acknowledgement, +) error { + // Lookup channel associated with destination channel ID and ensure + // that the packet was indeed sent by our counterparty by verifying + // packet sender is our channel's counterparty channel id. + channel, ok := k.GetChannel(ctx, packet.DestinationChannel) + if !ok { + return errorsmod.Wrapf(channeltypesv2.ErrChannelNotFound, "channel (%s) not found", 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.HasPacketAcknowledgement(ctx, packet.DestinationChannel, packet.Sequence) { + return errorsmod.Wrapf(channeltypes.ErrAcknowledgementExists, "acknowledgement for channel %s, sequence %d already exists", packet.DestinationChannel, packet.Sequence) + } + + if _, found := k.GetPacketReceipt(ctx, packet.DestinationChannel, packet.Sequence); !found { + return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet") + } + + // set the acknowledgement so that it can be verified on the other side + k.SetPacketAcknowledgement( + ctx, packet.DestinationChannel, packet.Sequence, + channeltypesv2.CommitAcknowledgement(ack), + ) + + k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest-channel", packet.DestinationChannel) + + EmitWriteAcknowledgementEvents(ctx, packet, ack) + + return nil +} + func (k *Keeper) acknowledgePacket(ctx context.Context, packet channeltypesv2.Packet, acknowledgement channeltypesv2.Acknowledgement, proof []byte, proofHeight exported.Height) error { channel, ok := k.GetChannel(ctx, packet.SourceChannel) if !ok { - return errorsmod.Wrap(types.ErrChannelNotFound, packet.SourceChannel) + return errorsmod.Wrap(channeltypesv2.ErrChannelNotFound, packet.SourceChannel) } if channel.CounterpartyChannelId != packet.DestinationChannel { - return channeltypes.ErrInvalidChannelIdentifier + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) } clientID := channel.ClientId @@ -192,7 +234,7 @@ func (k *Keeper) acknowledgePacket(ctx context.Context, packet channeltypesv2.Pa } path := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyMembership( ctx, @@ -230,11 +272,11 @@ func (k *Keeper) timeoutPacket( ) error { channel, ok := k.GetChannel(ctx, packet.SourceChannel) if !ok { - return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) + return errorsmod.Wrap(channeltypesv2.ErrChannelNotFound, packet.DestinationChannel) } if channel.CounterpartyChannelId != packet.DestinationChannel { - return channeltypes.ErrInvalidChannelIdentifier + return errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) } clientID := channel.ClientId @@ -269,7 +311,7 @@ func (k *Keeper) timeoutPacket( // verify packet receipt absence path := hostv2.PacketReceiptKey(packet.SourceChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyNonMembership( ctx, @@ -279,7 +321,7 @@ func (k *Keeper) timeoutPacket( proof, merklePath, ); err != nil { - return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", packet.SourceChannel) + return errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) } // delete packet commitment to prevent replay diff --git a/modules/core/packet-server/module.go b/modules/core/04-channel/v2/module.go similarity index 75% rename from modules/core/packet-server/module.go rename to modules/core/04-channel/v2/module.go index c695542ca50..9bc3ad94699 100644 --- a/modules/core/packet-server/module.go +++ b/modules/core/04-channel/v2/module.go @@ -3,8 +3,8 @@ package client import ( "github.com/spf13/cobra" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/client/cli" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/client/cli" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) // Name returns the IBC client name diff --git a/modules/core/04-channel/v2/types/codec.go b/modules/core/04-channel/v2/types/codec.go index 1053c8b64d6..79941f59175 100644 --- a/modules/core/04-channel/v2/types/codec.go +++ b/modules/core/04-channel/v2/types/codec.go @@ -14,5 +14,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { &MsgRecvPacket{}, &MsgTimeout{}, &MsgAcknowledgement{}, + &MsgCreateChannel{}, + &MsgProvideCounterparty{}, ) } diff --git a/modules/core/04-channel/v2/types/errors.go b/modules/core/04-channel/v2/types/errors.go index 7f56d8f8e34..2873867295b 100644 --- a/modules/core/04-channel/v2/types/errors.go +++ b/modules/core/04-channel/v2/types/errors.go @@ -5,8 +5,10 @@ import ( ) var ( - ErrInvalidChannel = errorsmod.Register(SubModuleName, 1, "invalid channel") - ErrChannelNotFound = errorsmod.Register(SubModuleName, 2, "channel not found") - ErrInvalidPacket = errorsmod.Register(SubModuleName, 3, "invalid packet") - ErrInvalidPayload = errorsmod.Register(SubModuleName, 4, "invalid payload") + ErrInvalidChannel = errorsmod.Register(SubModuleName, 2, "invalid channel") + ErrChannelNotFound = errorsmod.Register(SubModuleName, 3, "channel not found") + ErrInvalidPacket = errorsmod.Register(SubModuleName, 4, "invalid packet") + ErrInvalidPayload = errorsmod.Register(SubModuleName, 5, "invalid payload") + ErrSequenceSendNotFound = errorsmod.Register(SubModuleName, 6, "sequence send not found") + ErrInvalidPacketData = errorsmod.Register(SubModuleName, 7, "invalid packet data") ) diff --git a/modules/core/packet-server/types/events.go b/modules/core/04-channel/v2/types/events.go similarity index 100% rename from modules/core/packet-server/types/events.go rename to modules/core/04-channel/v2/types/events.go diff --git a/modules/core/04-channel/v2/types/keys.go b/modules/core/04-channel/v2/types/keys.go index 965f010716e..af3f68c5449 100644 --- a/modules/core/04-channel/v2/types/keys.go +++ b/modules/core/04-channel/v2/types/keys.go @@ -8,4 +8,9 @@ const ( // 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" + + // CreatorKey is the key used to store the client creator in the client store + // the creator key is imported from types instead of host because + // the creator key is not a part of the ics-24 host specification + CreatorKey = "creator" ) diff --git a/modules/core/packet-server/types/merkle.go b/modules/core/04-channel/v2/types/merkle.go similarity index 100% rename from modules/core/packet-server/types/merkle.go rename to modules/core/04-channel/v2/types/merkle.go diff --git a/modules/core/packet-server/types/merkle_test.go b/modules/core/04-channel/v2/types/merkle_test.go similarity index 76% rename from modules/core/packet-server/types/merkle_test.go rename to modules/core/04-channel/v2/types/merkle_test.go index 46c75dd2303..df239bc17d7 100644 --- a/modules/core/packet-server/types/merkle_test.go +++ b/modules/core/04-channel/v2/types/merkle_test.go @@ -1,41 +1,19 @@ package types_test import ( - "testing" - - "github.com/stretchr/testify/suite" - + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" commitmenttypesv2 "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" ) -type TypesTestSuite struct { - suite.Suite - - coordinator *ibctesting.Coordinator - chainA *ibctesting.TestChain - chainB *ibctesting.TestChain -} - -func (s *TypesTestSuite) SetupTest() { - s.coordinator = ibctesting.NewCoordinator(s.T(), 2) - s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) - s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) -} - -func TestTypesTestSuite(t *testing.T) { - suite.Run(t, new(TypesTestSuite)) -} - func (s *TypesTestSuite) TestBuildMerklePath() { path := ibctesting.NewPath(s.chainA, s.chainB) path.SetupV2() prefixPath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) - packetCommitmentKey := host.PacketCommitmentKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ClientID, 1) + packetCommitmentKey := host.PacketCommitmentKey(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 1) testCases := []struct { name string diff --git a/modules/core/04-channel/v2/types/msgs.go b/modules/core/04-channel/v2/types/msgs.go index f2b52aaf802..d48f0f653ee 100644 --- a/modules/core/04-channel/v2/types/msgs.go +++ b/modules/core/04-channel/v2/types/msgs.go @@ -1,5 +1,81 @@ package types +import ( + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + commitmenttypesv1 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" +) + +var ( + _ sdk.Msg = (*MsgProvideCounterparty)(nil) + _ sdk.HasValidateBasic = (*MsgProvideCounterparty)(nil) + + _ sdk.Msg = (*MsgCreateChannel)(nil) + _ sdk.HasValidateBasic = (*MsgCreateChannel)(nil) + + _ sdk.Msg = (*MsgRecvPacket)(nil) + _ sdk.HasValidateBasic = (*MsgRecvPacket)(nil) +) + +// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance +func NewMsgProvideCounterparty(channelID, counterpartyChannelID string, signer string) *MsgProvideCounterparty { + return &MsgProvideCounterparty{ + Signer: signer, + ChannelId: channelID, + CounterpartyChannelId: counterpartyChannelID, + } +} + +// ValidateBasic performs basic checks on a MsgProvideCounterparty. +func (msg *MsgProvideCounterparty) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil { + return err + } + + if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { + return err + } + + return nil +} + +// NewMsgCreateChannel creates a new MsgCreateChannel instance +func NewMsgCreateChannel(clientID string, merklePathPrefix commitmenttypesv2.MerklePath, signer string) *MsgCreateChannel { + return &MsgCreateChannel{ + Signer: signer, + ClientId: clientID, + MerklePathPrefix: merklePathPrefix, + } +} + +// ValidateBasic performs basic checks on a MsgCreateChannel. +func (msg *MsgCreateChannel) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { + return err + } + + if err := msg.MerklePathPrefix.ValidateAsPrefix(); err != nil { + return err + } + + return nil +} + // NewMsgSendPacket creates a new MsgSendPacket instance. func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer string, packetData ...PacketData) *MsgSendPacket { return &MsgSendPacket{ @@ -9,3 +85,76 @@ func NewMsgSendPacket(sourceChannel string, timeoutTimestamp uint64, signer stri Signer: signer, } } + +// ValidateBasic performs basic checks on a MsgSendPacket. +func (msg *MsgSendPacket) ValidateBasic() error { + if err := host.ChannelIdentifierValidator(msg.SourceChannel); err != nil { + return err + } + + if msg.TimeoutTimestamp == 0 { + return errorsmod.Wrap(channeltypesv1.ErrInvalidTimeout, "timeout must not be 0") + } + + if len(msg.PacketData) != 1 { + return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.PacketData)) + } + + for _, pd := range msg.PacketData { + if err := pd.ValidateBasic(); err != nil { + return err + } + } + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return nil +} + +// NewMsgRecvPacket creates a new MsgRecvPacket instance. +func NewMsgRecvPacket(packet Packet, proofCommitment []byte, proofHeight clienttypes.Height, signer string) *MsgRecvPacket { + return &MsgRecvPacket{ + Packet: packet, + ProofCommitment: proofCommitment, + ProofHeight: proofHeight, + Signer: signer, + } +} + +// ValidateBasic performs basic checks on a MsgRecvPacket. +func (msg *MsgRecvPacket) ValidateBasic() error { + if len(msg.ProofCommitment) == 0 { + return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "proof commitment can not be empty") + } + + _, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) + } + + return msg.Packet.ValidateBasic() +} + +// NewMsgAcknowledgement creates a new MsgAcknowledgement instance +func NewMsgAcknowledgement(packet Packet, acknowledgement Acknowledgement, proofAcked []byte, proofHeight clienttypes.Height, signer string) *MsgAcknowledgement { + return &MsgAcknowledgement{ + Packet: packet, + Acknowledgement: acknowledgement, + ProofAcked: proofAcked, + ProofHeight: proofHeight, + Signer: signer, + } +} + +// NewMsgTimeout creates a new MsgTimeout instance +func NewMsgTimeout(packet Packet, proofUnreceived []byte, proofHeight clienttypes.Height, signer string) *MsgTimeout { + return &MsgTimeout{ + Packet: packet, + ProofUnreceived: proofUnreceived, + ProofHeight: proofHeight, + Signer: signer, + } +} diff --git a/modules/core/04-channel/v2/types/msgs_test.go b/modules/core/04-channel/v2/types/msgs_test.go new file mode 100644 index 00000000000..1cebdd19647 --- /dev/null +++ b/modules/core/04-channel/v2/types/msgs_test.go @@ -0,0 +1,270 @@ +package types_test + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/suite" + + channeltypesv1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + mockv2 "github.com/cosmos/ibc-go/v9/testing/mock/v2" +) + +var testProof = []byte("test") + +type TypesTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain +} + +func (s *TypesTestSuite) SetupTest() { + s.coordinator = ibctesting.NewCoordinator(s.T(), 2) + s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) + s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) +} + +func TestTypesTestSuite(t *testing.T) { + suite.Run(t, new(TypesTestSuite)) +} + +// TestMsgProvideCounterpartyValidateBasic tests ValidateBasic for MsgProvideCounterparty +func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() { + var msg *types.MsgProvideCounterparty + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: invalid signer address", + func() { + msg.Signer = "invalid" + }, + ibcerrors.ErrInvalidAddress, + }, + { + "failure: invalid channel ID", + func() { + msg.ChannelId = "" + }, + host.ErrInvalidID, + }, + { + "failure: invalid counterparty channel ID", + func() { + msg.CounterpartyChannelId = "" + }, + host.ErrInvalidID, + }, + } + + for _, tc := range testCases { + msg = types.NewMsgProvideCounterparty( + ibctesting.FirstChannelID, + ibctesting.SecondChannelID, + ibctesting.TestAccAddress, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err, "valid case %s failed", tc.name) + } else { + s.Require().ErrorIs(err, tc.expError, "invalid case %s passed", tc.name) + } + } +} + +// TestMsgCreateChannelValidateBasic tests ValidateBasic for MsgCreateChannel +func (s *TypesTestSuite) TestMsgCreateChannelValidateBasic() { + var msg *types.MsgCreateChannel + + testCases := []struct { + name string + malleate func() + expError error + }{ + { + "success", + func() {}, + nil, + }, + { + "failure: invalid signer address", + func() { + msg.Signer = "invalid" + }, + ibcerrors.ErrInvalidAddress, + }, + { + "failure: invalid client ID", + func() { + msg.ClientId = "" + }, + host.ErrInvalidID, + }, + { + "failure: empty key path", + func() { + msg.MerklePathPrefix.KeyPath = nil + }, + errors.New("path cannot have length 0"), + }, + } + + for _, tc := range testCases { + msg = types.NewMsgCreateChannel( + ibctesting.FirstClientID, + commitmenttypes.NewMerklePath([]byte("key")), + ibctesting.TestAccAddress, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err, "valid case %s failed", tc.name) + } else { + s.Require().ErrorContains(err, tc.expError.Error(), "invalid case %s passed", tc.name) + } + } +} + +func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() { + var msg *types.MsgSendPacket + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid source channel", + malleate: func() { + msg.SourceChannel = "" + }, + expError: host.ErrInvalidID, + }, + { + name: "failure: invalid timestamp", + malleate: func() { + msg.TimeoutTimestamp = 0 + }, + expError: channeltypesv1.ErrInvalidTimeout, + }, + { + name: "failure: invalid length for packetdata", + malleate: func() { + msg.PacketData = []types.PacketData{} + }, + expError: types.ErrInvalidPacketData, + }, + { + name: "failure: invalid packetdata", + malleate: func() { + msg.PacketData[0].DestinationPort = "" + }, + expError: host.ErrInvalidID, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + msg = types.NewMsgSendPacket( + ibctesting.FirstChannelID, s.chainA.GetTimeoutTimestamp(), + s.chainA.SenderAccount.GetAddress().String(), + types.PacketData{SourcePort: ibctesting.MockPort, DestinationPort: ibctesting.MockPort, Payload: types.NewPayload("ics20-1", "json", ibctesting.MockPacketData)}, + ) + + tc.malleate() + + err := msg.ValidateBasic() + expPass := tc.expError == nil + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} + +func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() { + var msg *types.MsgRecvPacket + testCases := []struct { + name string + malleate func() + expError error + }{ + { + name: "success", + malleate: func() {}, + }, + { + name: "failure: invalid packet", + malleate: func() { + msg.Packet.Data = []types.PacketData{} + }, + expError: types.ErrInvalidPacket, + }, + { + name: "failure: invalid proof commitment", + malleate: func() { + msg.ProofCommitment = []byte{} + }, + expError: commitmenttypes.ErrInvalidProof, + }, + { + name: "failure: invalid signer", + malleate: func() { + msg.Signer = "" + }, + expError: ibcerrors.ErrInvalidAddress, + }, + } + for _, tc := range testCases { + s.Run(tc.name, func() { + packet := types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, s.chainA.GetTimeoutTimestamp(), mockv2.NewMockPacketData(mockv2.ModuleNameA, mockv2.ModuleNameB)) + + msg = types.NewMsgRecvPacket(packet, testProof, s.chainA.GetTimeoutHeight(), s.chainA.SenderAccount.GetAddress().String()) + + tc.malleate() + + err := msg.ValidateBasic() + + expPass := tc.expError == nil + + if expPass { + s.Require().NoError(err) + } else { + ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expError) + } + }) + } +} diff --git a/modules/core/04-channel/v2/types/packet.go b/modules/core/04-channel/v2/types/packet.go index 8d874072e76..787c95a459d 100644 --- a/modules/core/04-channel/v2/types/packet.go +++ b/modules/core/04-channel/v2/types/packet.go @@ -1,6 +1,7 @@ package types import ( + "math" "strings" "time" @@ -88,5 +89,9 @@ func (p Payload) Validate() error { // TimeoutTimestampToNanos takes seconds as a uint64 and returns Unix nanoseconds as uint64. func TimeoutTimestampToNanos(seconds uint64) uint64 { - return uint64(time.Unix(int64(seconds), 0).Unix()) + if seconds >= math.MaxInt64 { + + } + + return uint64(time.Unix(int64(seconds), 0).UnixNano()) } diff --git a/modules/core/04-channel/v2/types/packet_test.go b/modules/core/04-channel/v2/types/packet_test.go index aad8539edc1..4f908d54a90 100644 --- a/modules/core/04-channel/v2/types/packet_test.go +++ b/modules/core/04-channel/v2/types/packet_test.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/ibc-go/v9/testing/mock" ) -// TestValidate tests the Validate function of Packet +// TestValidate tests the Validate function of Payload func TestValidate(t *testing.T) { testCases := []struct { name string @@ -52,7 +52,7 @@ func TestValidate(t *testing.T) { } } -// TestValidateBasic tests the ValidateBasic functio of Packet +// TestValidateBasic tests the ValidateBasic function of Packet func TestValidateBasic(t *testing.T) { var packet types.Packet testCases := []struct { @@ -117,7 +117,7 @@ func TestValidateBasic(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - packet = types.NewPacket(1, ibctesting.FirstClientID, ibctesting.FirstClientID, uint64(time.Now().Unix()), types.PacketData{ + packet = types.NewPacket(1, ibctesting.FirstChannelID, ibctesting.SecondChannelID, uint64(time.Now().Unix()), types.PacketData{ SourcePort: ibctesting.MockPort, DestinationPort: ibctesting.MockPort, Payload: types.Payload{ diff --git a/modules/core/packet-server/types/query.pb.go b/modules/core/04-channel/v2/types/query.pb.go similarity index 83% rename from modules/core/packet-server/types/query.pb.go rename to modules/core/04-channel/v2/types/query.pb.go index 694ab5b79ba..04c4360c60d 100644 --- a/modules/core/packet-server/types/query.pb.go +++ b/modules/core/04-channel/v2/types/query.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/core/packetserver/v1/query.proto +// source: ibc/core/channel/v2/query.proto package types @@ -38,7 +38,7 @@ func (m *QueryChannelRequest) Reset() { *m = QueryChannelRequest{} } func (m *QueryChannelRequest) String() string { return proto.CompactTextString(m) } func (*QueryChannelRequest) ProtoMessage() {} func (*QueryChannelRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7ac0ae50eee8e6db, []int{0} + return fileDescriptor_a328cba4986edcab, []int{0} } func (m *QueryChannelRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -84,7 +84,7 @@ func (m *QueryChannelResponse) Reset() { *m = QueryChannelResponse{} } func (m *QueryChannelResponse) String() string { return proto.CompactTextString(m) } func (*QueryChannelResponse) ProtoMessage() {} func (*QueryChannelResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_7ac0ae50eee8e6db, []int{1} + return fileDescriptor_a328cba4986edcab, []int{1} } func (m *QueryChannelResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -128,38 +128,36 @@ func (m *QueryChannelResponse) GetChannel() Channel { } func init() { - proto.RegisterType((*QueryChannelRequest)(nil), "ibc.core.packetserver.v1.QueryChannelRequest") - proto.RegisterType((*QueryChannelResponse)(nil), "ibc.core.packetserver.v1.QueryChannelResponse") -} - -func init() { - proto.RegisterFile("ibc/core/packetserver/v1/query.proto", fileDescriptor_7ac0ae50eee8e6db) -} - -var fileDescriptor_7ac0ae50eee8e6db = []byte{ - // 351 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x4b, 0x03, 0x31, - 0x14, 0xc7, 0x2f, 0x45, 0x2d, 0x8d, 0x5b, 0xec, 0x70, 0x14, 0x3d, 0x6b, 0x11, 0xa9, 0x48, 0x13, - 0x5a, 0x5d, 0x04, 0x17, 0xeb, 0xe4, 0x68, 0x07, 0x07, 0x17, 0xb9, 0x4b, 0xc3, 0xf5, 0xb0, 0xbd, - 0x77, 0x4d, 0x72, 0x07, 0x45, 0x5c, 0xfc, 0x04, 0x82, 0xa3, 0xb3, 0xdf, 0xa5, 0x63, 0xc1, 0xc5, - 0x49, 0xa4, 0xf5, 0x83, 0xc8, 0xf5, 0xd2, 0x5a, 0xc1, 0x03, 0xb7, 0x97, 0x97, 0xff, 0xff, 0x97, - 0xf7, 0xf2, 0xc7, 0xfb, 0x81, 0xc7, 0x19, 0x07, 0x29, 0x58, 0xe4, 0xf2, 0x3b, 0xa1, 0x95, 0x90, - 0x89, 0x90, 0x2c, 0x69, 0xb2, 0x61, 0x2c, 0xe4, 0x88, 0x46, 0x12, 0x34, 0x10, 0x3b, 0xf0, 0x38, - 0x4d, 0x55, 0x74, 0x55, 0x45, 0x93, 0x66, 0xe5, 0x20, 0xd7, 0xcf, 0x7b, 0x6e, 0x18, 0x8a, 0x7e, - 0x46, 0xa8, 0x6c, 0xfb, 0x00, 0x7e, 0x5f, 0x30, 0x37, 0x0a, 0x98, 0x1b, 0x86, 0xa0, 0x5d, 0x1d, - 0x40, 0xa8, 0xcc, 0x6d, 0xd9, 0x07, 0x1f, 0xe6, 0x25, 0x4b, 0xab, 0xac, 0x5b, 0x3b, 0xc1, 0x5b, - 0x57, 0xe9, 0x10, 0x17, 0x19, 0xa9, 0x23, 0x86, 0xb1, 0x50, 0x9a, 0xec, 0x60, 0x6c, 0xd8, 0xb7, - 0x41, 0xd7, 0x46, 0x55, 0x54, 0x2f, 0x75, 0x4a, 0xa6, 0x73, 0xd9, 0xad, 0x29, 0x5c, 0xfe, 0xed, - 0x52, 0x11, 0x84, 0x4a, 0x10, 0x1b, 0x17, 0xb9, 0x14, 0xae, 0x06, 0x69, 0x3c, 0x8b, 0x23, 0x39, - 0xc7, 0x45, 0x63, 0xb7, 0x0b, 0x55, 0x54, 0xdf, 0x6c, 0xed, 0xd1, 0xbc, 0x7d, 0xa9, 0xa1, 0xb6, - 0xd7, 0xc6, 0x1f, 0xbb, 0x56, 0x67, 0xe1, 0x6b, 0xbd, 0x22, 0xbc, 0x3e, 0x7f, 0x95, 0xbc, 0x20, - 0x5c, 0x34, 0x22, 0xd2, 0xc8, 0xe7, 0xfc, 0xb1, 0x58, 0x85, 0xfe, 0x57, 0x9e, 0x6d, 0x54, 0x6b, - 0x3e, 0xbe, 0x7d, 0x3d, 0x17, 0x8e, 0xc8, 0x21, 0x5b, 0x86, 0x60, 0xe6, 0x61, 0x49, 0x6b, 0x59, - 0xde, 0xff, 0x7c, 0xd6, 0x43, 0xfb, 0x7a, 0x3c, 0x75, 0xd0, 0x64, 0xea, 0xa0, 0xcf, 0xa9, 0x83, - 0x9e, 0x66, 0x8e, 0x35, 0x99, 0x39, 0xd6, 0xfb, 0xcc, 0xb1, 0x6e, 0xce, 0xfc, 0x40, 0xf7, 0x62, - 0x8f, 0x72, 0x18, 0x30, 0x0e, 0x6a, 0x00, 0x2a, 0xa5, 0x36, 0x7c, 0x60, 0xc9, 0x29, 0x1b, 0x40, - 0x37, 0xee, 0x0b, 0xb5, 0x1a, 0x74, 0xc3, 0x24, 0xad, 0x47, 0x91, 0x50, 0xde, 0xc6, 0x3c, 0xb1, - 0xe3, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5b, 0xe3, 0xea, 0xfa, 0x4f, 0x02, 0x00, 0x00, + proto.RegisterType((*QueryChannelRequest)(nil), "ibc.core.channel.v2.QueryChannelRequest") + proto.RegisterType((*QueryChannelResponse)(nil), "ibc.core.channel.v2.QueryChannelResponse") +} + +func init() { proto.RegisterFile("ibc/core/channel/v2/query.proto", fileDescriptor_a328cba4986edcab) } + +var fileDescriptor_a328cba4986edcab = []byte{ + // 339 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcf, 0x4c, 0x4a, 0xd6, + 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0x48, 0xcc, 0xcb, 0x4b, 0xcd, 0xd1, 0x2f, 0x33, 0xd2, + 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0xce, 0x4c, 0x4a, + 0xd6, 0x03, 0x29, 0xd0, 0x83, 0x2a, 0xd0, 0x2b, 0x33, 0x92, 0x52, 0xc4, 0xa6, 0x0b, 0x26, 0x0f, + 0xd6, 0x27, 0x25, 0x93, 0x9e, 0x9f, 0x9f, 0x9e, 0x93, 0xaa, 0x9f, 0x58, 0x90, 0xa9, 0x9f, 0x98, + 0x97, 0x97, 0x5f, 0x92, 0x58, 0x92, 0x99, 0x9f, 0x57, 0x0c, 0x95, 0x15, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0x33, 0xf5, 0x41, 0x2c, 0x88, 0xa8, 0x92, 0x09, 0x97, 0x70, 0x20, 0xc8, 0x6a, 0x67, 0x88, + 0x49, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0xb2, 0x5c, 0x5c, 0x50, 0xb3, 0xe3, 0x33, + 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x38, 0xa1, 0x22, 0x9e, 0x29, 0x4a, 0x79, 0x5c, + 0x22, 0xa8, 0xba, 0x8a, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0x24, 0xb8, 0xd8, 0x93, 0x8b, 0x52, + 0x13, 0x4b, 0xf2, 0x8b, 0xa0, 0x7a, 0x60, 0x5c, 0x21, 0x1b, 0x2e, 0x76, 0xa8, 0x76, 0x09, 0x26, + 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x19, 0x3d, 0x2c, 0xbe, 0xd4, 0x83, 0x1a, 0xe8, 0xc4, 0x72, 0xe2, + 0x9e, 0x3c, 0x43, 0x10, 0x4c, 0x8b, 0xd1, 0x6c, 0x46, 0x2e, 0x56, 0xb0, 0x85, 0x42, 0x13, 0x19, + 0xb9, 0xd8, 0xa1, 0x8a, 0x84, 0x34, 0xb0, 0x1a, 0x81, 0xc5, 0x3b, 0x52, 0x9a, 0x44, 0xa8, 0x84, + 0x78, 0x41, 0xc9, 0xb0, 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0xda, 0x42, 0x9a, 0xfa, 0x78, 0x02, 0x5c, + 0xbf, 0x1a, 0x11, 0x3a, 0xb5, 0x4e, 0x61, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, + 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, + 0x10, 0x65, 0x93, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9c, 0x5f, + 0x9c, 0x9b, 0x5f, 0x0c, 0x32, 0x55, 0x37, 0x3d, 0x5f, 0xbf, 0xcc, 0x52, 0x3f, 0x37, 0x3f, 0xa5, + 0x34, 0x27, 0xb5, 0x18, 0x62, 0x87, 0x81, 0x89, 0x2e, 0x92, 0x35, 0x25, 0x95, 0x05, 0xa9, 0xc5, + 0x49, 0x6c, 0xe0, 0x28, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x69, 0x95, 0xfc, 0x31, + 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -188,7 +186,7 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) Channel(ctx context.Context, in *QueryChannelRequest, opts ...grpc.CallOption) (*QueryChannelResponse, error) { out := new(QueryChannelResponse) - err := c.cc.Invoke(ctx, "/ibc.core.packetserver.v1.Query/Channel", in, out, opts...) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Query/Channel", in, out, opts...) if err != nil { return nil, err } @@ -223,7 +221,7 @@ func _Query_Channel_Handler(srv interface{}, ctx context.Context, dec func(inter } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/ibc.core.packetserver.v1.Query/Channel", + FullMethod: "/ibc.core.channel.v2.Query/Channel", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Channel(ctx, req.(*QueryChannelRequest)) @@ -232,7 +230,7 @@ func _Query_Channel_Handler(srv interface{}, ctx context.Context, dec func(inter } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "ibc.core.packetserver.v1.Query", + ServiceName: "ibc.core.channel.v2.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -241,7 +239,7 @@ var _Query_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "ibc/core/packetserver/v1/query.proto", + Metadata: "ibc/core/channel/v2/query.proto", } func (m *QueryChannelRequest) Marshal() (dAtA []byte, err error) { diff --git a/modules/core/packet-server/types/query.pb.gw.go b/modules/core/04-channel/v2/types/query.pb.gw.go similarity index 99% rename from modules/core/packet-server/types/query.pb.gw.go rename to modules/core/04-channel/v2/types/query.pb.gw.go index caea72e9575..6ed5d7819e6 100644 --- a/modules/core/packet-server/types/query.pb.gw.go +++ b/modules/core/04-channel/v2/types/query.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: ibc/core/packetserver/v1/query.proto +// source: ibc/core/channel/v2/query.proto /* Package types is a reverse proxy. diff --git a/modules/core/04-channel/v2/types/tx.pb.go b/modules/core/04-channel/v2/types/tx.pb.go index 0532c9c4c4a..07d85dccd6c 100644 --- a/modules/core/04-channel/v2/types/tx.pb.go +++ b/modules/core/04-channel/v2/types/tx.pb.go @@ -12,6 +12,7 @@ import ( proto "github.com/cosmos/gogoproto/proto" types "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" types1 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -31,6 +32,169 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgCreateChannel defines the message used to create a v2 Channel. +type MsgCreateChannel 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 key path used to store packet flow messages that the counterparty + // will use to send to us. + MerklePathPrefix v2.MerklePath `protobuf:"bytes,2,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` + // signer address + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgCreateChannel) Reset() { *m = MsgCreateChannel{} } +func (m *MsgCreateChannel) String() string { return proto.CompactTextString(m) } +func (*MsgCreateChannel) ProtoMessage() {} +func (*MsgCreateChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{0} +} +func (m *MsgCreateChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateChannel.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 *MsgCreateChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateChannel.Merge(m, src) +} +func (m *MsgCreateChannel) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateChannel) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateChannel proto.InternalMessageInfo + +// MsgCreateChannelResponse defines the Msg/CreateChannel response type. +type MsgCreateChannelResponse struct { + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *MsgCreateChannelResponse) Reset() { *m = MsgCreateChannelResponse{} } +func (m *MsgCreateChannelResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateChannelResponse) ProtoMessage() {} +func (*MsgCreateChannelResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{1} +} +func (m *MsgCreateChannelResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateChannelResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateChannelResponse.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 *MsgCreateChannelResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateChannelResponse.Merge(m, src) +} +func (m *MsgCreateChannelResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateChannelResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateChannelResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateChannelResponse proto.InternalMessageInfo + +// MsgProvideCounterparty defines the message used to provide the counterparty channel +// identifier. +type MsgProvideCounterparty struct { + // unique identifier we will use to write all packet messages sent to counterparty + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + // counterparty channel identifier + CounterpartyChannelId string `protobuf:"bytes,2,opt,name=counterparty_channel_id,json=counterpartyChannelId,proto3" json:"counterparty_channel_id,omitempty"` + // signer address + Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgProvideCounterparty) Reset() { *m = MsgProvideCounterparty{} } +func (m *MsgProvideCounterparty) String() string { return proto.CompactTextString(m) } +func (*MsgProvideCounterparty) ProtoMessage() {} +func (*MsgProvideCounterparty) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{2} +} +func (m *MsgProvideCounterparty) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgProvideCounterparty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgProvideCounterparty.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 *MsgProvideCounterparty) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgProvideCounterparty.Merge(m, src) +} +func (m *MsgProvideCounterparty) XXX_Size() int { + return m.Size() +} +func (m *MsgProvideCounterparty) XXX_DiscardUnknown() { + xxx_messageInfo_MsgProvideCounterparty.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgProvideCounterparty proto.InternalMessageInfo + +// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. +type MsgProvideCounterpartyResponse struct { +} + +func (m *MsgProvideCounterpartyResponse) Reset() { *m = MsgProvideCounterpartyResponse{} } +func (m *MsgProvideCounterpartyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgProvideCounterpartyResponse) ProtoMessage() {} +func (*MsgProvideCounterpartyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d421c7119e969b99, []int{3} +} +func (m *MsgProvideCounterpartyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgProvideCounterpartyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgProvideCounterpartyResponse.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 *MsgProvideCounterpartyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgProvideCounterpartyResponse.Merge(m, src) +} +func (m *MsgProvideCounterpartyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgProvideCounterpartyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgProvideCounterpartyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgProvideCounterpartyResponse proto.InternalMessageInfo + // MsgSendPacket sends an outgoing IBC packet. type MsgSendPacket struct { SourceChannel string `protobuf:"bytes,1,opt,name=source_channel,json=sourceChannel,proto3" json:"source_channel,omitempty"` @@ -43,7 +207,7 @@ func (m *MsgSendPacket) Reset() { *m = MsgSendPacket{} } func (m *MsgSendPacket) String() string { return proto.CompactTextString(m) } func (*MsgSendPacket) ProtoMessage() {} func (*MsgSendPacket) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{0} + return fileDescriptor_d421c7119e969b99, []int{4} } func (m *MsgSendPacket) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -81,7 +245,7 @@ func (m *MsgSendPacketResponse) Reset() { *m = MsgSendPacketResponse{} } func (m *MsgSendPacketResponse) String() string { return proto.CompactTextString(m) } func (*MsgSendPacketResponse) ProtoMessage() {} func (*MsgSendPacketResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{1} + return fileDescriptor_d421c7119e969b99, []int{5} } func (m *MsgSendPacketResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -122,7 +286,7 @@ func (m *MsgRecvPacket) Reset() { *m = MsgRecvPacket{} } func (m *MsgRecvPacket) String() string { return proto.CompactTextString(m) } func (*MsgRecvPacket) ProtoMessage() {} func (*MsgRecvPacket) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{2} + return fileDescriptor_d421c7119e969b99, []int{6} } func (m *MsgRecvPacket) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -160,7 +324,7 @@ func (m *MsgRecvPacketResponse) Reset() { *m = MsgRecvPacketResponse{} } func (m *MsgRecvPacketResponse) String() string { return proto.CompactTextString(m) } func (*MsgRecvPacketResponse) ProtoMessage() {} func (*MsgRecvPacketResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{3} + return fileDescriptor_d421c7119e969b99, []int{7} } func (m *MsgRecvPacketResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -191,18 +355,17 @@ var xxx_messageInfo_MsgRecvPacketResponse proto.InternalMessageInfo // MsgTimeout receives timed-out packet type MsgTimeout struct { - Packet Packet `protobuf:"bytes,1,opt,name=packet,proto3" json:"packet"` - ProofUnreceived []byte `protobuf:"bytes,2,opt,name=proof_unreceived,json=proofUnreceived,proto3" json:"proof_unreceived,omitempty"` - ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` - NextSequenceRecv uint64 `protobuf:"varint,4,opt,name=next_sequence_recv,json=nextSequenceRecv,proto3" json:"next_sequence_recv,omitempty"` - Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty"` + Packet Packet `protobuf:"bytes,1,opt,name=packet,proto3" json:"packet"` + ProofUnreceived []byte `protobuf:"bytes,2,opt,name=proof_unreceived,json=proofUnreceived,proto3" json:"proof_unreceived,omitempty"` + ProofHeight types.Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` + Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty"` } func (m *MsgTimeout) Reset() { *m = MsgTimeout{} } func (m *MsgTimeout) String() string { return proto.CompactTextString(m) } func (*MsgTimeout) ProtoMessage() {} func (*MsgTimeout) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{4} + return fileDescriptor_d421c7119e969b99, []int{8} } func (m *MsgTimeout) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -240,7 +403,7 @@ func (m *MsgTimeoutResponse) Reset() { *m = MsgTimeoutResponse{} } func (m *MsgTimeoutResponse) String() string { return proto.CompactTextString(m) } func (*MsgTimeoutResponse) ProtoMessage() {} func (*MsgTimeoutResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{5} + return fileDescriptor_d421c7119e969b99, []int{9} } func (m *MsgTimeoutResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -282,7 +445,7 @@ func (m *MsgAcknowledgement) Reset() { *m = MsgAcknowledgement{} } func (m *MsgAcknowledgement) String() string { return proto.CompactTextString(m) } func (*MsgAcknowledgement) ProtoMessage() {} func (*MsgAcknowledgement) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{6} + return fileDescriptor_d421c7119e969b99, []int{10} } func (m *MsgAcknowledgement) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -320,7 +483,7 @@ func (m *MsgAcknowledgementResponse) Reset() { *m = MsgAcknowledgementRe func (m *MsgAcknowledgementResponse) String() string { return proto.CompactTextString(m) } func (*MsgAcknowledgementResponse) ProtoMessage() {} func (*MsgAcknowledgementResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d421c7119e969b99, []int{7} + return fileDescriptor_d421c7119e969b99, []int{11} } func (m *MsgAcknowledgementResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -350,6 +513,10 @@ func (m *MsgAcknowledgementResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgAcknowledgementResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgCreateChannel)(nil), "ibc.core.channel.v2.MsgCreateChannel") + proto.RegisterType((*MsgCreateChannelResponse)(nil), "ibc.core.channel.v2.MsgCreateChannelResponse") + proto.RegisterType((*MsgProvideCounterparty)(nil), "ibc.core.channel.v2.MsgProvideCounterparty") + proto.RegisterType((*MsgProvideCounterpartyResponse)(nil), "ibc.core.channel.v2.MsgProvideCounterpartyResponse") proto.RegisterType((*MsgSendPacket)(nil), "ibc.core.channel.v2.MsgSendPacket") proto.RegisterType((*MsgSendPacketResponse)(nil), "ibc.core.channel.v2.MsgSendPacketResponse") proto.RegisterType((*MsgRecvPacket)(nil), "ibc.core.channel.v2.MsgRecvPacket") @@ -363,53 +530,63 @@ func init() { func init() { proto.RegisterFile("ibc/core/channel/v2/tx.proto", fileDescriptor_d421c7119e969b99) } var fileDescriptor_d421c7119e969b99 = []byte{ - // 724 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4d, 0x6f, 0xd3, 0x30, - 0x18, 0xc7, 0x9b, 0xb5, 0x2b, 0xf0, 0x74, 0x5b, 0x47, 0x78, 0xab, 0x02, 0x6a, 0xab, 0x0a, 0xb4, - 0x31, 0x58, 0x42, 0x0b, 0x97, 0x4d, 0x48, 0x68, 0x1b, 0x42, 0x5c, 0x26, 0xa1, 0xac, 0x70, 0x80, - 0x89, 0x2a, 0x75, 0x4d, 0x1a, 0xad, 0x89, 0x43, 0xec, 0x86, 0xed, 0x86, 0x38, 0x21, 0x0e, 0x88, - 0x8f, 0xc0, 0x47, 0xd8, 0x81, 0x0f, 0xb1, 0xe3, 0x0e, 0x1c, 0x38, 0x21, 0xb4, 0x1e, 0xf6, 0x35, - 0x50, 0x6c, 0x37, 0x7d, 0x59, 0xbb, 0x4d, 0x5a, 0x4f, 0x49, 0x9e, 0xe7, 0xef, 0xff, 0xf3, 0xf8, - 0x67, 0xc7, 0x86, 0x3b, 0x4e, 0x1d, 0x19, 0x88, 0x04, 0xd8, 0x40, 0x4d, 0xcb, 0xf3, 0x70, 0xcb, - 0x08, 0x2b, 0x06, 0xdb, 0xd5, 0xfd, 0x80, 0x30, 0xa2, 0x5e, 0x73, 0xea, 0x48, 0x8f, 0xb2, 0xba, - 0xcc, 0xea, 0x61, 0x45, 0xbb, 0x6e, 0x13, 0x9b, 0xf0, 0xbc, 0x11, 0xbd, 0x09, 0xa9, 0x76, 0x0b, - 0x11, 0xea, 0x12, 0x6a, 0xb8, 0xd4, 0x36, 0xc2, 0x72, 0xf4, 0x90, 0x89, 0xe2, 0xa8, 0x0a, 0xbe, - 0x85, 0x76, 0x30, 0x93, 0x8a, 0x11, 0x3d, 0x94, 0xe3, 0x1e, 0xb4, 0x42, 0x2f, 0xdb, 0x72, 0xb0, - 0xc7, 0xa2, 0xa4, 0x78, 0x13, 0x82, 0xd2, 0x6f, 0x05, 0x66, 0x37, 0xa9, 0xbd, 0x85, 0xbd, 0xc6, - 0x2b, 0x6e, 0xab, 0xde, 0x83, 0x39, 0x4a, 0xda, 0x01, 0xc2, 0x35, 0x69, 0x98, 0x53, 0x8a, 0xca, - 0xe2, 0x15, 0x73, 0x56, 0x44, 0x37, 0x44, 0x50, 0x7d, 0x00, 0x57, 0x99, 0xe3, 0x62, 0xd2, 0x66, - 0xb5, 0xe8, 0x49, 0x99, 0xe5, 0xfa, 0xb9, 0xa9, 0xa2, 0xb2, 0x98, 0x32, 0xe7, 0x65, 0xa2, 0xda, - 0x8d, 0xab, 0x2f, 0x20, 0x23, 0x9a, 0xae, 0x35, 0x2c, 0x66, 0xe5, 0x92, 0xc5, 0xe4, 0x62, 0xa6, - 0x52, 0xd0, 0x47, 0x00, 0xd2, 0x45, 0x17, 0xcf, 0x2d, 0x66, 0xad, 0xa7, 0x0e, 0xfe, 0x16, 0x12, - 0x26, 0xf8, 0x71, 0x44, 0xbd, 0x09, 0x69, 0xea, 0xd8, 0x1e, 0x0e, 0x72, 0x29, 0xde, 0x93, 0xfc, - 0x5a, 0xcd, 0x7e, 0xfd, 0x59, 0x48, 0x7c, 0x39, 0xde, 0x5f, 0x92, 0x81, 0xd2, 0x0a, 0xdc, 0x18, - 0x98, 0x95, 0x89, 0xa9, 0x4f, 0x3c, 0x8a, 0x55, 0x0d, 0x2e, 0x53, 0xfc, 0xb1, 0x8d, 0x3d, 0x84, - 0xf9, 0xbc, 0x52, 0x66, 0xfc, 0xbd, 0x9a, 0x8a, 0x5c, 0x4a, 0x1d, 0x41, 0xc4, 0xc4, 0x28, 0x94, - 0x44, 0x56, 0x20, 0x2d, 0x7a, 0xe0, 0x23, 0x32, 0x95, 0xdb, 0xa7, 0x34, 0x2e, 0x9b, 0x96, 0x03, - 0xd4, 0xfb, 0x30, 0xef, 0x07, 0x84, 0x7c, 0xa8, 0x21, 0xe2, 0xba, 0x0e, 0x73, 0xb1, 0xc7, 0x38, - 0xa4, 0x19, 0x33, 0xcb, 0xe3, 0x1b, 0x71, 0x58, 0xdd, 0x80, 0x19, 0x21, 0x6d, 0x62, 0xc7, 0x6e, - 0xb2, 0x5c, 0x92, 0xd7, 0xd2, 0xfa, 0x6a, 0x89, 0x75, 0x0b, 0xcb, 0xfa, 0x4b, 0xae, 0x90, 0xa5, - 0x32, 0x7c, 0x94, 0x08, 0x9d, 0x1f, 0xd0, 0x7b, 0x0e, 0xa8, 0x37, 0xc9, 0x18, 0xd0, 0x33, 0x48, - 0x07, 0x98, 0xb6, 0x5b, 0x62, 0xb2, 0x73, 0x95, 0x85, 0x11, 0x93, 0x2d, 0xeb, 0x5d, 0xb9, 0xc9, - 0xa5, 0xd5, 0x3d, 0x1f, 0x9b, 0x72, 0x98, 0xa4, 0xf8, 0x7d, 0x0a, 0x60, 0x93, 0xda, 0x55, 0xb1, - 0x13, 0x26, 0x82, 0xb0, 0xed, 0x05, 0x18, 0x61, 0x27, 0xc4, 0x8d, 0x01, 0x84, 0xaf, 0xe3, 0xf0, - 0x64, 0x10, 0x3e, 0x04, 0xd5, 0xc3, 0xbb, 0xac, 0xd6, 0xdd, 0x16, 0xb5, 0x00, 0xa3, 0x90, 0xe3, - 0x4c, 0x99, 0xf3, 0x51, 0x66, 0x4b, 0x26, 0x22, 0x78, 0x7d, 0xc0, 0xa7, 0x4f, 0x07, 0xfe, 0x0e, - 0xd4, 0x1e, 0x8f, 0x49, 0xd3, 0xfe, 0x35, 0xc5, 0xdd, 0xd7, 0xd0, 0x8e, 0x47, 0x3e, 0xb5, 0x70, - 0xc3, 0xc6, 0x7c, 0x4b, 0x5d, 0x80, 0x7a, 0x15, 0xb2, 0xd6, 0xa0, 0x1b, 0x87, 0x9e, 0xa9, 0xdc, - 0x1d, 0xe9, 0x31, 0x54, 0x59, 0x9a, 0x0d, 0x5b, 0xa8, 0x05, 0x10, 0xa8, 0x6b, 0x51, 0x91, 0x06, - 0x5f, 0x9f, 0x19, 0x13, 0x78, 0x68, 0x2d, 0x8a, 0x9c, 0x58, 0xc1, 0xd4, 0xc5, 0x7e, 0x82, 0x33, - 0xd6, 0x04, 0x81, 0x76, 0x92, 0xda, 0x84, 0xd7, 0xa6, 0xf2, 0x2d, 0x09, 0xc9, 0x4d, 0x6a, 0xab, - 0xdb, 0x00, 0x7d, 0xa7, 0x6c, 0x69, 0x24, 0xc6, 0x81, 0x33, 0x4b, 0x5b, 0x3a, 0x5b, 0x13, 0x37, - 0xbb, 0x0d, 0xd0, 0x77, 0x62, 0x8d, 0x75, 0xef, 0x69, 0xc6, 0xbb, 0x8f, 0x38, 0x14, 0xb6, 0xe0, - 0x52, 0xf7, 0x4f, 0x2e, 0x8c, 0x1b, 0x26, 0x05, 0xda, 0xc2, 0x19, 0x82, 0xd8, 0x74, 0x07, 0xb2, - 0xc3, 0x1b, 0x76, 0xec, 0xd8, 0x21, 0xa1, 0x66, 0x9c, 0x53, 0xd8, 0x2d, 0xa6, 0x4d, 0x7f, 0x3e, - 0xde, 0x5f, 0x52, 0xd6, 0xdf, 0x1c, 0x1c, 0xe5, 0x95, 0xc3, 0xa3, 0xbc, 0xf2, 0xef, 0x28, 0xaf, - 0xfc, 0xe8, 0xe4, 0x13, 0x87, 0x9d, 0x7c, 0xe2, 0x4f, 0x27, 0x9f, 0x78, 0xfb, 0xd4, 0x76, 0x58, - 0xb3, 0x5d, 0xd7, 0x11, 0x71, 0x0d, 0x79, 0x1b, 0x3b, 0x75, 0xb4, 0x6c, 0x13, 0x23, 0x5c, 0x31, - 0x5c, 0xd2, 0x68, 0xb7, 0x30, 0x15, 0x37, 0xe9, 0xa3, 0x27, 0xcb, 0xfd, 0xd7, 0xfd, 0x9e, 0x8f, - 0x69, 0x3d, 0xcd, 0x6f, 0xd3, 0xc7, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x8c, 0xff, 0x15, - 0x12, 0x08, 0x00, 0x00, + // 885 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x41, 0x6f, 0xdc, 0x44, + 0x14, 0x5e, 0x27, 0xdb, 0xd0, 0xbc, 0x4d, 0x9a, 0xe0, 0xd2, 0x76, 0xe5, 0xc2, 0xee, 0x6a, 0x45, + 0x95, 0x90, 0x2a, 0x36, 0x71, 0x11, 0x52, 0x2a, 0xa4, 0xaa, 0x5d, 0x84, 0xe8, 0x61, 0xa5, 0xc8, + 0x0d, 0x3d, 0x00, 0xc2, 0xf2, 0xda, 0xaf, 0x5e, 0x2b, 0x6b, 0x8f, 0xf1, 0x8c, 0xdd, 0xe6, 0x86, + 0x38, 0x71, 0xe4, 0xc8, 0x91, 0x9f, 0x90, 0x03, 0x3f, 0xa2, 0xc7, 0x1e, 0x38, 0x70, 0x42, 0x55, + 0x72, 0xa8, 0xc4, 0xaf, 0x40, 0x9e, 0x99, 0xb5, 0x9d, 0xad, 0x37, 0x09, 0x22, 0x3d, 0xd9, 0x7e, + 0xef, 0x7b, 0xdf, 0x7b, 0xef, 0x7b, 0xe3, 0x99, 0x81, 0x0f, 0x83, 0x91, 0x6b, 0xb8, 0x24, 0x41, + 0xc3, 0x1d, 0x3b, 0x51, 0x84, 0x13, 0x23, 0x33, 0x0d, 0xf6, 0x42, 0x8f, 0x13, 0xc2, 0x88, 0x7a, + 0x3d, 0x18, 0xb9, 0x7a, 0xee, 0xd5, 0xa5, 0x57, 0xcf, 0x4c, 0xed, 0x03, 0x9f, 0xf8, 0x84, 0xfb, + 0x8d, 0xfc, 0x4d, 0x40, 0xb5, 0x5b, 0x2e, 0xa1, 0x21, 0xa1, 0x46, 0x48, 0x7d, 0x23, 0xdb, 0xc9, + 0x1f, 0xd2, 0xd1, 0xab, 0xcb, 0x10, 0x3b, 0xee, 0x01, 0x32, 0x89, 0xa8, 0xa9, 0x61, 0xa7, 0xa8, + 0x41, 0xeb, 0x96, 0xde, 0x49, 0x80, 0x11, 0xcb, 0x9d, 0xe2, 0x4d, 0x02, 0x36, 0x4a, 0x00, 0x09, + 0xc3, 0x80, 0x85, 0x1c, 0x64, 0x56, 0xbe, 0x04, 0xb0, 0x7f, 0xa4, 0xc0, 0xfa, 0x90, 0xfa, 0x83, + 0x04, 0x1d, 0x86, 0x03, 0x91, 0x4a, 0xbd, 0x0d, 0xcb, 0x82, 0xcd, 0x0e, 0xbc, 0xb6, 0xd2, 0x53, + 0x36, 0x97, 0xad, 0xab, 0xc2, 0xf0, 0xd8, 0x53, 0x9f, 0x82, 0x1a, 0x62, 0x72, 0x30, 0x41, 0x3b, + 0x76, 0xd8, 0xd8, 0x8e, 0x13, 0x7c, 0x16, 0xbc, 0x68, 0x2f, 0xf4, 0x94, 0xcd, 0x96, 0xd9, 0xd7, + 0x4b, 0x71, 0xca, 0x4c, 0x99, 0xa9, 0x0f, 0x79, 0xc4, 0x9e, 0xc3, 0xc6, 0x8f, 0x9a, 0x2f, 0xff, + 0xee, 0x36, 0xac, 0xf5, 0xb0, 0xb0, 0xec, 0x71, 0x06, 0xf5, 0x26, 0x2c, 0xd1, 0xc0, 0x8f, 0x30, + 0x69, 0x2f, 0xf2, 0x8c, 0xf2, 0xeb, 0xfe, 0xda, 0x2f, 0xbf, 0x77, 0x1b, 0x3f, 0xbf, 0x39, 0xda, + 0x92, 0x86, 0xfe, 0x03, 0x68, 0xcf, 0x56, 0x6c, 0x21, 0x8d, 0x49, 0x44, 0x51, 0xfd, 0x08, 0x40, + 0xea, 0x55, 0x96, 0xbe, 0x2c, 0x2d, 0x8f, 0xbd, 0xfb, 0xcd, 0x9c, 0xab, 0xff, 0x9b, 0x02, 0x37, + 0x87, 0xd4, 0xdf, 0x4b, 0x48, 0x16, 0x78, 0x38, 0x20, 0x69, 0xc4, 0x30, 0x89, 0x9d, 0x84, 0x1d, + 0x9e, 0x13, 0xaf, 0x7e, 0x0e, 0xb7, 0xdc, 0x0a, 0xdc, 0xae, 0x60, 0x17, 0x38, 0xf6, 0x46, 0xd5, + 0x3d, 0x28, 0xe2, 0x2e, 0xdc, 0x5b, 0x0f, 0x3a, 0xf5, 0x95, 0x4d, 0x3b, 0xec, 0xff, 0xa9, 0xc0, + 0xea, 0x90, 0xfa, 0x4f, 0x30, 0xf2, 0xf6, 0xf8, 0x82, 0x51, 0xef, 0xc0, 0x35, 0x4a, 0xd2, 0xc4, + 0xc5, 0x69, 0x39, 0xb2, 0xee, 0x55, 0x61, 0x9d, 0x0e, 0xf5, 0x2e, 0xbc, 0xcf, 0x82, 0x10, 0x49, + 0xca, 0xec, 0xfc, 0x49, 0x99, 0x13, 0xc6, 0xbc, 0xea, 0xa6, 0xb5, 0x2e, 0x1d, 0xfb, 0x53, 0xbb, + 0xfa, 0x15, 0xb4, 0xc4, 0x72, 0xb4, 0x3d, 0x87, 0x39, 0xed, 0xc5, 0xde, 0xe2, 0x66, 0xcb, 0xec, + 0xea, 0x35, 0x4b, 0x5f, 0x17, 0x55, 0x7c, 0xe9, 0x30, 0x47, 0x8e, 0x16, 0xe2, 0xc2, 0x52, 0x69, + 0xbc, 0x79, 0x76, 0xe3, 0xbb, 0x70, 0xe3, 0x54, 0x57, 0xc5, 0x44, 0x35, 0xb8, 0x4a, 0xf1, 0xc7, + 0x14, 0x23, 0x17, 0x79, 0x5f, 0x4d, 0xab, 0xf8, 0x96, 0xe3, 0x3c, 0x11, 0x8a, 0x58, 0xe8, 0x66, + 0x52, 0x91, 0x5d, 0x58, 0x12, 0x35, 0xf0, 0x88, 0x96, 0x79, 0xfb, 0x8c, 0xc2, 0x65, 0xd1, 0x32, + 0x40, 0xfd, 0x04, 0xd6, 0xe3, 0x84, 0x90, 0x67, 0x76, 0xb9, 0x7e, 0xb9, 0x48, 0x2b, 0xd6, 0x1a, + 0xb7, 0x0f, 0x0a, 0xb3, 0x3a, 0x80, 0x15, 0x01, 0x1d, 0x63, 0xe0, 0x8f, 0x19, 0x1f, 0x6d, 0xcb, + 0xd4, 0x2a, 0xb9, 0xc4, 0x1f, 0x99, 0xed, 0xe8, 0x5f, 0x73, 0x84, 0x4c, 0xd5, 0xe2, 0x51, 0xc2, + 0x74, 0x71, 0x81, 0x7e, 0xe0, 0x02, 0x95, 0x4d, 0x16, 0x02, 0x3d, 0x80, 0xa5, 0x04, 0x69, 0x3a, + 0x11, 0xcd, 0x5e, 0x33, 0x37, 0x6a, 0x9a, 0xdd, 0xd1, 0xa7, 0x70, 0x8b, 0x43, 0xf7, 0x0f, 0x63, + 0xb4, 0x64, 0x98, 0x54, 0xf1, 0xb5, 0x02, 0x30, 0xa4, 0xfe, 0xbe, 0x58, 0x09, 0x97, 0x22, 0x61, + 0x1a, 0x25, 0xe8, 0x62, 0x90, 0xa1, 0x77, 0x4a, 0xc2, 0x6f, 0x0a, 0xf3, 0x65, 0x4b, 0x78, 0xe5, + 0x6c, 0x09, 0xbf, 0x03, 0xb5, 0xec, 0xf0, 0xb2, 0xf5, 0xfb, 0x63, 0x81, 0xb3, 0x3f, 0x74, 0x0f, + 0x22, 0xf2, 0x7c, 0x82, 0x9e, 0x8f, 0x7c, 0x91, 0xfc, 0x0f, 0x1d, 0xf7, 0x61, 0xcd, 0x39, 0xcd, + 0x26, 0x77, 0xd9, 0x8f, 0x6b, 0x39, 0x66, 0x32, 0x4b, 0xb2, 0x59, 0x0a, 0xb5, 0x0b, 0x42, 0x3c, + 0x3b, 0x4f, 0xe2, 0x71, 0xc5, 0x57, 0x2c, 0xe0, 0xa6, 0x87, 0xb9, 0xe5, 0xad, 0x99, 0x34, 0xdf, + 0xe9, 0x4c, 0x5c, 0xd0, 0xde, 0x56, 0xed, 0x92, 0x67, 0x63, 0xfe, 0xd3, 0x84, 0xc5, 0x21, 0xf5, + 0x55, 0x84, 0xd5, 0xd3, 0x07, 0xdd, 0x9d, 0x5a, 0x25, 0x67, 0x4f, 0x17, 0x6d, 0xfb, 0x42, 0xb0, + 0xa2, 0xea, 0xe7, 0x70, 0xbd, 0xee, 0x6c, 0xb9, 0x3b, 0x8f, 0xa5, 0x06, 0xac, 0xdd, 0xfb, 0x0f, + 0xe0, 0x22, 0xf1, 0xf7, 0x00, 0x95, 0x73, 0xa1, 0x3f, 0x8f, 0xa2, 0xc4, 0x68, 0x5b, 0xe7, 0x63, + 0xaa, 0xec, 0x95, 0x3d, 0x76, 0x2e, 0x7b, 0x89, 0x99, 0xcf, 0x5e, 0xb3, 0x8d, 0x3d, 0x81, 0xf7, + 0xa6, 0x7b, 0x4f, 0x77, 0x5e, 0x98, 0x04, 0x68, 0x1b, 0xe7, 0x00, 0x0a, 0xd2, 0x03, 0x58, 0x9b, + 0xfd, 0x21, 0xe7, 0xc6, 0xce, 0x00, 0x35, 0xe3, 0x82, 0xc0, 0x69, 0x32, 0xed, 0xca, 0x4f, 0x6f, + 0x8e, 0xb6, 0x94, 0x47, 0x4f, 0x5f, 0x1e, 0x77, 0x94, 0x57, 0xc7, 0x1d, 0xe5, 0xf5, 0x71, 0x47, + 0xf9, 0xf5, 0xa4, 0xd3, 0x78, 0x75, 0xd2, 0x69, 0xfc, 0x75, 0xd2, 0x69, 0x7c, 0xfb, 0x85, 0x1f, + 0xb0, 0x71, 0x3a, 0xca, 0xaf, 0x46, 0x86, 0xbc, 0x19, 0x06, 0x23, 0x77, 0xdb, 0x27, 0x46, 0xb6, + 0x6b, 0x84, 0xc4, 0x4b, 0x27, 0x48, 0xc5, 0xa5, 0xed, 0xd3, 0xcf, 0xb6, 0xab, 0x57, 0xcf, 0xc3, + 0x18, 0xe9, 0x68, 0x89, 0x5f, 0xd8, 0xee, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x79, 0x25, 0xfe, + 0x36, 0x9e, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -424,6 +601,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // CreateChannel defines a rpc handler method for MsgCreateChannel + CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) + // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. + ProvideCounterparty(ctx context.Context, in *MsgProvideCounterparty, opts ...grpc.CallOption) (*MsgProvideCounterpartyResponse, error) // SendPacket defines a rpc handler method for MsgSendPacket. SendPacket(ctx context.Context, in *MsgSendPacket, opts ...grpc.CallOption) (*MsgSendPacketResponse, error) // RecvPacket defines a rpc handler method for MsgRecvPacket. @@ -442,6 +623,24 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) { + out := new(MsgCreateChannelResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/CreateChannel", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) ProvideCounterparty(ctx context.Context, in *MsgProvideCounterparty, opts ...grpc.CallOption) (*MsgProvideCounterpartyResponse, error) { + out := new(MsgProvideCounterpartyResponse) + err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/ProvideCounterparty", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) SendPacket(ctx context.Context, in *MsgSendPacket, opts ...grpc.CallOption) (*MsgSendPacketResponse, error) { out := new(MsgSendPacketResponse) err := c.cc.Invoke(ctx, "/ibc.core.channel.v2.Msg/SendPacket", in, out, opts...) @@ -480,6 +679,10 @@ func (c *msgClient) Acknowledgement(ctx context.Context, in *MsgAcknowledgement, // MsgServer is the server API for Msg service. type MsgServer interface { + // CreateChannel defines a rpc handler method for MsgCreateChannel + CreateChannel(context.Context, *MsgCreateChannel) (*MsgCreateChannelResponse, error) + // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. + ProvideCounterparty(context.Context, *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) // SendPacket defines a rpc handler method for MsgSendPacket. SendPacket(context.Context, *MsgSendPacket) (*MsgSendPacketResponse, error) // RecvPacket defines a rpc handler method for MsgRecvPacket. @@ -494,6 +697,12 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) CreateChannel(ctx context.Context, req *MsgCreateChannel) (*MsgCreateChannelResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateChannel not implemented") +} +func (*UnimplementedMsgServer) ProvideCounterparty(ctx context.Context, req *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ProvideCounterparty not implemented") +} func (*UnimplementedMsgServer) SendPacket(ctx context.Context, req *MsgSendPacket) (*MsgSendPacketResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SendPacket not implemented") } @@ -511,6 +720,42 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_CreateChannel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateChannel) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateChannel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/CreateChannel", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateChannel(ctx, req.(*MsgCreateChannel)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_ProvideCounterparty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgProvideCounterparty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ProvideCounterparty(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.core.channel.v2.Msg/ProvideCounterparty", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ProvideCounterparty(ctx, req.(*MsgProvideCounterparty)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_SendPacket_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgSendPacket) if err := dec(in); err != nil { @@ -587,6 +832,14 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "ibc.core.channel.v2.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "CreateChannel", + Handler: _Msg_CreateChannel_Handler, + }, + { + MethodName: "ProvideCounterparty", + Handler: _Msg_ProvideCounterparty_Handler, + }, { MethodName: "SendPacket", Handler: _Msg_SendPacket_Handler, @@ -608,7 +861,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "ibc/core/channel/v2/tx.proto", } -func (m *MsgSendPacket) Marshal() (dAtA []byte, err error) { +func (m *MsgCreateChannel) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -618,12 +871,12 @@ func (m *MsgSendPacket) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSendPacket) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCreateChannel) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSendPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCreateChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -633,38 +886,29 @@ func (m *MsgSendPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Signer) i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } - if len(m.PacketData) > 0 { - for iNdEx := len(m.PacketData) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.PacketData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a + { + size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) } - if m.TimeoutTimestamp != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) - i-- - dAtA[i] = 0x10 - } - if len(m.SourceChannel) > 0 { - i -= len(m.SourceChannel) - copy(dAtA[i:], m.SourceChannel) - i = encodeVarintTx(dAtA, i, uint64(len(m.SourceChannel))) + i-- + dAtA[i] = 0x12 + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ClientId))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgSendPacketResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgCreateChannelResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -674,25 +918,27 @@ func (m *MsgSendPacketResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSendPacketResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCreateChannelResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSendPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCreateChannelResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Sequence != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *MsgRecvPacket) Marshal() (dAtA []byte, err error) { +func (m *MsgProvideCounterparty) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -702,12 +948,12 @@ func (m *MsgRecvPacket) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRecvPacket) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgProvideCounterparty) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRecvPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgProvideCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -717,39 +963,26 @@ func (m *MsgRecvPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Signer) i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- - dAtA[i] = 0x22 - } - { - size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + dAtA[i] = 0x1a } - i-- - dAtA[i] = 0x1a - if len(m.ProofCommitment) > 0 { - i -= len(m.ProofCommitment) - copy(dAtA[i:], m.ProofCommitment) - i = encodeVarintTx(dAtA, i, uint64(len(m.ProofCommitment))) + if len(m.CounterpartyChannelId) > 0 { + i -= len(m.CounterpartyChannelId) + copy(dAtA[i:], m.CounterpartyChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyChannelId))) i-- dAtA[i] = 0x12 } - { - size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0xa } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } -func (m *MsgRecvPacketResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgProvideCounterpartyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -759,25 +992,20 @@ func (m *MsgRecvPacketResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgRecvPacketResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgProvideCounterpartyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgRecvPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgProvideCounterpartyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Result != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Result)) - i-- - dAtA[i] = 0x8 - } return len(dAtA) - i, nil } -func (m *MsgTimeout) Marshal() (dAtA []byte, err error) { +func (m *MsgSendPacket) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -787,12 +1015,12 @@ func (m *MsgTimeout) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgTimeout) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSendPacket) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgTimeout) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSendPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -802,27 +1030,191 @@ func (m *MsgTimeout) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Signer) i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) i-- - dAtA[i] = 0x2a - } - if m.NextSequenceRecv != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.NextSequenceRecv)) - i-- - dAtA[i] = 0x20 + dAtA[i] = 0x22 } - { - size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.PacketData) > 0 { + for iNdEx := len(m.PacketData) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PacketData[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x1a - if len(m.ProofUnreceived) > 0 { - i -= len(m.ProofUnreceived) - copy(dAtA[i:], m.ProofUnreceived) - i = encodeVarintTx(dAtA, i, uint64(len(m.ProofUnreceived))) + if m.TimeoutTimestamp != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TimeoutTimestamp)) + i-- + dAtA[i] = 0x10 + } + if len(m.SourceChannel) > 0 { + i -= len(m.SourceChannel) + copy(dAtA[i:], m.SourceChannel) + i = encodeVarintTx(dAtA, i, uint64(len(m.SourceChannel))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSendPacketResponse) 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 *MsgSendPacketResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSendPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgRecvPacket) 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 *MsgRecvPacket) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRecvPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x22 + } + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ProofCommitment) > 0 { + i -= len(m.ProofCommitment) + copy(dAtA[i:], m.ProofCommitment) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProofCommitment))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Packet.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *MsgRecvPacketResponse) 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 *MsgRecvPacketResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRecvPacketResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Result != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Result)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *MsgTimeout) 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 *MsgTimeout) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTimeout) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x2a + } + { + size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ProofUnreceived) > 0 { + i -= len(m.ProofUnreceived) + copy(dAtA[i:], m.ProofUnreceived) + i = encodeVarintTx(dAtA, i, uint64(len(m.ProofUnreceived))) i-- dAtA[i] = 0x12 } @@ -973,6 +1365,68 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *MsgCreateChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.MerklePathPrefix.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateChannelResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgProvideCounterparty) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CounterpartyChannelId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgProvideCounterpartyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgSendPacket) Size() (n int) { if m == nil { return 0 @@ -1058,68 +1512,490 @@ func (m *MsgTimeout) Size() (n int) { } l = m.ProofHeight.Size() n += 1 + l + sovTx(uint64(l)) - if m.NextSequenceRecv != 0 { - n += 1 + sovTx(uint64(m.NextSequenceRecv)) + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgTimeoutResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != 0 { + n += 1 + sovTx(uint64(m.Result)) + } + return n +} + +func (m *MsgAcknowledgement) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Packet.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.Acknowledgement.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.ProofAcked) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) } + l = m.ProofHeight.Size() + n += 1 + l + sovTx(uint64(l)) l = len(m.Signer) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - return n -} + return n +} + +func (m *MsgAcknowledgementResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Result != 0 { + n += 1 + sovTx(uint64(m.Result)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateChannel) 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 ErrIntOverflowTx + } + 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: MsgCreateChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateChannel: 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 MerklePathPrefix", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateChannelResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateChannelResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateChannelResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } -func (m *MsgTimeoutResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Result != 0 { - n += 1 + sovTx(uint64(m.Result)) + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n + return nil } - -func (m *MsgAcknowledgement) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Packet.Size() - n += 1 + l + sovTx(uint64(l)) - l = m.Acknowledgement.Size() - n += 1 + l + sovTx(uint64(l)) - l = len(m.ProofAcked) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = m.ProofHeight.Size() - n += 1 + l + sovTx(uint64(l)) - l = len(m.Signer) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) +func (m *MsgProvideCounterparty) 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 ErrIntOverflowTx + } + 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: MsgProvideCounterparty: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgProvideCounterparty: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = 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 ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + 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 Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } } - return n -} -func (m *MsgAcknowledgementResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Result != 0 { - n += 1 + sovTx(uint64(m.Result)) + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n + return nil } +func (m *MsgProvideCounterpartyResponse) 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 ErrIntOverflowTx + } + 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: MsgProvideCounterpartyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgProvideCounterpartyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } func (m *MsgSendPacket) Unmarshal(dAtA []byte) error { l := len(dAtA) @@ -1737,25 +2613,6 @@ func (m *MsgTimeout) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NextSequenceRecv", wireType) - } - m.NextSequenceRecv = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NextSequenceRecv |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) diff --git a/modules/core/api/module.go b/modules/core/api/module.go index f15dfad6611..077dc65e35e 100644 --- a/modules/core/api/module.go +++ b/modules/core/api/module.go @@ -16,8 +16,8 @@ type IBCModule interface { // for this specific application. OnSendPacket( ctx context.Context, - sourceID string, - destinationID string, + sourceChannel string, + destinationChannel string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress, @@ -25,20 +25,28 @@ type IBCModule interface { OnRecvPacket( ctx context.Context, - sourceID string, - destinationID string, + sourceChannel string, + destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress, ) channeltypesv2.RecvPacketResult - // OnAcknowledgementPacket - // OnTimeoutPacket is executed when a packet has timed out on the receiving chain. OnTimeoutPacket( ctx context.Context, - sourceID string, - destinationID string, + sourceChannel string, + destinationChannel string, + data channeltypesv2.PacketData, + relayer sdk.AccAddress, + ) error + + // OnAcknowledgementPacket is executed when a packet gets acknowledged + OnAcknowledgementPacket( + ctx context.Context, + sourceChannel string, + destinationChannel string, data channeltypesv2.PacketData, + acknowledgement []byte, relayer sdk.AccAddress, ) error } diff --git a/modules/core/client/cli/cli.go b/modules/core/client/cli/cli.go index 56f3ff765d3..7edaf621076 100644 --- a/modules/core/client/cli/cli.go +++ b/modules/core/client/cli/cli.go @@ -8,8 +8,8 @@ import ( ibcclient "github.com/cosmos/ibc-go/v9/modules/core/02-client" connection "github.com/cosmos/ibc-go/v9/modules/core/03-connection" channel "github.com/cosmos/ibc-go/v9/modules/core/04-channel" + channelv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2" ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" - packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server" ) // GetTxCmd returns the transaction commands for this module @@ -25,7 +25,7 @@ func GetTxCmd() *cobra.Command { ibcTxCmd.AddCommand( ibcclient.GetTxCmd(), channel.GetTxCmd(), - packetserver.GetTxCmd(), + channelv2.GetTxCmd(), ) return ibcTxCmd @@ -46,7 +46,7 @@ func GetQueryCmd() *cobra.Command { ibcclient.GetQueryCmd(), connection.GetQueryCmd(), channel.GetQueryCmd(), - packetserver.GetQueryCmd(), + channelv2.GetQueryCmd(), ) return ibcQueryCmd diff --git a/modules/core/internal/errors/errors.go b/modules/core/internal/errors/errors.go new file mode 100644 index 00000000000..99acf8c02a5 --- /dev/null +++ b/modules/core/internal/errors/errors.go @@ -0,0 +1,25 @@ +package errors + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" +) + +// ConvertToErrorEvents converts all events to error events by appending the +// error attribute prefix to each event's attribute key. +func ConvertToErrorEvents(events sdk.Events) sdk.Events { + if events == nil { + return nil + } + + newEvents := make(sdk.Events, len(events)) + for i, event := range events { + newEvents[i] = sdk.NewEvent(coretypes.ErrorAttributeKeyPrefix + event.Type) + for _, attribute := range event.Attributes { + newEvents[i] = newEvents[i].AppendAttributes(sdk.NewAttribute(coretypes.ErrorAttributeKeyPrefix+attribute.Key, attribute.Value)) + } + } + + return newEvents +} diff --git a/modules/core/internal/v2/telemetry/packet.go b/modules/core/internal/v2/telemetry/packet.go new file mode 100644 index 00000000000..7c5c8588247 --- /dev/null +++ b/modules/core/internal/v2/telemetry/packet.go @@ -0,0 +1,14 @@ +package telemetry + +import ( + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" +) + +// ReportRecvPacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportRecvPacket(packet channeltypesv2.Packet) {} + +// ReportTimeoutPacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportTimeoutPacket(packet channeltypesv2.Packet, timeoutType string) {} + +// ReportAcknowledgePacket TODO: https://github.com/cosmos/ibc-go/issues/7437 +func ReportAcknowledgePacket(packet channeltypesv2.Packet) {} diff --git a/modules/core/keeper/events_test.go b/modules/core/keeper/events_test.go index 98915ac13c1..359322833f0 100644 --- a/modules/core/keeper/events_test.go +++ b/modules/core/keeper/events_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v9/modules/core/keeper" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -99,7 +99,7 @@ func TestConvertToErrorEvents(t *testing.T) { tc.malleate() - newEvents := keeper.ConvertToErrorEvents(events) + newEvents := internalerrors.ConvertToErrorEvents(events) require.Equal(t, expEvents, newEvents) }) } diff --git a/modules/core/keeper/export_test.go b/modules/core/keeper/export_test.go deleted file mode 100644 index 81d79ea7aa9..00000000000 --- a/modules/core/keeper/export_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package keeper - -import sdk "github.com/cosmos/cosmos-sdk/types" - -// ConvertToErrorEvents is a wrapper around convertToErrorEvents -// to allow the function to be directly called in tests. -func ConvertToErrorEvents(events sdk.Events) sdk.Events { - return convertToErrorEvents(events) -} diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 9f4351369bc..7b987945e61 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -15,10 +15,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" "github.com/cosmos/ibc-go/v9/modules/core/internal/telemetry" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" - coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" ) var ( @@ -26,7 +24,6 @@ var ( _ connectiontypes.MsgServer = (*Keeper)(nil) _ channeltypes.MsgServer = (*Keeper)(nil) _ channeltypes.PacketMsgServer = (*Keeper)(nil) - _ packetservertypes.MsgServer = (*Keeper)(nil) ) // CreateClient defines a rpc handler method for MsgCreateClient. @@ -140,49 +137,6 @@ func (k *Keeper) IBCSoftwareUpgrade(goCtx context.Context, msg *clienttypes.MsgI return &clienttypes.MsgIBCSoftwareUpgradeResponse{}, nil } -// CreateChannel defines a rpc handler method for MsgCreateChannel -func (k *Keeper) CreateChannel(goCtx context.Context, msg *packetservertypes.MsgCreateChannel) (*packetservertypes.MsgCreateChannelResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - channelID := k.ChannelKeeper.GenerateChannelIdentifier(ctx) - - // Initialize channel with empty counterparty channel identifier. - channel := packetservertypes.NewChannel(msg.ClientId, "", msg.MerklePathPrefix) - k.PacketServerKeeper.SetChannel(ctx, channelID, channel) - - k.PacketServerKeeper.SetCreator(ctx, channelID, msg.Signer) - - packetserverkeeper.EmitCreateChannelEvent(goCtx, channelID) - - return &packetservertypes.MsgCreateChannelResponse{ChannelId: channelID}, nil -} - -// ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. -func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertypes.MsgProvideCounterparty) (*packetservertypes.MsgProvideCounterpartyResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - creator, found := k.PacketServerKeeper.GetCreator(ctx, msg.ChannelId) - if !found { - return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set") - } - - if creator != msg.Signer { - return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "channel creator (%s) must match signer (%s)", creator, msg.Signer) - } - - channel, ok := k.PacketServerKeeper.GetChannel(ctx, msg.ChannelId) - if !ok { - return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidChannel, "channel must exist for channel id %s", msg.ChannelId) - } - - channel.CounterpartyChannelId = msg.CounterpartyChannelId - k.PacketServerKeeper.SetChannel(ctx, msg.ChannelId, channel) - // Delete client creator from state as it is not needed after this point. - k.PacketServerKeeper.DeleteCreator(ctx, msg.ChannelId) - - return &packetservertypes.MsgProvideCounterpartyResponse{}, nil -} - // ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit. func (k *Keeper) ConnectionOpenInit(goCtx context.Context, msg *connectiontypes.MsgConnectionOpenInit) (*connectiontypes.MsgConnectionOpenInitResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -488,7 +442,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack writeFn() } else { // Modify events in cached context to reflect unsuccessful acknowledgement - ctx.EventManager().EmitEvents(convertToErrorEvents(cacheCtx.EventManager().Events())) + ctx.EventManager().EmitEvents(internalerrors.ConvertToErrorEvents(cacheCtx.EventManager().Events())) } // Set packet acknowledgement only if the acknowledgement is not nil. @@ -1045,26 +999,6 @@ func (k *Keeper) UpdateChannelParams(goCtx context.Context, msg *channeltypes.Ms return &channeltypes.MsgUpdateParamsResponse{}, nil } -// convertToErrorEvents converts all events to error events by appending the -// error attribute prefix to each event's attribute key. -func convertToErrorEvents(events sdk.Events) sdk.Events { - if events == nil { - return nil - } - - newEvents := make(sdk.Events, len(events)) - for i, event := range events { - newAttributes := make([]sdk.Attribute, len(event.Attributes)) - for j, attribute := range event.Attributes { - newAttributes[j] = sdk.NewAttribute(coretypes.ErrorAttributeKeyPrefix+attribute.Key, attribute.Value) - } - - newEvents[i] = sdk.NewEvent(coretypes.ErrorAttributeKeyPrefix+event.Type, newAttributes...) - } - - return newEvents -} - // getPacketHandlerAndModule returns the appropriate packet handler // given the protocol version. An error is returned if the protocol // version is not supported. diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 404240f72d7..547d5702304 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -20,7 +20,7 @@ import ( host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/keeper" + internalerrors "github.com/cosmos/ibc-go/v9/modules/core/internal/errors" packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v9/testing" @@ -186,13 +186,13 @@ func (suite *KeeperTestSuite) TestHandleRecvPacket() { if tc.expRevert { // context events should contain error events - suite.Require().Contains(events, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + 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, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + suite.Require().NotContains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) } else { // context events should contain application events suite.Require().Contains(events, ibcmock.NewMockRecvPacketEvent()) @@ -353,13 +353,13 @@ func (suite *KeeperTestSuite) TestRecvPacketV2() { if tc.expRevert { // context events should contain error events - suite.Require().Contains(events, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + 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, keeper.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) + suite.Require().NotContains(events, internalerrors.ConvertToErrorEvents(sdk.Events{ibcmock.NewMockRecvPacketEvent()})[0]) } else { // context events should contain application events suite.Require().Contains(events, ibcmock.NewMockRecvPacketEvent()) @@ -1203,75 +1203,6 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() { } } -func (suite *KeeperTestSuite) TestProvideCounterparty() { - var ( - path *ibctesting.Path - msg *packetservertypes.MsgProvideCounterparty - ) - cases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() { - // set it before handler - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetChannel(suite.chainA.GetContext(), msg.ChannelId, packetservertypes.NewChannel(path.EndpointA.ClientID, "", ibctesting.MerklePath)) - }, - nil, - }, - { - "failure: signer does not match creator", - func() { - msg.Signer = ibctesting.TestAccAddress - }, - ibcerrors.ErrUnauthorized, - }, - { - "failure: counterparty does not already exists", - func() { - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(packetservertypes.ChannelKey)) - }, - packetservertypes.ErrInvalidChannel, - }, - } - - for _, tc := range cases { - tc := tc - path = ibctesting.NewPath(suite.chainA, suite.chainB) - path.SetupClients() - - suite.Require().NoError(path.EndpointA.CreateChannel()) - - signer := path.EndpointA.Chain.SenderAccount.GetAddress().String() - msg = packetservertypes.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer) - - tc.malleate() - - ctx := suite.chainA.GetContext() - resp, err := suite.chainA.App.GetIBCKeeper().ProvideCounterparty(ctx, msg) - - expPass := tc.expError == nil - if expPass { - suite.Require().NotNil(resp) - suite.Require().Nil(err) - - // Assert counterparty channel id filled in and creator deleted - channel, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID) - suite.Require().True(found) - suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID) - - _, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().False(found) - } else { - suite.Require().Nil(resp) - suite.Require().Error(err) - suite.Require().ErrorIs(err, tc.expError) - } - } -} - func (suite *KeeperTestSuite) TestUpgradeClient() { var ( path *ibctesting.Path diff --git a/modules/core/module.go b/modules/core/module.go index 29c1d2d8d04..c312604d7f3 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -28,8 +28,6 @@ import ( "github.com/cosmos/ibc-go/v9/modules/core/client/cli" "github.com/cosmos/ibc-go/v9/modules/core/exported" "github.com/cosmos/ibc-go/v9/modules/core/keeper" - packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" "github.com/cosmos/ibc-go/v9/modules/core/simulation" "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -94,7 +92,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r if err != nil { panic(err) } - err = packetservertypes.RegisterQueryHandlerClient(context.Background(), mux, packetservertypes.NewQueryClient(clientCtx)) if err != nil { panic(err) } @@ -140,12 +137,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterPacketMsgServer(cfg.MsgServer(), am.keeper) channeltypesv2.RegisterMsgServer(cfg.MsgServer(), am.keeper.ChannelKeeperV2) - packetservertypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) clienttypes.RegisterQueryServer(cfg.QueryServer(), clientkeeper.NewQueryServer(am.keeper.ClientKeeper)) connectiontypes.RegisterQueryServer(cfg.QueryServer(), connectionkeeper.NewQueryServer(am.keeper.ConnectionKeeper)) channeltypes.RegisterQueryServer(cfg.QueryServer(), channelkeeper.NewQueryServer(am.keeper.ChannelKeeper)) - packetservertypes.RegisterQueryServer(cfg.QueryServer(), packetserverkeeper.NewQueryServer(am.keeper.PacketServerKeeper)) clientMigrator := clientkeeper.NewMigrator(am.keeper.ClientKeeper) if err := cfg.RegisterMigration(exported.ModuleName, 2, clientMigrator.Migrate2to3); err != nil { diff --git a/modules/core/packet-server/client/cli/tx.go b/modules/core/packet-server/client/cli/tx.go deleted file mode 100644 index a1180c24b87..00000000000 --- a/modules/core/packet-server/client/cli/tx.go +++ /dev/null @@ -1,45 +0,0 @@ -package cli - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/version" - - "github.com/cosmos/ibc-go/v9/modules/core/exported" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" -) - -// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC channel. -func newProvideCounterpartyCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]", - Args: cobra.ExactArgs(2), - Short: "provide the counterparty channel id to an IBC channel end", - Long: `Provide the counterparty channel id to an IBC channel end specified by its channel ID.`, - Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - channelID := args[0] - counterpartyChannelID := args[1] - - msg := types.MsgProvideCounterparty{ - ChannelId: channelID, - CounterpartyChannelId: counterpartyChannelID, - Signer: clientCtx.GetFromAddress().String(), - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - return cmd -} diff --git a/modules/core/packet-server/keeper/events.go b/modules/core/packet-server/keeper/events.go deleted file mode 100644 index 64f5c023205..00000000000 --- a/modules/core/packet-server/keeper/events.go +++ /dev/null @@ -1,25 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" -) - -// EmitCreateChannelEvent emits a channel create event. -func EmitCreateChannelEvent(ctx context.Context, channelID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeCreateChannel, - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) -} diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index b862b3e0ed5..eeeeec5aa3e 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -66,26 +66,3 @@ func (k *Keeper) GetChannel(ctx context.Context, clientID string) (types.Channel k.cdc.MustUnmarshal(bz, &channel) return channel, true } - -// GetCreator returns the creator of the client. -func (k *Keeper) GetCreator(ctx context.Context, clientID string) (string, bool) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - bz := k.ChannelStore(sdkCtx, clientID).Get([]byte(types.CreatorKey)) - if len(bz) == 0 { - return "", false - } - - return string(bz), true -} - -// SetCreator sets the creator of the client. -func (k *Keeper) SetCreator(ctx context.Context, clientID, creator string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - k.ChannelStore(sdkCtx, clientID).Set([]byte(types.CreatorKey), []byte(creator)) -} - -// DeleteCreator deletes the creator associated with the client. -func (k *Keeper) DeleteCreator(ctx context.Context, clientID string) { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - k.ChannelStore(sdkCtx, clientID).Delete([]byte(types.CreatorKey)) -} diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go deleted file mode 100644 index 3c95dc45e0e..00000000000 --- a/modules/core/packet-server/keeper/keeper_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package keeper_test - -import ( - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" - ibctesting "github.com/cosmos/ibc-go/v9/testing" -) - -const testClientID = "tendermint-0" - -func (suite *KeeperTestSuite) TestSetChannel() { - merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) - channel := types.Channel{ - ClientId: testClientID, - MerklePathPrefix: merklePathPrefix, - } - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetChannel(suite.chainA.GetContext(), testClientID, channel) - - retrievedChannel, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetChannel(suite.chainA.GetContext(), testClientID) - suite.Require().True(found, "GetChannel does not return channel") - suite.Require().Equal(channel, retrievedChannel, "Channel retrieved not equal") - - // Channel not yet stored for another client. - retrievedChannel, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetChannel(suite.chainA.GetContext(), ibctesting.SecondClientID) - suite.Require().False(found, "GetChannel unexpectedly returned a channel") - suite.Require().Equal(types.Channel{}, retrievedChannel, "Channel retrieved not empty") -} - -func (suite *KeeperTestSuite) TestSetCreator() { - clientID := ibctesting.FirstClientID - expectedCreator := "test-creator" - - // Set the creator for the client - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCreator(suite.chainA.GetContext(), clientID, expectedCreator) - - // Retrieve the creator from the store - retrievedCreator, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), clientID) - - // Verify that the retrieved creator matches the expected creator - suite.Require().True(found, "GetCreator did not return stored creator") - suite.Require().Equal(expectedCreator, retrievedCreator, "Creator is not retrieved correctly") - - // Verify non stored creator is not found - retrievedCreator, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), ibctesting.SecondClientID) - suite.Require().False(found, "GetCreator unexpectedly returned a creator") - suite.Require().Empty(retrievedCreator, "Creator is not empty") - - // Verify that the creator is deleted from the store - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.DeleteCreator(suite.chainA.GetContext(), clientID) - retrievedCreator, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), clientID) - suite.Require().False(found, "GetCreator unexpectedly returned a creator") - suite.Require().Empty(retrievedCreator, "Creator is not empty") -} diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go index 9ad03fb70c8..334ea601a03 100644 --- a/modules/core/packet-server/keeper/relay.go +++ b/modules/core/packet-server/keeper/relay.go @@ -12,6 +12,7 @@ import ( 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" @@ -134,7 +135,7 @@ func (k Keeper) RecvPacket( } if channel.CounterpartyChannelId != packet.SourceChannel { - return "", channeltypes.ErrInvalidChannelIdentifier + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet source channel id (%s)", channel.CounterpartyChannelId, packet.SourceChannel) } clientID := channel.ClientId @@ -159,7 +160,7 @@ func (k Keeper) RecvPacket( } path := host.PacketCommitmentKey(packet.SourcePort, packet.SourceChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) commitment := channeltypes.CommitPacket(packet) @@ -210,7 +211,7 @@ func (k Keeper) WriteAcknowledgement( return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationChannel) } if channel.CounterpartyChannelId != packet.SourceChannel { - return channeltypes.ErrInvalidChannelIdentifier + 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 @@ -267,7 +268,7 @@ func (k Keeper) AcknowledgePacket( } if channel.CounterpartyChannelId != packet.DestinationChannel { - return "", channeltypes.ErrInvalidChannelIdentifier + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) } clientID := channel.ClientId @@ -290,7 +291,7 @@ func (k Keeper) AcknowledgePacket( } path := host.PacketAcknowledgementKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyMembership( ctx, @@ -338,7 +339,7 @@ func (k Keeper) TimeoutPacket( } if channel.CounterpartyChannelId != packet.DestinationChannel { - return "", channeltypes.ErrInvalidChannelIdentifier + return "", errorsmod.Wrapf(channeltypes.ErrInvalidChannelIdentifier, "counterparty channel id (%s) does not match packet destination channel id (%s)", channel.CounterpartyChannelId, packet.DestinationChannel) } clientID := channel.ClientId @@ -373,7 +374,7 @@ func (k Keeper) TimeoutPacket( // verify packet receipt absence path := host.PacketReceiptKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(channel.MerklePathPrefix, path) + merklePath := channeltypesv2.BuildMerklePath(channel.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyNonMembership( ctx, diff --git a/modules/core/packet-server/types/codec.go b/modules/core/packet-server/types/codec.go deleted file mode 100644 index 1c0bd85c7c2..00000000000 --- a/modules/core/packet-server/types/codec.go +++ /dev/null @@ -1,15 +0,0 @@ -package types - -import ( - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// RegisterInterfaces registers the client interfaces to protobuf Any. -func RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterImplementations( - (*sdk.Msg)(nil), - &MsgProvideCounterparty{}, - &MsgCreateChannel{}, - ) -} diff --git a/modules/core/packet-server/types/keys.go b/modules/core/packet-server/types/keys.go index fcbeb56d5e4..d1426569d57 100644 --- a/modules/core/packet-server/types/keys.go +++ b/modules/core/packet-server/types/keys.go @@ -8,9 +8,4 @@ const ( // 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" - - // CreatorKey is the key used to store the client creator in the client store - // the creator key is imported from types instead of host because - // the creator key is not a part of the ics-24 host specification - CreatorKey = "creator" ) diff --git a/modules/core/packet-server/types/msgs.go b/modules/core/packet-server/types/msgs.go deleted file mode 100644 index a291f62ab2d..00000000000 --- a/modules/core/packet-server/types/msgs.go +++ /dev/null @@ -1,68 +0,0 @@ -package types - -import ( - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" -) - -var ( - _ sdk.Msg = (*MsgProvideCounterparty)(nil) - _ sdk.HasValidateBasic = (*MsgProvideCounterparty)(nil) -) - -// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance -func NewMsgProvideCounterparty(channelID, counterpartyChannelID string, signer string) *MsgProvideCounterparty { - return &MsgProvideCounterparty{ - Signer: signer, - ChannelId: channelID, - CounterpartyChannelId: counterpartyChannelID, - } -} - -// ValidateBasic performs basic checks on a MsgProvideCounterparty. -func (msg *MsgProvideCounterparty) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) - } - - if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil { - return err - } - - if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil { - return err - } - - return nil -} - -// NewMsgCreateChannel creates a new MsgCreateChannel instance -func NewMsgCreateChannel(clientID string, merklePathPrefix commitmenttypes.MerklePath, signer string) *MsgCreateChannel { - return &MsgCreateChannel{ - Signer: signer, - ClientId: clientID, - MerklePathPrefix: merklePathPrefix, - } -} - -// ValidateBasic performs basic checks on a MsgCreateChannel. -func (msg *MsgCreateChannel) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { - return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) - } - - if err := host.ClientIdentifierValidator(msg.ClientId); err != nil { - return err - } - - if err := msg.MerklePathPrefix.ValidateAsPrefix(); err != nil { - return err - } - - return nil -} diff --git a/modules/core/packet-server/types/msgs_test.go b/modules/core/packet-server/types/msgs_test.go deleted file mode 100644 index c6af4cf8684..00000000000 --- a/modules/core/packet-server/types/msgs_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package types_test - -import ( - "errors" - - commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" - ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" - "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" - ibctesting "github.com/cosmos/ibc-go/v9/testing" -) - -// TestMsgProvideCounterpartyValidateBasic tests ValidateBasic for MsgProvideCounterparty -func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() { - var msg *types.MsgProvideCounterparty - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - "failure: invalid signer address", - func() { - msg.Signer = "invalid" - }, - ibcerrors.ErrInvalidAddress, - }, - { - "failure: invalid channel ID", - func() { - msg.ChannelId = "" - }, - host.ErrInvalidID, - }, - { - "failure: invalid counterparty channel ID", - func() { - msg.CounterpartyChannelId = "" - }, - host.ErrInvalidID, - }, - } - - for _, tc := range testCases { - msg = types.NewMsgProvideCounterparty( - ibctesting.FirstClientID, - ibctesting.SecondClientID, - ibctesting.TestAccAddress, - ) - - tc.malleate() - - err := msg.ValidateBasic() - expPass := tc.expError == nil - if expPass { - s.Require().NoError(err, "valid case %s failed", tc.name) - } else { - s.Require().ErrorIs(err, tc.expError, "invalid case %s passed", tc.name) - } - } -} - -// TestMsgCreateChannelValidateBasic tests ValidateBasic for MsgCreateChannel -func (s *TypesTestSuite) TestMsgCreateChannelValidateBasic() { - var msg *types.MsgCreateChannel - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - "failure: invalid signer address", - func() { - msg.Signer = "invalid" - }, - ibcerrors.ErrInvalidAddress, - }, - { - "failure: invalid client ID", - func() { - msg.ClientId = "" - }, - host.ErrInvalidID, - }, - { - "failure: empty key path", - func() { - msg.MerklePathPrefix.KeyPath = nil - }, - errors.New("path cannot have length 0"), - }, - } - - for _, tc := range testCases { - msg = types.NewMsgCreateChannel( - ibctesting.FirstClientID, - commitmenttypes.NewMerklePath([]byte("key")), - ibctesting.TestAccAddress, - ) - - tc.malleate() - - err := msg.ValidateBasic() - expPass := tc.expError == nil - if expPass { - s.Require().NoError(err, "valid case %s failed", tc.name) - } else { - s.Require().ErrorContains(err, tc.expError.Error(), "invalid case %s passed", tc.name) - } - } -} diff --git a/modules/core/packet-server/types/tx.pb.go b/modules/core/packet-server/types/tx.pb.go deleted file mode 100644 index 22b052db787..00000000000 --- a/modules/core/packet-server/types/tx.pb.go +++ /dev/null @@ -1,1091 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ibc/core/packetserver/v1/tx.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/cosmos-sdk/types/msgservice" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/proto" - v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - 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 - -// MsgProvideCounterparty defines the message used to provide the counterparty client -// identifier. Can only be invoked one time by the signer of MsgCreateClient if the counterparty -// client identifier was not provided in the initial MsgCreateClient message. -type MsgProvideCounterparty struct { - // unique identifier we will use to write all packet messages sent to counterparty - ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` - // counterparty channel identifier - CounterpartyChannelId string `protobuf:"bytes,2,opt,name=counterparty_channel_id,json=counterpartyChannelId,proto3" json:"counterparty_channel_id,omitempty"` - // signer address - Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` -} - -func (m *MsgProvideCounterparty) Reset() { *m = MsgProvideCounterparty{} } -func (m *MsgProvideCounterparty) String() string { return proto.CompactTextString(m) } -func (*MsgProvideCounterparty) ProtoMessage() {} -func (*MsgProvideCounterparty) Descriptor() ([]byte, []int) { - return fileDescriptor_3c556aec8b7966db, []int{0} -} -func (m *MsgProvideCounterparty) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgProvideCounterparty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgProvideCounterparty.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 *MsgProvideCounterparty) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgProvideCounterparty.Merge(m, src) -} -func (m *MsgProvideCounterparty) XXX_Size() int { - return m.Size() -} -func (m *MsgProvideCounterparty) XXX_DiscardUnknown() { - xxx_messageInfo_MsgProvideCounterparty.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgProvideCounterparty proto.InternalMessageInfo - -// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. -type MsgProvideCounterpartyResponse struct { -} - -func (m *MsgProvideCounterpartyResponse) Reset() { *m = MsgProvideCounterpartyResponse{} } -func (m *MsgProvideCounterpartyResponse) String() string { return proto.CompactTextString(m) } -func (*MsgProvideCounterpartyResponse) ProtoMessage() {} -func (*MsgProvideCounterpartyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_3c556aec8b7966db, []int{1} -} -func (m *MsgProvideCounterpartyResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgProvideCounterpartyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgProvideCounterpartyResponse.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 *MsgProvideCounterpartyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgProvideCounterpartyResponse.Merge(m, src) -} -func (m *MsgProvideCounterpartyResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgProvideCounterpartyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgProvideCounterpartyResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgProvideCounterpartyResponse proto.InternalMessageInfo - -// MsgCreateChannel defines the message used to create a v2 Channel. -type MsgCreateChannel 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 key path used to store packet flow messages that the counterparty - // will use to send to us. - MerklePathPrefix v2.MerklePath `protobuf:"bytes,2,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` - // signer address - Signer string `protobuf:"bytes,3,opt,name=signer,proto3" json:"signer,omitempty"` -} - -func (m *MsgCreateChannel) Reset() { *m = MsgCreateChannel{} } -func (m *MsgCreateChannel) String() string { return proto.CompactTextString(m) } -func (*MsgCreateChannel) ProtoMessage() {} -func (*MsgCreateChannel) Descriptor() ([]byte, []int) { - return fileDescriptor_3c556aec8b7966db, []int{2} -} -func (m *MsgCreateChannel) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateChannel.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 *MsgCreateChannel) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateChannel.Merge(m, src) -} -func (m *MsgCreateChannel) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateChannel) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateChannel.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateChannel proto.InternalMessageInfo - -// MsgCreateChannelResponse defines the Msg/CreateChannel response type. -type MsgCreateChannelResponse struct { - ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` -} - -func (m *MsgCreateChannelResponse) Reset() { *m = MsgCreateChannelResponse{} } -func (m *MsgCreateChannelResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCreateChannelResponse) ProtoMessage() {} -func (*MsgCreateChannelResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_3c556aec8b7966db, []int{3} -} -func (m *MsgCreateChannelResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCreateChannelResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCreateChannelResponse.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 *MsgCreateChannelResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCreateChannelResponse.Merge(m, src) -} -func (m *MsgCreateChannelResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgCreateChannelResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCreateChannelResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCreateChannelResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*MsgProvideCounterparty)(nil), "ibc.core.packetserver.v1.MsgProvideCounterparty") - proto.RegisterType((*MsgProvideCounterpartyResponse)(nil), "ibc.core.packetserver.v1.MsgProvideCounterpartyResponse") - proto.RegisterType((*MsgCreateChannel)(nil), "ibc.core.packetserver.v1.MsgCreateChannel") - proto.RegisterType((*MsgCreateChannelResponse)(nil), "ibc.core.packetserver.v1.MsgCreateChannelResponse") -} - -func init() { proto.RegisterFile("ibc/core/packetserver/v1/tx.proto", fileDescriptor_3c556aec8b7966db) } - -var fileDescriptor_3c556aec8b7966db = []byte{ - // 468 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x7d, 0x6d, 0xa9, 0xc8, 0x21, 0x44, 0x65, 0xa0, 0x8d, 0x8c, 0x70, 0x4b, 0x16, 0x50, - 0xa4, 0xde, 0x51, 0x23, 0x21, 0xa8, 0x90, 0x90, 0x9a, 0xa9, 0x43, 0xa4, 0x28, 0x43, 0x07, 0x96, - 0xc8, 0x3e, 0x3f, 0x2e, 0xa7, 0xfa, 0x7c, 0xd6, 0xdd, 0xc5, 0x6a, 0x37, 0xca, 0xc4, 0xc8, 0xc8, - 0xc8, 0x47, 0xc8, 0xc7, 0xe8, 0xd8, 0x91, 0x09, 0xa1, 0x64, 0xe8, 0xd7, 0x40, 0x76, 0x5c, 0x63, - 0xaa, 0x00, 0x65, 0xf3, 0xbd, 0xf7, 0x7b, 0xef, 0xfd, 0xdf, 0xf3, 0x7b, 0xf8, 0x89, 0x88, 0x18, - 0x65, 0x4a, 0x03, 0xcd, 0x42, 0x76, 0x0c, 0xd6, 0x80, 0xce, 0x41, 0xd3, 0x7c, 0x8f, 0xda, 0x13, - 0x92, 0x69, 0x65, 0x95, 0xdb, 0x16, 0x11, 0x23, 0x05, 0x42, 0x9a, 0x08, 0xc9, 0xf7, 0xbc, 0x07, - 0x5c, 0x71, 0x55, 0x42, 0xb4, 0xf8, 0x5a, 0xf0, 0xde, 0xd3, 0x3a, 0x25, 0x53, 0x52, 0x0a, 0x2b, - 0x21, 0xb5, 0x34, 0x0f, 0x1a, 0xaf, 0x0a, 0xdc, 0x62, 0xca, 0x48, 0x65, 0xa8, 0x34, 0xbc, 0x28, - 0x28, 0x0d, 0x5f, 0x38, 0x3a, 0x5f, 0x10, 0xde, 0xec, 0x1b, 0x3e, 0xd0, 0x2a, 0x17, 0x31, 0xf4, - 0xd4, 0x24, 0xb5, 0xa0, 0xb3, 0x50, 0xdb, 0x53, 0xf7, 0x31, 0xc6, 0x6c, 0x1c, 0xa6, 0x29, 0x24, - 0x23, 0x11, 0xb7, 0xd1, 0x0e, 0x7a, 0xd6, 0x1a, 0xb6, 0x2a, 0xcb, 0x61, 0xec, 0xbe, 0xc4, 0x5b, - 0xac, 0x81, 0x8f, 0x1a, 0xec, 0x4a, 0xc9, 0x3e, 0x6c, 0xba, 0x7b, 0x75, 0xdc, 0x26, 0x5e, 0x37, - 0x82, 0xa7, 0xa0, 0xdb, 0xab, 0x25, 0x56, 0xbd, 0xf6, 0xef, 0x7d, 0xfa, 0xba, 0xed, 0x7c, 0xbc, - 0x9c, 0x76, 0x2b, 0x43, 0x67, 0x07, 0xfb, 0xcb, 0x95, 0x0d, 0xc1, 0x64, 0x2a, 0x35, 0xd0, 0x99, - 0x22, 0xbc, 0xd1, 0x37, 0xbc, 0xa7, 0x21, 0xb4, 0x50, 0x55, 0x70, 0x1f, 0xe1, 0x16, 0x4b, 0x04, - 0xa4, 0xf6, 0x97, 0xea, 0xdb, 0x0b, 0xc3, 0x61, 0xec, 0x1e, 0x61, 0x57, 0x82, 0x3e, 0x4e, 0x60, - 0x94, 0x85, 0x76, 0x3c, 0xca, 0x34, 0xbc, 0x17, 0x27, 0xa5, 0xde, 0x3b, 0x41, 0x87, 0xd4, 0xd3, - 0x6f, 0xcc, 0x2f, 0x0f, 0x48, 0xbf, 0x8c, 0x18, 0x84, 0x76, 0x7c, 0xb0, 0x76, 0xfe, 0x7d, 0xdb, - 0x19, 0x6e, 0xc8, 0xda, 0x32, 0x28, 0x33, 0xdc, 0xbc, 0xa9, 0xb7, 0xb8, 0x7d, 0x5d, 0xf1, 0x55, - 0x3b, 0xff, 0x18, 0xf8, 0xfe, 0x5a, 0x91, 0x2b, 0x38, 0x5b, 0xc1, 0xab, 0x7d, 0xc3, 0x5d, 0x85, - 0xef, 0xfe, 0xde, 0x77, 0x97, 0xfc, 0x69, 0x79, 0xc8, 0xf5, 0x8a, 0x5e, 0x70, 0x73, 0xb6, 0x56, - 0x77, 0x86, 0xf0, 0xfd, 0x65, 0x6b, 0xf2, 0xfc, 0xaf, 0xb9, 0x96, 0x44, 0x78, 0xaf, 0xfe, 0x37, - 0xe2, 0x4a, 0x83, 0x77, 0xeb, 0xc3, 0xe5, 0xb4, 0x8b, 0x0e, 0x8e, 0xce, 0x67, 0x3e, 0xba, 0x98, - 0xf9, 0xe8, 0xc7, 0xcc, 0x47, 0x9f, 0xe7, 0xbe, 0x73, 0x31, 0xf7, 0x9d, 0x6f, 0x73, 0xdf, 0x79, - 0xf7, 0x86, 0x0b, 0x3b, 0x9e, 0x44, 0xc5, 0x0f, 0xa4, 0xd5, 0xca, 0x8b, 0x88, 0xed, 0x72, 0x45, - 0xf3, 0xd7, 0x54, 0xaa, 0x78, 0x92, 0x80, 0x69, 0xde, 0xe0, 0x6e, 0x75, 0x84, 0xf6, 0x34, 0x03, - 0x13, 0xad, 0x97, 0x37, 0xf1, 0xe2, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x8b, 0x7a, 0x32, - 0xaa, 0x03, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MsgClient is the client API for Msg service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MsgClient interface { - // CreateChannel defines a rpc handler method for MsgCreateChannel - CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - ProvideCounterparty(ctx context.Context, in *MsgProvideCounterparty, opts ...grpc.CallOption) (*MsgProvideCounterpartyResponse, error) -} - -type msgClient struct { - cc grpc1.ClientConn -} - -func NewMsgClient(cc grpc1.ClientConn) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) CreateChannel(ctx context.Context, in *MsgCreateChannel, opts ...grpc.CallOption) (*MsgCreateChannelResponse, error) { - out := new(MsgCreateChannelResponse) - err := c.cc.Invoke(ctx, "/ibc.core.packetserver.v1.Msg/CreateChannel", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) ProvideCounterparty(ctx context.Context, in *MsgProvideCounterparty, opts ...grpc.CallOption) (*MsgProvideCounterpartyResponse, error) { - out := new(MsgProvideCounterpartyResponse) - err := c.cc.Invoke(ctx, "/ibc.core.packetserver.v1.Msg/ProvideCounterparty", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -type MsgServer interface { - // CreateChannel defines a rpc handler method for MsgCreateChannel - CreateChannel(context.Context, *MsgCreateChannel) (*MsgCreateChannelResponse, error) - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - ProvideCounterparty(context.Context, *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) -} - -// UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} - -func (*UnimplementedMsgServer) CreateChannel(ctx context.Context, req *MsgCreateChannel) (*MsgCreateChannelResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateChannel not implemented") -} -func (*UnimplementedMsgServer) ProvideCounterparty(ctx context.Context, req *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ProvideCounterparty not implemented") -} - -func RegisterMsgServer(s grpc1.Server, srv MsgServer) { - s.RegisterService(&_Msg_serviceDesc, srv) -} - -func _Msg_CreateChannel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCreateChannel) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).CreateChannel(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/ibc.core.packetserver.v1.Msg/CreateChannel", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CreateChannel(ctx, req.(*MsgCreateChannel)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_ProvideCounterparty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgProvideCounterparty) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).ProvideCounterparty(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/ibc.core.packetserver.v1.Msg/ProvideCounterparty", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).ProvideCounterparty(ctx, req.(*MsgProvideCounterparty)) - } - return interceptor(ctx, in, info, handler) -} - -var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "ibc.core.packetserver.v1.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateChannel", - Handler: _Msg_CreateChannel_Handler, - }, - { - MethodName: "ProvideCounterparty", - Handler: _Msg_ProvideCounterparty_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "ibc/core/packetserver/v1/tx.proto", -} - -func (m *MsgProvideCounterparty) 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 *MsgProvideCounterparty) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgProvideCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Signer) > 0 { - i -= len(m.Signer) - copy(dAtA[i:], m.Signer) - i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) - i-- - dAtA[i] = 0x1a - } - if len(m.CounterpartyChannelId) > 0 { - i -= len(m.CounterpartyChannelId) - copy(dAtA[i:], m.CounterpartyChannelId) - i = encodeVarintTx(dAtA, i, uint64(len(m.CounterpartyChannelId))) - i-- - dAtA[i] = 0x12 - } - if len(m.ChannelId) > 0 { - i -= len(m.ChannelId) - copy(dAtA[i:], m.ChannelId) - i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgProvideCounterpartyResponse) 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 *MsgProvideCounterpartyResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgProvideCounterpartyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *MsgCreateChannel) 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 *MsgCreateChannel) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCreateChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Signer) > 0 { - i -= len(m.Signer) - copy(dAtA[i:], m.Signer) - i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) - i-- - dAtA[i] = 0x1a - } - { - size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.ClientId) > 0 { - i -= len(m.ClientId) - copy(dAtA[i:], m.ClientId) - i = encodeVarintTx(dAtA, i, uint64(len(m.ClientId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgCreateChannelResponse) 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 *MsgCreateChannelResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCreateChannelResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ChannelId) > 0 { - i -= len(m.ChannelId) - copy(dAtA[i:], m.ChannelId) - i = encodeVarintTx(dAtA, i, uint64(len(m.ChannelId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgProvideCounterparty) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChannelId) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.CounterpartyChannelId) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.Signer) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgProvideCounterpartyResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *MsgCreateChannel) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ClientId) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = m.MerklePathPrefix.Size() - n += 1 + l + sovTx(uint64(l)) - l = len(m.Signer) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgCreateChannelResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChannelId) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgProvideCounterparty) 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 ErrIntOverflowTx - } - 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: MsgProvideCounterparty: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgProvideCounterparty: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChannelId = 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 ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - 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 Signer", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgProvideCounterpartyResponse) 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 ErrIntOverflowTx - } - 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: MsgProvideCounterpartyResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgProvideCounterpartyResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCreateChannel) 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 ErrIntOverflowTx - } - 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: MsgCreateChannel: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateChannel: 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 ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - 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 MerklePathPrefix", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signer = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCreateChannelResponse) 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 ErrIntOverflowTx - } - 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: MsgCreateChannelResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCreateChannelResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - 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 ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChannelId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTx(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, ErrIntOverflowTx - } - 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, ErrIntOverflowTx - } - 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, ErrIntOverflowTx - } - 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, ErrInvalidLengthTx - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTx - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTx - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") -) diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index d805413f912..d704d725ea3 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -8,7 +8,6 @@ import ( 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" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) // RegisterInterfaces registers ibc types against interfaces using the global InterfaceRegistry. @@ -17,7 +16,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { clienttypes.RegisterInterfaces(registry) connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) - packetservertypes.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) channeltypesv2.RegisterInterfaces(registry) diff --git a/proto/ibc/core/channel/v2/packet.proto b/proto/ibc/core/channel/v2/packet.proto index 20d002d2e6e..0012f8ec697 100644 --- a/proto/ibc/core/channel/v2/packet.proto +++ b/proto/ibc/core/channel/v2/packet.proto @@ -17,7 +17,7 @@ message Packet { string source_channel = 2; // identifies the receiving chain. string destination_channel = 3; - // timeout timestamp after which the packet times out. + // timeout timestamp in seconds after which the packet times out. uint64 timeout_timestamp = 4; // a list of packet data, each one for a specific application. repeated PacketData data = 5 [(gogoproto.nullable) = false]; diff --git a/proto/ibc/core/packetserver/v1/query.proto b/proto/ibc/core/channel/v2/query.proto similarity index 80% rename from proto/ibc/core/packetserver/v1/query.proto rename to proto/ibc/core/channel/v2/query.proto index f429a185e87..072118099a8 100644 --- a/proto/ibc/core/packetserver/v1/query.proto +++ b/proto/ibc/core/channel/v2/query.proto @@ -1,10 +1,10 @@ syntax = "proto3"; -package ibc.core.packetserver.v1; +package ibc.core.channel.v2; -option go_package = "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"; +option go_package = "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"; -import "ibc/core/packetserver/v1/channel.proto"; +import "ibc/core/channel/v2/channel.proto"; import "google/api/annotations.proto"; import "gogoproto/gogo.proto"; diff --git a/proto/ibc/core/channel/v2/tx.proto b/proto/ibc/core/channel/v2/tx.proto index 771706b3efc..b949b506412 100644 --- a/proto/ibc/core/channel/v2/tx.proto +++ b/proto/ibc/core/channel/v2/tx.proto @@ -9,11 +9,18 @@ import "cosmos/msg/v1/msg.proto"; import "ibc/core/channel/v2/packet.proto"; import "ibc/core/channel/v1/tx.proto"; import "ibc/core/client/v1/client.proto"; +import "ibc/core/commitment/v2/commitment.proto"; // Msg defines the ibc/channel/v2 Msg service. service Msg { option (cosmos.msg.v1.service) = true; + // CreateChannel defines a rpc handler method for MsgCreateChannel + rpc CreateChannel(MsgCreateChannel) returns (MsgCreateChannelResponse); + + // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. + rpc ProvideCounterparty(MsgProvideCounterparty) returns (MsgProvideCounterpartyResponse); + // SendPacket defines a rpc handler method for MsgSendPacket. rpc SendPacket(MsgSendPacket) returns (MsgSendPacketResponse); @@ -27,6 +34,46 @@ service Msg { rpc Acknowledgement(MsgAcknowledgement) returns (MsgAcknowledgementResponse); } +// MsgCreateChannel defines the message used to create a v2 Channel. +message MsgCreateChannel { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // the client identifier of the light client representing the counterparty chain + string client_id = 1; + // the key path used to store packet flow messages that the counterparty + // will use to send to us. + ibc.core.commitment.v2.MerklePath merkle_path_prefix = 2 [(gogoproto.nullable) = false]; + // signer address + string signer = 3; +} + +// MsgCreateChannelResponse defines the Msg/CreateChannel response type. +message MsgCreateChannelResponse { + option (gogoproto.goproto_getters) = false; + + string channel_id = 1; +} + +// MsgProvideCounterparty defines the message used to provide the counterparty channel +// identifier. +message MsgProvideCounterparty { + option (cosmos.msg.v1.signer) = "signer"; + + option (gogoproto.goproto_getters) = false; + + // unique identifier we will use to write all packet messages sent to counterparty + string channel_id = 1; + // counterparty channel identifier + string counterparty_channel_id = 2; + // signer address + string signer = 3; +} + +// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. +message MsgProvideCounterpartyResponse {} + // MsgSendPacket sends an outgoing IBC packet. message MsgSendPacket { option (cosmos.msg.v1.signer) = "signer"; @@ -70,11 +117,10 @@ message MsgTimeout { option (gogoproto.goproto_getters) = false; - Packet packet = 1 [(gogoproto.nullable) = false]; - bytes proof_unreceived = 2; - ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; - uint64 next_sequence_recv = 4; - string signer = 5; + Packet packet = 1 [(gogoproto.nullable) = false]; + bytes proof_unreceived = 2; + ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; + string signer = 5; } // MsgTimeoutResponse defines the Msg/Timeout response type. diff --git a/proto/ibc/core/packetserver/v1/tx.proto b/proto/ibc/core/packetserver/v1/tx.proto deleted file mode 100644 index c179e9ae25c..00000000000 --- a/proto/ibc/core/packetserver/v1/tx.proto +++ /dev/null @@ -1,62 +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"; -import "cosmos/msg/v1/msg.proto"; - -// Msg defines the ibc/packetserver Msg service. -service Msg { - option (cosmos.msg.v1.service) = true; - - // CreateChannel defines a rpc handler method for MsgCreateChannel - rpc CreateChannel(MsgCreateChannel) returns (MsgCreateChannelResponse); - - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - rpc ProvideCounterparty(MsgProvideCounterparty) returns (MsgProvideCounterpartyResponse); -} - -// MsgProvideCounterparty defines the message used to provide the counterparty client -// identifier. Can only be invoked one time by the signer of MsgCreateClient if the counterparty -// client identifier was not provided in the initial MsgCreateClient message. -message MsgProvideCounterparty { - option (cosmos.msg.v1.signer) = "signer"; - - option (gogoproto.goproto_getters) = false; - - // unique identifier we will use to write all packet messages sent to counterparty - string channel_id = 1; - // counterparty channel identifier - string counterparty_channel_id = 2; - // signer address - string signer = 3; -} - -// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. -message MsgProvideCounterpartyResponse {} - -// MsgCreateChannel defines the message used to create a v2 Channel. -message MsgCreateChannel { - option (cosmos.msg.v1.signer) = "signer"; - - option (gogoproto.goproto_getters) = false; - - // the client identifier of the light client representing the counterparty chain - string client_id = 1; - // the key path used to store packet flow messages that the counterparty - // will use to send to us. - ibc.core.commitment.v2.MerklePath merkle_path_prefix = 2 [(gogoproto.nullable) = false]; - // signer address - string signer = 3; -} - -// MsgCreateChannelResponse defines the Msg/CreateChannel response type. -message MsgCreateChannelResponse { - option (gogoproto.goproto_getters) = false; - - string channel_id = 1; -} diff --git a/testing/chain.go b/testing/chain.go index 8a8dbabba0f..89d804460a4 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -579,6 +579,12 @@ func (chain *TestChain) GetTimeoutTimestamp() uint64 { return uint64(chain.GetContext().BlockTime().UnixNano()) + DefaultTimeoutTimestampDelta } +// GetTimeoutTimestampSecs is a convenience function which returns a IBC packet timeout timestamp in seconds +// to be used for testing. It returns the current block timestamp + default timestamp delta (1 hour). +func (chain *TestChain) GetTimeoutTimestampSecs() uint64 { + return uint64(chain.GetContext().BlockTime().Unix()) + uint64(time.Hour.Seconds()) +} + // DeleteKey deletes the specified key from the ibc store. func (chain *TestChain) DeleteKey(key []byte) { storeKey := chain.GetSimApp().GetKey(exported.StoreKey) diff --git a/testing/endpoint.go b/testing/endpoint.go index 05ad6c1e654..82f735ae78e 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -16,10 +16,10 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" 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" commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types" 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" ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint" ) @@ -178,7 +178,7 @@ func (endpoint *Endpoint) FreezeClient() { // ProvideCounterparty will construct and execute a MsgProvideCounterparty on the associated endpoint. func (endpoint *Endpoint) ProvideCounterparty() (err error) { - msg := packetservertypes.NewMsgProvideCounterparty(endpoint.ChannelID, endpoint.Counterparty.ChannelID, endpoint.Chain.SenderAccount.GetAddress().String()) + msg := channeltypesv2.NewMsgProvideCounterparty(endpoint.ChannelID, endpoint.Counterparty.ChannelID, endpoint.Chain.SenderAccount.GetAddress().String()) // setup counterparty _, err = endpoint.Chain.SendMsgs(msg) @@ -188,7 +188,7 @@ func (endpoint *Endpoint) ProvideCounterparty() (err error) { // CreateChannel will construct and execute a new MsgCreateChannel on the associated endpoint. func (endpoint *Endpoint) CreateChannel() (err error) { - msg := packetservertypes.NewMsgCreateChannel(endpoint.ClientID, MerklePath, endpoint.Chain.SenderAccount.GetAddress().String()) + msg := channeltypesv2.NewMsgCreateChannel(endpoint.ClientID, MerklePath, endpoint.Chain.SenderAccount.GetAddress().String()) // create channel res, err := endpoint.Chain.SendMsgs(msg) diff --git a/testing/endpoint_v2.go b/testing/endpoint_v2.go new file mode 100644 index 00000000000..506ce2b03f2 --- /dev/null +++ b/testing/endpoint_v2.go @@ -0,0 +1,72 @@ +package ibctesting + +import ( + "github.com/stretchr/testify/require" + + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" + hostv2 "github.com/cosmos/ibc-go/v9/modules/core/24-host/v2" +) + +// MsgSendPacket sends a packet on the associated endpoint. The constructed packet is returned. +func (endpoint *Endpoint) MsgSendPacket(timeoutTimestamp uint64, packetData channeltypesv2.PacketData) (channeltypesv2.Packet, error) { + msgSendPacket := channeltypesv2.NewMsgSendPacket(endpoint.ChannelID, timeoutTimestamp, endpoint.Chain.SenderAccount.GetAddress().String(), packetData) + + _, err := endpoint.Chain.SendMsgs(msgSendPacket) + if err != nil { + return channeltypesv2.Packet{}, err + } + + if err := endpoint.Counterparty.UpdateClient(); err != nil { + return channeltypesv2.Packet{}, err + } + + // TODO: parse the packet from events instead of manually constructing it. https://github.com/cosmos/ibc-go/issues/7459 + nextSequenceSend, ok := endpoint.Chain.GetSimApp().IBCKeeper.ChannelKeeperV2.GetNextSequenceSend(endpoint.Chain.GetContext(), endpoint.ChannelID) + require.True(endpoint.Chain.TB, ok) + packet := channeltypesv2.NewPacket(nextSequenceSend-1, endpoint.ChannelID, endpoint.Counterparty.ChannelID, timeoutTimestamp, packetData) + + return packet, nil +} + +// MsgRecvPacket sends a MsgRecvPacket on the associated endpoint with the provided packet. +func (endpoint *Endpoint) MsgRecvPacket(packet channeltypesv2.Packet) error { + // get proof of packet commitment from chainA + packetKey := hostv2.PacketCommitmentKey(packet.SourceChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgRecvPacket(packet, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} + +// MsgAcknowledgePacket sends a MsgAcknowledgement on the associated endpoint with the provided packet and ack. +func (endpoint *Endpoint) MsgAcknowledgePacket(packet channeltypesv2.Packet, ack channeltypesv2.Acknowledgement) error { + packetKey := hostv2.PacketAcknowledgementKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgAcknowledgement(packet, ack, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} + +// MsgTimeoutPacket sends a MsgTimeout on the associated endpoint with the provided packet. +func (endpoint *Endpoint) MsgTimeoutPacket(packet channeltypesv2.Packet) error { + packetKey := hostv2.PacketReceiptKey(packet.DestinationChannel, packet.Sequence) + proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey) + + msg := channeltypesv2.NewMsgTimeout(packet, proof, proofHeight, endpoint.Chain.SenderAccount.GetAddress().String()) + + if err := endpoint.Chain.sendMsgs(msg); err != nil { + return err + } + + return endpoint.Counterparty.UpdateClient() +} diff --git a/testing/events.go b/testing/events.go index 0fa3cfafb73..a4caaf46a9e 100644 --- a/testing/events.go +++ b/testing/events.go @@ -14,7 +14,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" + channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" ) // ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the @@ -48,7 +48,7 @@ func ParseConnectionIDFromEvents(events []abci.Event) (string, error) { // MsgChannelOpenTry or a MsgCreateChannel and returns the channel identifier. func ParseChannelIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { - if ev.Type == packetservertypes.EventTypeCreateChannel || ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { + if ev.Type == channeltypesv2.EventTypeCreateChannel || ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { if attribute, found := attributeByKey(ev.Attributes, channeltypes.AttributeKeyChannelID); found { return attribute.Value, nil } diff --git a/testing/mock/v2/ibc_app.go b/testing/mock/v2/ibc_app.go index ddf4c67f115..74c6ca7c543 100644 --- a/testing/mock/v2/ibc_app.go +++ b/testing/mock/v2/ibc_app.go @@ -9,7 +9,8 @@ import ( ) type IBCApp struct { - OnSendPacket func(ctx context.Context, sourceID string, destinationID string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error - OnRecvPacket func(ctx context.Context, sourceID string, destinationID string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult - OnTimeoutPacket func(ctx context.Context, sourceID string, destinationID string, data channeltypesv2.PacketData, relayer sdk.AccAddress) error + OnSendPacket func(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error + OnRecvPacket func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult + OnTimeoutPacket func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) error + OnAcknowledgementPacket func(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, acknowledgement []byte, relayer sdk.AccAddress) error } diff --git a/testing/mock/v2/ibc_module.go b/testing/mock/v2/ibc_module.go index 0e948daa471..871b870bba4 100644 --- a/testing/mock/v2/ibc_module.go +++ b/testing/mock/v2/ibc_module.go @@ -32,16 +32,16 @@ func NewIBCModule() IBCModule { } } -func (im IBCModule) OnSendPacket(ctx context.Context, sourceID string, destinationID string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error { +func (im IBCModule) OnSendPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error { if im.IBCApp.OnSendPacket != nil { - return im.IBCApp.OnSendPacket(ctx, sourceID, destinationID, sequence, data, signer) + return im.IBCApp.OnSendPacket(ctx, sourceChannel, destinationChannel, sequence, data, signer) } return nil } -func (im IBCModule) OnRecvPacket(ctx context.Context, sourceID string, destinationID string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult { +func (im IBCModule) OnRecvPacket(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult { if im.IBCApp.OnRecvPacket != nil { - return im.IBCApp.OnRecvPacket(ctx, sourceID, destinationID, data, relayer) + return im.IBCApp.OnRecvPacket(ctx, sourceChannel, destinationChannel, data, relayer) } return channeltypesv2.RecvPacketResult{ Status: channeltypesv2.PacketStatus_Success, @@ -49,18 +49,16 @@ func (im IBCModule) OnRecvPacket(ctx context.Context, sourceID string, destinati } } -// -// func (im IBCModule) OnAcknowledgementPacket() error { -// if im.IBCApp.OnAcknowledgementPacket != nil { -// return im.IBCApp.OnAcknowledgementPacket(...) -// } -// return nil -// } -// +func (im IBCModule) OnAcknowledgementPacket(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, acknowledgement []byte, relayer sdk.AccAddress) error { + if im.IBCApp.OnAcknowledgementPacket != nil { + return im.IBCApp.OnAcknowledgementPacket(ctx, sourceChannel, destinationChannel, data, acknowledgement, relayer) + } + return nil +} -func (im IBCModule) OnTimeoutPacket(ctx context.Context, sourceID string, destinationID string, data channeltypesv2.PacketData, relayer sdk.AccAddress) error { +func (im IBCModule) OnTimeoutPacket(ctx context.Context, sourceChannel string, destinationChannel string, data channeltypesv2.PacketData, relayer sdk.AccAddress) error { if im.IBCApp.OnTimeoutPacket != nil { - return im.IBCApp.OnTimeoutPacket(ctx, sourceID, destinationID, data, relayer) + return im.IBCApp.OnTimeoutPacket(ctx, sourceChannel, destinationChannel, data, relayer) } return nil } diff --git a/testing/utils.go b/testing/utils.go index 53d84ab559a..861bb54e1a6 100644 --- a/testing/utils.go +++ b/testing/utils.go @@ -87,6 +87,7 @@ func UnmarshalMsgResponses(cdc codec.Codec, data []byte, msgs ...codec.ProtoMars // RequireErrorIsOrContains verifies that the passed error is either a target error or contains its error message. func RequireErrorIsOrContains(t *testing.T, err, targetError error, msgAndArgs ...interface{}) { t.Helper() + require.Error(t, err) require.True( t, errors.Is(err, targetError) ||