From 2a2d7398549559a61d13f621a9929e753499fb81 Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:29:46 +0200 Subject: [PATCH 1/8] aliasing start --- modules/core/04-channel/keeper/keeper.go | 25 +++++++++++++++++++ modules/core/packet-server/keeper/keeper.go | 23 +++++++++++++---- .../packet-server/types/expected_keepers.go | 3 +++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 3c5e65b97f6..51cb2c36d50 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -19,6 +19,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" + commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -95,6 +96,30 @@ func (k *Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel t store.Set(host.ChannelKey(portID, channelID), bz) } +// GetV2Counterparty returns a version 2 counterparty for the given port and channel ID +// by converting the channel into a version 2 counterparty +func (k *Keeper) GetV2Counterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) { + channel, ok := k.GetChannel(ctx, portID, channelID) + if !ok { + return clienttypes.Counterparty{}, false + } + // Do not allow channel to be converted into a version 2 counterparty + // if the channel is not OPEN or if it is ORDERED + if channel.State != types.OPEN || channel.Ordering == types.ORDERED { + return clienttypes.Counterparty{}, false + } + connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) + if !ok { + return clienttypes.Counterparty{}, false + } + merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte("")) + counterparty := clienttypes.Counterparty{ + ClientId: connection.ClientId, + MerklePathPrefix: &merklePathPrefix, + } + return counterparty, true +} + // GetAppVersion gets the version for the specified channel. func (k *Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) { channel, found := k.GetChannel(ctx, portID, channelID) diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index 330e13ed759..b815a76e4b0 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -52,7 +52,7 @@ func (k Keeper) SendPacket( data []byte, ) (uint64, error) { // Lookup counterparty associated with our source channel to retrieve the destination channel - counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, sourceChannel) + counterparty, ok := k.GetCounterparty(ctx, sourcePort, sourceChannel) if !ok { return 0, channeltypes.ErrChannelNotFound } @@ -125,7 +125,7 @@ func (k Keeper) RecvPacket( // Lookup counterparty associated with our channel and ensure that it was packet was indeed // sent by our counterparty. // Note: This can be implemented by the current keeper - counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) + counterparty, ok := k.GetCounterparty(ctx, packet.DestinationPort, packet.DestinationChannel) if !ok { return "", channeltypes.ErrChannelNotFound } @@ -200,7 +200,7 @@ func (k Keeper) WriteAcknowledgement( // Lookup counterparty associated with our channel and ensure that it was packet was indeed // sent by our counterparty. - counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) + counterparty, ok := k.GetCounterparty(ctx, packet.DestinationPort, packet.DestinationChannel) if !ok { return channeltypes.ErrChannelNotFound } @@ -254,7 +254,7 @@ func (k Keeper) AcknowledgePacket( // Lookup counterparty associated with our channel and ensure that it was packet was indeed // sent by our counterparty. - counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) + counterparty, ok := k.GetCounterparty(ctx, packet.SourcePort, packet.SourceChannel) if !ok { return "", channeltypes.ErrChannelNotFound } @@ -321,7 +321,7 @@ func (k Keeper) TimeoutPacket( } // Lookup counterparty associated with our channel and ensure that destination channel // is the expected counterparty - counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) + counterparty, ok := k.GetCounterparty(ctx, packet.SourcePort, packet.SourceChannel) if !ok { return "", channeltypes.ErrChannelNotFound } @@ -390,3 +390,16 @@ func (k Keeper) TimeoutPacket( func sentinelChannel(clientID string) channeltypes.Channel { return channeltypes.Channel{Ordering: channeltypes.UNORDERED, ConnectionHops: []string{clientID}} } + +// GetCounterparty returns the v2 counterparty for a given portID and channelID. +// If the portID and channel ID resolves to a v1 channel, then we create a v2 counterparty +// using the channel information +// If the channel ID resolves to client, then we can directly retrieve the v2 counterparty +func (k Keeper) GetCounterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) { + counterparty, ok := k.ChannelKeeper.GetV2Counterparty(ctx, portID, channelID) + if ok { + return counterparty, true + } + // get the counterparty directly from the client keeper using the channel id as a client identifier + return k.ClientKeeper.GetCounterparty(ctx, channelID) +} diff --git a/modules/core/packet-server/types/expected_keepers.go b/modules/core/packet-server/types/expected_keepers.go index c3e23572228..dd4a8aea7c1 100644 --- a/modules/core/packet-server/types/expected_keepers.go +++ b/modules/core/packet-server/types/expected_keepers.go @@ -38,6 +38,9 @@ type ChannelKeeper interface { // SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path // This is a public path that is standardized by the IBC specification SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) + + // GetChannel returns a version 2 counterparty for a given portID and channel ID + GetV2Counterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) } type ClientKeeper interface { From 016f1f76268dbc102e20bcba0263179c5c6d3ab2 Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:34:08 +0200 Subject: [PATCH 2/8] move counterparty logic and msgs into packetserver --- modules/core/02-client/keeper/keeper.go | 19 - modules/core/02-client/types/client.go | 22 - modules/core/02-client/types/client.pb.go | 302 +-------- modules/core/02-client/types/client_test.go | 45 -- modules/core/02-client/types/codec.go | 1 - modules/core/02-client/types/errors.go | 1 - modules/core/02-client/types/msgs.go | 31 - modules/core/02-client/types/tx.pb.go | 535 ++------------- modules/core/04-channel/keeper/keeper.go | 15 +- modules/core/24-host/channel_keys.go | 2 + modules/core/keeper/keeper.go | 2 +- modules/core/keeper/msg_server.go | 11 +- modules/core/packet-server/keeper/keeper.go | 386 +---------- modules/core/packet-server/keeper/relay.go | 370 +++++++++++ .../keeper/{keeper_test.go => relay_test.go} | 0 modules/core/packet-server/types/codec.go | 14 + .../core/packet-server/types/counterparty.go | 29 + .../packet-server/types/counterparty.pb.go | 440 ++++++++++++ .../packet-server/types/counterparty_test.go | 54 ++ modules/core/packet-server/types/errors.go | 10 + .../packet-server/types/expected_keepers.go | 6 +- modules/core/packet-server/types/keys.go | 11 + modules/core/packet-server/types/msgs.go | 45 ++ modules/core/packet-server/types/tx.pb.go | 624 ++++++++++++++++++ proto/ibc/core/client/v1/client.proto | 9 - proto/ibc/core/client/v1/tx.proto | 22 - .../core/packetserver/v1/counterparty.proto | 21 + proto/ibc/core/packetserver/v1/tx.proto | 36 + 28 files changed, 1782 insertions(+), 1281 deletions(-) create mode 100644 modules/core/packet-server/keeper/relay.go rename modules/core/packet-server/keeper/{keeper_test.go => relay_test.go} (100%) create mode 100644 modules/core/packet-server/types/codec.go create mode 100644 modules/core/packet-server/types/counterparty.go create mode 100644 modules/core/packet-server/types/counterparty.pb.go create mode 100644 modules/core/packet-server/types/counterparty_test.go create mode 100644 modules/core/packet-server/types/errors.go create mode 100644 modules/core/packet-server/types/keys.go create mode 100644 modules/core/packet-server/types/msgs.go create mode 100644 modules/core/packet-server/types/tx.pb.go create mode 100644 proto/ibc/core/packetserver/v1/counterparty.proto create mode 100644 proto/ibc/core/packetserver/v1/tx.proto diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 94de6e8887c..dd5fb094657 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -304,25 +304,6 @@ func (k *Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) return k.GetClientConsensusState(ctx, clientID, clientModule.LatestHeight(ctx, clientID)) } -// SetCounterparty sets the Counterparty for a given client identifier. -func (k *Keeper) SetCounterparty(ctx sdk.Context, clientID string, counterparty types.Counterparty) { - bz := k.cdc.MustMarshal(&counterparty) - k.ClientStore(ctx, clientID).Set([]byte(types.CounterpartyKey), bz) -} - -// GetCounterparty gets the Counterparty for a given client identifier. -func (k *Keeper) GetCounterparty(ctx sdk.Context, clientID string) (types.Counterparty, bool) { - store := k.ClientStore(ctx, clientID) - bz := store.Get([]byte(types.CounterpartyKey)) - if len(bz) == 0 { - return types.Counterparty{}, false - } - - var counterparty types.Counterparty - k.cdc.MustUnmarshal(bz, &counterparty) - return counterparty, true -} - // GetCreator returns the creator of the client. func (k *Keeper) GetCreator(ctx sdk.Context, clientID string) (string, bool) { bz := k.ClientStore(ctx, clientID).Get([]byte(types.CreatorKey)) diff --git a/modules/core/02-client/types/client.go b/modules/core/02-client/types/client.go index 72e47ecf40b..6e3df24694e 100644 --- a/modules/core/02-client/types/client.go +++ b/modules/core/02-client/types/client.go @@ -12,7 +12,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/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" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -65,27 +64,6 @@ func (ics IdentifiedClientStates) Sort() IdentifiedClientStates { return ics } -// NewCounterparty creates a new Counterparty instance -func NewCounterparty(clientID string, merklePathPrefix *commitmenttypes.MerklePath) Counterparty { - return Counterparty{ - ClientId: clientID, - MerklePathPrefix: merklePathPrefix, - } -} - -// Validate validates the Counterparty -func (c Counterparty) Validate() error { - if err := host.ClientIdentifierValidator(c.ClientId); err != nil { - return err - } - - if c.MerklePathPrefix.Empty() { - return errorsmod.Wrap(ErrInvalidCounterparty, "prefix cannot be empty") - } - - return nil -} - // NewConsensusStateWithHeight creates a new ConsensusStateWithHeight instance func NewConsensusStateWithHeight(height Height, consensusState exported.ConsensusState) ConsensusStateWithHeight { msg, ok := consensusState.(proto.Message) diff --git a/modules/core/02-client/types/client.pb.go b/modules/core/02-client/types/client.pb.go index 12a978e9e33..0a61762a377 100644 --- a/modules/core/02-client/types/client.pb.go +++ b/modules/core/02-client/types/client.pb.go @@ -8,7 +8,6 @@ import ( types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" - v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" io "io" math "math" math_bits "math/bits" @@ -193,61 +192,6 @@ func (m *ClientConsensusStates) GetConsensusStates() []ConsensusStateWithHeight return nil } -// Counterparty defines the counterparty for a light client to implement IBC eureka protocol -type Counterparty struct { - // the client identifier of the counterparty chain - ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` - // the merkle path that all ICS24 paths will be stored under - MerklePathPrefix *v2.MerklePath `protobuf:"bytes,2,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix,omitempty"` -} - -func (m *Counterparty) Reset() { *m = Counterparty{} } -func (m *Counterparty) String() string { return proto.CompactTextString(m) } -func (*Counterparty) ProtoMessage() {} -func (*Counterparty) Descriptor() ([]byte, []int) { - return fileDescriptor_b6bc4c8185546947, []int{3} -} -func (m *Counterparty) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Counterparty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Counterparty.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 *Counterparty) XXX_Merge(src proto.Message) { - xxx_messageInfo_Counterparty.Merge(m, src) -} -func (m *Counterparty) XXX_Size() int { - return m.Size() -} -func (m *Counterparty) XXX_DiscardUnknown() { - xxx_messageInfo_Counterparty.DiscardUnknown(m) -} - -var xxx_messageInfo_Counterparty proto.InternalMessageInfo - -func (m *Counterparty) GetClientId() string { - if m != nil { - return m.ClientId - } - return "" -} - -func (m *Counterparty) GetMerklePathPrefix() *v2.MerklePath { - if m != nil { - return m.MerklePathPrefix - } - return nil -} - // Height is a monotonically increasing data type // that can be compared against another Height for the purposes of updating and // freezing clients @@ -271,7 +215,7 @@ type Height struct { func (m *Height) Reset() { *m = Height{} } func (*Height) ProtoMessage() {} func (*Height) Descriptor() ([]byte, []int) { - return fileDescriptor_b6bc4c8185546947, []int{4} + return fileDescriptor_b6bc4c8185546947, []int{3} } func (m *Height) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -312,7 +256,7 @@ func (m *Params) Reset() { *m = Params{} } func (m *Params) String() string { return proto.CompactTextString(m) } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_b6bc4c8185546947, []int{5} + return fileDescriptor_b6bc4c8185546947, []int{4} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -352,7 +296,6 @@ func init() { proto.RegisterType((*IdentifiedClientState)(nil), "ibc.core.client.v1.IdentifiedClientState") proto.RegisterType((*ConsensusStateWithHeight)(nil), "ibc.core.client.v1.ConsensusStateWithHeight") proto.RegisterType((*ClientConsensusStates)(nil), "ibc.core.client.v1.ClientConsensusStates") - proto.RegisterType((*Counterparty)(nil), "ibc.core.client.v1.Counterparty") proto.RegisterType((*Height)(nil), "ibc.core.client.v1.Height") proto.RegisterType((*Params)(nil), "ibc.core.client.v1.Params") } @@ -360,40 +303,36 @@ func init() { func init() { proto.RegisterFile("ibc/core/client/v1/client.proto", fileDescriptor_b6bc4c8185546947) } var fileDescriptor_b6bc4c8185546947 = []byte{ - // 523 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0xb6, 0xdb, 0x2a, 0x6a, 0x2e, 0x55, 0x52, 0x99, 0x56, 0x0a, 0x41, 0x72, 0x22, 0x2f, 0xcd, - 0x40, 0x7d, 0xc4, 0x0c, 0x14, 0x04, 0x03, 0xc9, 0x42, 0x07, 0x50, 0x64, 0x06, 0x24, 0x24, 0x64, - 0xf9, 0xc7, 0xc5, 0x3e, 0xe1, 0xf3, 0x59, 0xbe, 0xb3, 0x21, 0x03, 0x3b, 0x13, 0x42, 0x62, 0x61, - 0xec, 0x9f, 0xd3, 0xb1, 0x23, 0x53, 0x85, 0x92, 0x8d, 0xbf, 0x02, 0xf9, 0xee, 0x42, 0x9a, 0x52, - 0x2a, 0xb6, 0xf7, 0xe3, 0x7b, 0xfe, 0xbe, 0xf7, 0x3d, 0x1f, 0xe8, 0xe3, 0x20, 0x84, 0x21, 0x2d, - 0x10, 0x0c, 0x53, 0x8c, 0x32, 0x0e, 0xab, 0x91, 0x8a, 0xec, 0xbc, 0xa0, 0x9c, 0x1a, 0x06, 0x0e, - 0x42, 0xbb, 0x06, 0xd8, 0xaa, 0x5c, 0x8d, 0x7a, 0x07, 0x31, 0x8d, 0xa9, 0x68, 0xc3, 0x3a, 0x92, - 0xc8, 0xde, 0xdd, 0x98, 0xd2, 0x38, 0x45, 0x50, 0x64, 0x41, 0x39, 0x83, 0x7e, 0x36, 0x57, 0xad, - 0xa3, 0x35, 0x0b, 0x25, 0x04, 0x73, 0x22, 0x98, 0x9c, 0x2b, 0x99, 0x04, 0x5a, 0x04, 0x1c, 0x9e, - 0x46, 0x28, 0xe3, 0x78, 0x86, 0x51, 0x34, 0x11, 0x84, 0xaf, 0xb9, 0xcf, 0x91, 0x71, 0x0f, 0x34, - 0x25, 0xbf, 0x87, 0xa3, 0xae, 0x3e, 0xd0, 0x87, 0x4d, 0x77, 0x57, 0x16, 0x4e, 0x23, 0xe3, 0x11, - 0xd8, 0x53, 0x4d, 0x56, 0x83, 0xbb, 0x5b, 0x03, 0x7d, 0xd8, 0x72, 0x0e, 0x6c, 0x29, 0xc8, 0x5e, - 0x09, 0xb2, 0x9f, 0x67, 0x73, 0xb7, 0x15, 0xae, 0xbf, 0x6a, 0x7d, 0xd3, 0x41, 0x77, 0x42, 0x33, - 0x86, 0x32, 0x56, 0x32, 0x51, 0x7a, 0x83, 0x79, 0xf2, 0x02, 0xe1, 0x38, 0xe1, 0xc6, 0x09, 0x68, - 0x24, 0x22, 0x12, 0x7c, 0x2d, 0xa7, 0x67, 0xff, 0x6d, 0x85, 0x2d, 0xb1, 0xe3, 0x9d, 0xf3, 0xcb, - 0xbe, 0xe6, 0x2a, 0xbc, 0xf1, 0x0c, 0x74, 0xc2, 0xd5, 0x57, 0xff, 0x43, 0x52, 0x3b, 0xdc, 0x90, - 0x50, 0xab, 0x3a, 0x94, 0xbb, 0x6f, 0x6a, 0x63, 0xb7, 0xbb, 0xf0, 0x0e, 0xec, 0x5f, 0x63, 0x65, - 0xdd, 0xad, 0xc1, 0xf6, 0xb0, 0xe5, 0xdc, 0xbf, 0x49, 0xf9, 0xbf, 0xf6, 0x56, 0xbb, 0x74, 0x36, - 0x45, 0x31, 0xeb, 0x13, 0xd8, 0x9b, 0xd0, 0x32, 0xe3, 0xa8, 0xc8, 0xfd, 0x82, 0xcf, 0x6f, 0xd7, - 0x32, 0x05, 0x06, 0x41, 0xc5, 0xfb, 0x14, 0x79, 0xb9, 0xcf, 0x13, 0x2f, 0x2f, 0xd0, 0x0c, 0x7f, - 0x54, 0x26, 0x58, 0x57, 0xd4, 0xac, 0xef, 0x5f, 0x39, 0xf6, 0x4b, 0x31, 0x31, 0xf5, 0x79, 0xe2, - 0xee, 0x93, 0x3f, 0xf1, 0x54, 0xcc, 0x5a, 0x5f, 0x74, 0xd0, 0x50, 0x87, 0x79, 0x0a, 0x3a, 0x05, - 0xaa, 0x30, 0xc3, 0x34, 0xf3, 0xb2, 0x92, 0x04, 0xa8, 0x10, 0xfc, 0x3b, 0xe3, 0x3b, 0xbf, 0x2e, - 0xfb, 0xd7, 0x5b, 0x6e, 0x7b, 0x55, 0x78, 0x25, 0xf2, 0x8d, 0x69, 0x75, 0xdf, 0xad, 0x1b, 0xa6, - 0x65, 0x6b, 0x3d, 0x2d, 0xb9, 0x9f, 0xec, 0x7e, 0x3e, 0xeb, 0x6b, 0xdf, 0xcf, 0xfa, 0x9a, 0x35, - 0x02, 0x8d, 0xa9, 0x5f, 0xf8, 0x84, 0x19, 0x47, 0xa0, 0xe3, 0xa7, 0x29, 0xfd, 0x80, 0x22, 0x4f, - 0x1a, 0xc0, 0xba, 0xfa, 0x60, 0x7b, 0xd8, 0x74, 0xdb, 0xaa, 0x2c, 0x8f, 0xc9, 0xc6, 0xee, 0xf9, - 0xc2, 0xd4, 0x2f, 0x16, 0xa6, 0xfe, 0x73, 0x61, 0xea, 0x5f, 0x97, 0xa6, 0x76, 0xb1, 0x34, 0xb5, - 0x1f, 0x4b, 0x53, 0x7b, 0x7b, 0x12, 0x63, 0x9e, 0x94, 0x41, 0x6d, 0x08, 0x0c, 0x29, 0x23, 0x94, - 0x41, 0x1c, 0x84, 0xc7, 0x31, 0x85, 0xd5, 0x63, 0x48, 0x68, 0x54, 0xa6, 0x88, 0xc9, 0x07, 0xf4, - 0xc0, 0x39, 0x56, 0x2f, 0x95, 0xcf, 0x73, 0xc4, 0x82, 0x86, 0xf8, 0x95, 0x1e, 0xfe, 0x0e, 0x00, - 0x00, 0xff, 0xff, 0xa8, 0xfc, 0xb8, 0x84, 0xc9, 0x03, 0x00, 0x00, + // 456 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xf6, 0xa5, 0x55, 0xd4, 0x5c, 0x50, 0x82, 0x4c, 0x2b, 0x99, 0x20, 0xd9, 0x51, 0x16, 0x32, + 0xd0, 0x3b, 0x12, 0x06, 0x0a, 0x82, 0x81, 0x74, 0xa1, 0x0b, 0x42, 0x66, 0x40, 0x42, 0x42, 0x91, + 0x7d, 0xbe, 0xda, 0x27, 0xd9, 0x77, 0x95, 0xef, 0x6c, 0x94, 0x7f, 0xc0, 0x84, 0x90, 0x58, 0x18, + 0xfb, 0x73, 0x3a, 0x76, 0x64, 0xaa, 0x50, 0xb2, 0xf1, 0x2b, 0x90, 0xef, 0x2e, 0xaa, 0x5c, 0x0a, + 0x62, 0x7b, 0xf7, 0xbe, 0xef, 0xbd, 0xef, 0xfb, 0x5e, 0x62, 0x18, 0xb0, 0x98, 0x60, 0x22, 0x4a, + 0x8a, 0x49, 0xce, 0x28, 0x57, 0xb8, 0x9e, 0xd9, 0x0a, 0x9d, 0x95, 0x42, 0x09, 0xd7, 0x65, 0x31, + 0x41, 0x0d, 0x01, 0xd9, 0x76, 0x3d, 0x1b, 0xed, 0xa7, 0x22, 0x15, 0x1a, 0xc6, 0x4d, 0x65, 0x98, + 0xa3, 0xfb, 0xa9, 0x10, 0x69, 0x4e, 0xb1, 0x7e, 0xc5, 0xd5, 0x29, 0x8e, 0xf8, 0xca, 0x40, 0x93, + 0x02, 0x1e, 0x9c, 0x24, 0x94, 0x2b, 0x76, 0xca, 0x68, 0x72, 0xac, 0xf7, 0xbc, 0x53, 0x91, 0xa2, + 0xee, 0x03, 0xd8, 0x33, 0x6b, 0x97, 0x2c, 0xf1, 0xc0, 0x18, 0x4c, 0x7b, 0xe1, 0x9e, 0x69, 0x9c, + 0x24, 0xee, 0x53, 0x78, 0xc7, 0x82, 0xb2, 0x21, 0x7b, 0x9d, 0x31, 0x98, 0xf6, 0xe7, 0xfb, 0xc8, + 0xe8, 0xa0, 0xad, 0x0e, 0x7a, 0xc5, 0x57, 0x61, 0x9f, 0x5c, 0x6f, 0x9d, 0x7c, 0x03, 0xd0, 0x3b, + 0x16, 0x5c, 0x52, 0x2e, 0x2b, 0xa9, 0x5b, 0xef, 0x99, 0xca, 0x5e, 0x53, 0x96, 0x66, 0xca, 0x3d, + 0x82, 0xdd, 0x4c, 0x57, 0x5a, 0xaf, 0x3f, 0x1f, 0xa1, 0x3f, 0x13, 0x22, 0xc3, 0x5d, 0xec, 0x5e, + 0x5c, 0x05, 0x4e, 0x68, 0xf9, 0xee, 0x4b, 0x38, 0x24, 0xdb, 0xad, 0xff, 0x61, 0x69, 0x40, 0x5a, + 0x16, 0x1a, 0x57, 0x07, 0x26, 0x7b, 0xdb, 0x9b, 0xfc, 0xf7, 0x15, 0x3e, 0xc2, 0xbb, 0x37, 0x54, + 0xa5, 0xd7, 0x19, 0xef, 0x4c, 0xfb, 0xf3, 0x47, 0xb7, 0x39, 0xff, 0x5b, 0x6e, 0x9b, 0x65, 0xd8, + 0x36, 0x25, 0x27, 0x5f, 0x00, 0xec, 0xda, 0xcb, 0xbc, 0x80, 0xc3, 0x92, 0xd6, 0x4c, 0x32, 0xc1, + 0x97, 0xbc, 0x2a, 0x62, 0x5a, 0x6a, 0x33, 0xbb, 0x8b, 0x7b, 0xbf, 0xae, 0x82, 0x9b, 0x50, 0x38, + 0xd8, 0x36, 0xde, 0xe8, 0x77, 0x6b, 0xda, 0x1e, 0xb8, 0x73, 0xcb, 0xb4, 0x81, 0xae, 0xa7, 0x8d, + 0xf6, 0xf3, 0xbd, 0xcf, 0xe7, 0x81, 0xf3, 0xfd, 0x3c, 0x70, 0x26, 0x33, 0xd8, 0x7d, 0x1b, 0x95, + 0x51, 0x21, 0xdd, 0x87, 0x70, 0x18, 0xe5, 0xb9, 0xf8, 0x44, 0x93, 0xa5, 0xc9, 0x27, 0x3d, 0x30, + 0xde, 0x99, 0xf6, 0xc2, 0x81, 0x6d, 0x9b, 0x6b, 0xca, 0x45, 0x78, 0xb1, 0xf6, 0xc1, 0xe5, 0xda, + 0x07, 0x3f, 0xd7, 0x3e, 0xf8, 0xba, 0xf1, 0x9d, 0xcb, 0x8d, 0xef, 0xfc, 0xd8, 0xf8, 0xce, 0x87, + 0xa3, 0x94, 0xa9, 0xac, 0x8a, 0x11, 0x11, 0x05, 0x26, 0x42, 0x16, 0x42, 0x62, 0x16, 0x93, 0xc3, + 0x54, 0xe0, 0xfa, 0x19, 0x2e, 0x44, 0x52, 0xe5, 0x54, 0x9a, 0xbf, 0xff, 0xe3, 0xf9, 0xa1, 0xfd, + 0x02, 0xd4, 0xea, 0x8c, 0xca, 0xb8, 0xab, 0x7f, 0xcb, 0x27, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, + 0x94, 0x27, 0x25, 0x2c, 0x21, 0x03, 0x00, 0x00, } func (m *IdentifiedClientState) Marshal() (dAtA []byte, err error) { @@ -527,48 +466,6 @@ func (m *ClientConsensusStates) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *Counterparty) 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 *Counterparty) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Counterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.MerklePathPrefix != nil { - { - size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintClient(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.ClientId) > 0 { - i -= len(m.ClientId) - copy(dAtA[i:], m.ClientId) - i = encodeVarintClient(dAtA, i, uint64(len(m.ClientId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *Height) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -696,23 +593,6 @@ func (m *ClientConsensusStates) Size() (n int) { return n } -func (m *Counterparty) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ClientId) - if l > 0 { - n += 1 + l + sovClient(uint64(l)) - } - if m.MerklePathPrefix != nil { - l = m.MerklePathPrefix.Size() - n += 1 + l + sovClient(uint64(l)) - } - return n -} - func (m *Height) Size() (n int) { if m == nil { return 0 @@ -1102,124 +982,6 @@ func (m *ClientConsensusStates) Unmarshal(dAtA []byte) error { } return nil } -func (m *Counterparty) 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 ErrIntOverflowClient - } - 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: Counterparty: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Counterparty: 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 ErrIntOverflowClient - } - 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 ErrInvalidLengthClient - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthClient - } - 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 ErrIntOverflowClient - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthClient - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthClient - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.MerklePathPrefix == nil { - m.MerklePathPrefix = &v2.MerklePath{} - } - if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipClient(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthClient - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *Height) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/modules/core/02-client/types/client_test.go b/modules/core/02-client/types/client_test.go index 21769232cb1..43b5b1c7f58 100644 --- a/modules/core/02-client/types/client_test.go +++ b/modules/core/02-client/types/client_test.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/ibc-go/v9/modules/core/02-client/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" ibctesting "github.com/cosmos/ibc-go/v9/testing" ) @@ -88,46 +86,3 @@ func TestValidateClientType(t *testing.T) { } } } - -func TestValidateCounterparty(t *testing.T) { - testCases := []struct { - name string - clientID string - merklePathPrefix commitmenttypes.MerklePath - expError error - }{ - { - "success", - ibctesting.FirstClientID, - commitmenttypes.NewMerklePath([]byte("ibc")), - nil, - }, - { - "failure: invalid client id", - "", - commitmenttypes.NewMerklePath([]byte("ibc")), - host.ErrInvalidID, - }, - { - "failure: empty merkle path prefix", - ibctesting.FirstClientID, - commitmenttypes.NewMerklePath(), - types.ErrInvalidCounterparty, - }, - } - - for _, tc := range testCases { - tc := tc - - counterparty := types.NewCounterparty(tc.clientID, &tc.merklePathPrefix) - err := counterparty.Validate() - - expPass := tc.expError == nil - if expPass { - require.NoError(t, err, tc.name) - } else { - require.Error(t, err, tc.name) - require.ErrorIs(t, err, tc.expError) - } - } -} diff --git a/modules/core/02-client/types/codec.go b/modules/core/02-client/types/codec.go index 9e239c83564..082970cd598 100644 --- a/modules/core/02-client/types/codec.go +++ b/modules/core/02-client/types/codec.go @@ -45,7 +45,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { &MsgRecoverClient{}, &MsgIBCSoftwareUpgrade{}, &MsgUpdateParams{}, - &MsgProvideCounterparty{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 116e322ac6d..62d906bc40c 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -38,5 +38,4 @@ var ( ErrFailedNonMembershipVerification = errorsmod.Register(SubModuleName, 31, "non-membership verification failed") ErrRouteNotFound = errorsmod.Register(SubModuleName, 32, "light client module route not found") ErrClientTypeNotSupported = errorsmod.Register(SubModuleName, 33, "client type not supported") - ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") ) diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index e8e0d100555..e35b7bbbaad 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -7,7 +7,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" 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" "github.com/cosmos/ibc-go/v9/modules/core/exported" @@ -21,7 +20,6 @@ var ( _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.Msg = (*MsgIBCSoftwareUpgrade)(nil) _ sdk.Msg = (*MsgRecoverClient)(nil) - _ sdk.Msg = (*MsgProvideCounterparty)(nil) _ sdk.HasValidateBasic = (*MsgCreateClient)(nil) _ sdk.HasValidateBasic = (*MsgUpdateClient)(nil) @@ -30,7 +28,6 @@ var ( _ sdk.HasValidateBasic = (*MsgUpdateParams)(nil) _ sdk.HasValidateBasic = (*MsgIBCSoftwareUpgrade)(nil) _ sdk.HasValidateBasic = (*MsgRecoverClient)(nil) - _ sdk.HasValidateBasic = (*MsgProvideCounterparty)(nil) _ codectypes.UnpackInterfacesMessage = (*MsgCreateClient)(nil) _ codectypes.UnpackInterfacesMessage = (*MsgUpdateClient)(nil) @@ -268,34 +265,6 @@ func (msg *MsgRecoverClient) ValidateBasic() error { return nil } -// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance -func NewMsgProvideCounterparty(signer, clientID, counterpartyID string, merklePathPrefix *commitmenttypes.MerklePath) *MsgProvideCounterparty { - counterparty := NewCounterparty(counterpartyID, merklePathPrefix) - - return &MsgProvideCounterparty{ - Signer: signer, - ClientId: clientID, - Counterparty: counterparty, - } -} - -// 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.ClientIdentifierValidator(msg.ClientId); err != nil { - return err - } - - if err := msg.Counterparty.Validate(); err != nil { - return err - } - - return nil -} - // NewMsgIBCSoftwareUpgrade creates a new MsgIBCSoftwareUpgrade instance func NewMsgIBCSoftwareUpgrade(signer string, plan upgradetypes.Plan, upgradedClientState exported.ClientState) (*MsgIBCSoftwareUpgrade, error) { anyClient, err := PackClientState(upgradedClientState) diff --git a/modules/core/02-client/types/tx.pb.go b/modules/core/02-client/types/tx.pb.go index fdca53cd3c9..5a22491005e 100644 --- a/modules/core/02-client/types/tx.pb.go +++ b/modules/core/02-client/types/tx.pb.go @@ -448,88 +448,6 @@ func (m *MsgRecoverClientResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRecoverClientResponse proto.InternalMessageInfo -// 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 { - // client unique identifier - ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` - // counterparty client - Counterparty Counterparty `protobuf:"bytes,2,opt,name=counterparty,proto3" json:"counterparty"` - // 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_cb5dc4651eb49a04, []int{10} -} -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_cb5dc4651eb49a04, []int{11} -} -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 - // MsgIBCSoftwareUpgrade defines the message used to schedule an upgrade of an IBC client using a v1 governance proposal type MsgIBCSoftwareUpgrade struct { Plan types1.Plan `protobuf:"bytes,1,opt,name=plan,proto3" json:"plan"` @@ -550,7 +468,7 @@ func (m *MsgIBCSoftwareUpgrade) Reset() { *m = MsgIBCSoftwareUpgrade{} } func (m *MsgIBCSoftwareUpgrade) String() string { return proto.CompactTextString(m) } func (*MsgIBCSoftwareUpgrade) ProtoMessage() {} func (*MsgIBCSoftwareUpgrade) Descriptor() ([]byte, []int) { - return fileDescriptor_cb5dc4651eb49a04, []int{12} + return fileDescriptor_cb5dc4651eb49a04, []int{10} } func (m *MsgIBCSoftwareUpgrade) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -608,7 +526,7 @@ func (m *MsgIBCSoftwareUpgradeResponse) Reset() { *m = MsgIBCSoftwareUpg func (m *MsgIBCSoftwareUpgradeResponse) String() string { return proto.CompactTextString(m) } func (*MsgIBCSoftwareUpgradeResponse) ProtoMessage() {} func (*MsgIBCSoftwareUpgradeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_cb5dc4651eb49a04, []int{13} + return fileDescriptor_cb5dc4651eb49a04, []int{11} } func (m *MsgIBCSoftwareUpgradeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -651,7 +569,7 @@ func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParams) ProtoMessage() {} func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_cb5dc4651eb49a04, []int{14} + return fileDescriptor_cb5dc4651eb49a04, []int{12} } func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -688,7 +606,7 @@ func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateParamsResponse) ProtoMessage() {} func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_cb5dc4651eb49a04, []int{15} + return fileDescriptor_cb5dc4651eb49a04, []int{13} } func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -728,8 +646,6 @@ func init() { proto.RegisterType((*MsgSubmitMisbehaviourResponse)(nil), "ibc.core.client.v1.MsgSubmitMisbehaviourResponse") proto.RegisterType((*MsgRecoverClient)(nil), "ibc.core.client.v1.MsgRecoverClient") proto.RegisterType((*MsgRecoverClientResponse)(nil), "ibc.core.client.v1.MsgRecoverClientResponse") - proto.RegisterType((*MsgProvideCounterparty)(nil), "ibc.core.client.v1.MsgProvideCounterparty") - proto.RegisterType((*MsgProvideCounterpartyResponse)(nil), "ibc.core.client.v1.MsgProvideCounterpartyResponse") proto.RegisterType((*MsgIBCSoftwareUpgrade)(nil), "ibc.core.client.v1.MsgIBCSoftwareUpgrade") proto.RegisterType((*MsgIBCSoftwareUpgradeResponse)(nil), "ibc.core.client.v1.MsgIBCSoftwareUpgradeResponse") proto.RegisterType((*MsgUpdateParams)(nil), "ibc.core.client.v1.MsgUpdateParams") @@ -739,63 +655,59 @@ func init() { func init() { proto.RegisterFile("ibc/core/client/v1/tx.proto", fileDescriptor_cb5dc4651eb49a04) } var fileDescriptor_cb5dc4651eb49a04 = []byte{ - // 886 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x31, 0x73, 0xe3, 0x44, - 0x14, 0xb6, 0x1c, 0x9f, 0x87, 0x6c, 0x7c, 0x67, 0x6e, 0xcf, 0x77, 0xe7, 0xd3, 0x71, 0xb6, 0xc7, - 0x5c, 0x11, 0x0c, 0x91, 0x62, 0x33, 0x03, 0x21, 0x40, 0x91, 0xb8, 0x21, 0xcc, 0x78, 0x26, 0xa3, - 0x0c, 0x0d, 0x8d, 0x23, 0xc9, 0x6b, 0x45, 0x8c, 0xa5, 0xd5, 0x68, 0x57, 0x06, 0x77, 0x0c, 0x15, - 0x25, 0x05, 0x0d, 0x1d, 0x35, 0x55, 0x86, 0x1f, 0x40, 0xc7, 0x4c, 0xca, 0x94, 0x54, 0x0c, 0x24, - 0x45, 0xfe, 0x06, 0x23, 0xed, 0x5a, 0x59, 0xc9, 0x92, 0x10, 0x43, 0x27, 0xe9, 0x7d, 0xef, 0xed, - 0xf7, 0xbd, 0x7d, 0xfb, 0xad, 0xc0, 0x4b, 0xdb, 0x30, 0x55, 0x13, 0xfb, 0x48, 0x35, 0x17, 0x36, - 0x72, 0xa9, 0xba, 0x1c, 0xaa, 0xf4, 0x1b, 0xc5, 0xf3, 0x31, 0xc5, 0x10, 0xda, 0x86, 0xa9, 0x84, - 0x41, 0x85, 0x05, 0x95, 0xe5, 0x50, 0x7e, 0x6e, 0x62, 0xe2, 0x60, 0xa2, 0x3a, 0xc4, 0x0a, 0xb1, - 0x0e, 0xb1, 0x18, 0x58, 0x7e, 0xcd, 0x03, 0x81, 0x67, 0xf9, 0xfa, 0x0c, 0xa9, 0xcb, 0xa1, 0x81, - 0xa8, 0x3e, 0x5c, 0xbf, 0x73, 0x54, 0xcb, 0xc2, 0x16, 0x8e, 0x1e, 0xd5, 0xf0, 0x89, 0x7f, 0x7d, - 0x61, 0x61, 0x6c, 0x2d, 0x90, 0x1a, 0xbd, 0x19, 0xc1, 0x5c, 0xd5, 0xdd, 0x15, 0x0f, 0x75, 0x33, - 0x08, 0x72, 0x36, 0x11, 0xa0, 0xff, 0xab, 0x04, 0x9a, 0x13, 0x62, 0x8d, 0x7d, 0xa4, 0x53, 0x34, - 0x8e, 0x22, 0xf0, 0x43, 0xd0, 0x60, 0x98, 0x29, 0xa1, 0x3a, 0x45, 0x6d, 0xa9, 0x27, 0xed, 0xee, - 0x8c, 0x5a, 0x0a, 0x5b, 0x46, 0x59, 0x2f, 0xa3, 0x1c, 0xb9, 0x2b, 0x6d, 0x87, 0x21, 0xcf, 0x42, - 0x20, 0xfc, 0x14, 0x34, 0x4d, 0xec, 0x12, 0xe4, 0x92, 0x80, 0xf0, 0xdc, 0x6a, 0x41, 0xee, 0xa3, - 0x18, 0xcc, 0xd2, 0x9f, 0x81, 0x3a, 0xb1, 0x2d, 0x17, 0xf9, 0xed, 0xad, 0x9e, 0xb4, 0xbb, 0xad, - 0xf1, 0xb7, 0xc3, 0xe6, 0xf7, 0x3f, 0x77, 0x2b, 0xdf, 0xdd, 0x5d, 0x0e, 0xf8, 0x87, 0xfe, 0x27, - 0xe0, 0x79, 0x8a, 0xb3, 0x86, 0x88, 0x17, 0x16, 0x83, 0x2f, 0xc1, 0x36, 0xe7, 0x6e, 0xcf, 0x22, - 0xe2, 0xdb, 0xda, 0x1b, 0xec, 0xc3, 0xc9, 0xec, 0xb0, 0x16, 0x16, 0xea, 0xff, 0xc8, 0x24, 0x7f, - 0xe1, 0xcd, 0xee, 0x25, 0x17, 0xa5, 0xc1, 0x8f, 0xc1, 0x23, 0x1e, 0x74, 0x10, 0x21, 0xba, 0x55, - 0xac, 0xea, 0x21, 0xc3, 0x4e, 0x18, 0xb4, 0xbc, 0xa8, 0x17, 0x91, 0x28, 0x91, 0xd5, 0x5a, 0x54, - 0xff, 0xf7, 0x2a, 0x78, 0x33, 0x8a, 0x45, 0xb3, 0x50, 0x86, 0x72, 0x7a, 0x0b, 0xab, 0xff, 0x63, - 0x0b, 0xb7, 0xfe, 0xc3, 0x16, 0xee, 0x83, 0x96, 0xe7, 0x63, 0x3c, 0x9f, 0xf2, 0xb9, 0x9d, 0xb2, - 0xda, 0xed, 0x5a, 0x4f, 0xda, 0x6d, 0x68, 0x30, 0x8a, 0x25, 0x65, 0x1c, 0x81, 0x57, 0xa9, 0x8c, - 0xd4, 0xf2, 0x0f, 0xa2, 0x54, 0x39, 0x91, 0x9a, 0x37, 0x37, 0xf5, 0xe2, 0x16, 0xcb, 0xa0, 0x9d, - 0x6e, 0x63, 0xdc, 0xe3, 0x9f, 0x24, 0xf0, 0x74, 0x42, 0xac, 0xb3, 0xc0, 0x70, 0x6c, 0x3a, 0xb1, - 0x89, 0x81, 0x2e, 0xf4, 0xa5, 0x8d, 0x03, 0xbf, 0xb8, 0xd1, 0x07, 0xa0, 0xe1, 0x08, 0xe0, 0xc2, - 0x46, 0x27, 0x90, 0xb9, 0x83, 0xf1, 0x38, 0xc5, 0xba, 0x2d, 0xf5, 0xbb, 0xe0, 0x55, 0x26, 0x35, - 0x91, 0x7c, 0x38, 0x20, 0x1a, 0x32, 0xf1, 0x12, 0xf9, 0xbc, 0xb3, 0x03, 0xf0, 0x98, 0x04, 0xc6, - 0x57, 0xc8, 0xa4, 0xd3, 0x34, 0xff, 0x26, 0x0f, 0x8c, 0xd7, 0x32, 0xf6, 0x41, 0x8b, 0x04, 0x06, - 0xa1, 0x36, 0x0d, 0x28, 0x12, 0xe0, 0xd5, 0x08, 0x0e, 0xef, 0x63, 0x71, 0x46, 0xe9, 0xb9, 0x66, - 0x4d, 0x4f, 0x50, 0x8b, 0x79, 0xff, 0x22, 0x81, 0x67, 0x13, 0x62, 0x9d, 0xfa, 0x78, 0x69, 0x87, - 0xdb, 0x1a, 0xb8, 0x14, 0xf9, 0x9e, 0xee, 0xd3, 0x55, 0x71, 0xd7, 0x3f, 0x07, 0x0d, 0x53, 0x00, - 0xf3, 0xae, 0xf7, 0x94, 0x4d, 0xc7, 0x55, 0xc4, 0xa2, 0xc7, 0xb5, 0xab, 0x3f, 0xbb, 0x15, 0x2d, - 0x91, 0x5b, 0x5e, 0x48, 0x0f, 0x74, 0xb2, 0xb9, 0xc6, 0x72, 0x7e, 0x63, 0x33, 0x74, 0x72, 0x3c, - 0x3e, 0xc3, 0x73, 0xfa, 0xb5, 0xee, 0x23, 0x3e, 0x6b, 0xf0, 0x03, 0x50, 0xf3, 0x16, 0xba, 0xcb, - 0xad, 0xf4, 0x2d, 0x85, 0xb9, 0xbd, 0xb2, 0x76, 0x77, 0xee, 0xf6, 0xca, 0xe9, 0x42, 0x77, 0x39, - 0xc9, 0x08, 0x0f, 0x3f, 0x03, 0x4f, 0x39, 0x66, 0x36, 0x2d, 0x7d, 0xa0, 0x9f, 0xac, 0x53, 0xc6, - 0xc2, 0xc1, 0xce, 0x93, 0xb9, 0x23, 0x4a, 0x64, 0x83, 0xb6, 0xc9, 0x3f, 0x56, 0x48, 0x05, 0xeb, - 0x3c, 0xd5, 0x7d, 0xdd, 0x21, 0x42, 0x61, 0x49, 0x2c, 0x0c, 0x0f, 0x40, 0xdd, 0x8b, 0x10, 0x9c, - 0xab, 0x9c, 0xb5, 0x3b, 0xac, 0x06, 0x97, 0xcc, 0xf1, 0xc5, 0xd6, 0xc8, 0x32, 0xd6, 0x84, 0x46, - 0x7f, 0xd7, 0xc1, 0xd6, 0x84, 0x58, 0xf0, 0x1c, 0x34, 0x12, 0x77, 0xd8, 0xdb, 0x59, 0xab, 0xa5, - 0x2e, 0x0d, 0xf9, 0xdd, 0x12, 0xa0, 0xf8, 0x66, 0x39, 0x07, 0x8d, 0xc4, 0x95, 0x91, 0xb7, 0x82, - 0x08, 0xca, 0x5d, 0x21, 0xcb, 0xe6, 0xa1, 0x09, 0x1e, 0x26, 0xbd, 0xf1, 0x75, 0x6e, 0xb6, 0x80, - 0x92, 0xdf, 0x2b, 0x83, 0x8a, 0x17, 0xf1, 0x01, 0xcc, 0xf0, 0xb8, 0x77, 0x72, 0x6a, 0x6c, 0x42, - 0xe5, 0x61, 0x69, 0xa8, 0x28, 0x2c, 0x69, 0x4d, 0x79, 0xc2, 0x12, 0xa8, 0x5c, 0x61, 0x99, 0x5e, - 0x02, 0x03, 0xf0, 0x24, 0xcb, 0x47, 0x06, 0x39, 0x45, 0x32, 0xb0, 0xf2, 0xa8, 0x3c, 0x56, 0xec, - 0x67, 0xc6, 0x79, 0xcf, 0xeb, 0xe7, 0x26, 0x34, 0xb7, 0x9f, 0xf9, 0xa7, 0x10, 0xce, 0x01, 0x14, - 0x07, 0x88, 0x1f, 0xc4, 0xe2, 0x81, 0x64, 0xa0, 0x7f, 0x19, 0xc8, 0xe4, 0xe1, 0x92, 0x1f, 0x7c, - 0x7b, 0x77, 0x39, 0x90, 0x8e, 0xb5, 0xab, 0x9b, 0x8e, 0x74, 0x7d, 0xd3, 0x91, 0xfe, 0xba, 0xe9, - 0x48, 0x3f, 0xdc, 0x76, 0x2a, 0xd7, 0xb7, 0x9d, 0xca, 0x1f, 0xb7, 0x9d, 0xca, 0x97, 0x07, 0x96, - 0x4d, 0x2f, 0x02, 0x43, 0x31, 0xb1, 0xa3, 0xf2, 0x1f, 0x58, 0xdb, 0x30, 0xf7, 0x2c, 0xac, 0x2e, - 0x3f, 0x52, 0x1d, 0x3c, 0x0b, 0x16, 0x88, 0xb0, 0xdf, 0xcf, 0xfd, 0xd1, 0x1e, 0xff, 0x03, 0xa5, - 0x2b, 0x0f, 0x11, 0xa3, 0x1e, 0x39, 0xd6, 0xfb, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x4a, 0xa4, - 0xb8, 0x24, 0x42, 0x0b, 0x00, 0x00, + // 819 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0x8e, 0xd3, 0x34, 0xa2, 0xd7, 0xb4, 0xa1, 0x47, 0x4a, 0x53, 0x97, 0x26, 0x55, 0xe8, 0x50, + 0x0a, 0xb5, 0x9b, 0x22, 0x41, 0x29, 0x30, 0xb4, 0x59, 0xe8, 0x10, 0xa9, 0x72, 0xc5, 0xc2, 0x92, + 0xda, 0xce, 0xc5, 0x35, 0x8a, 0x7d, 0x96, 0xef, 0x1c, 0xe8, 0x86, 0x98, 0x18, 0x19, 0x58, 0xd8, + 0xf8, 0x09, 0x15, 0x3f, 0x80, 0x0d, 0xa9, 0x63, 0x47, 0x26, 0x84, 0xda, 0xa1, 0x12, 0xbf, 0x02, + 0xd9, 0x77, 0x49, 0x6d, 0x27, 0x36, 0x41, 0x6c, 0xb1, 0xdf, 0xf7, 0xee, 0x7d, 0xdf, 0xbb, 0xf7, + 0xbe, 0x18, 0x2c, 0x99, 0x9a, 0x2e, 0xeb, 0xd8, 0x45, 0xb2, 0xde, 0x35, 0x91, 0x4d, 0xe5, 0x5e, + 0x5d, 0xa6, 0x6f, 0x25, 0xc7, 0xc5, 0x14, 0x43, 0x68, 0x6a, 0xba, 0xe4, 0x07, 0x25, 0x16, 0x94, + 0x7a, 0x75, 0x71, 0x41, 0xc7, 0xc4, 0xc2, 0x44, 0xb6, 0x88, 0xe1, 0x63, 0x2d, 0x62, 0x30, 0xb0, + 0xb8, 0xca, 0x03, 0x9e, 0x63, 0xb8, 0x6a, 0x1b, 0xc9, 0xbd, 0xba, 0x86, 0xa8, 0x5a, 0xef, 0x3f, + 0x73, 0x54, 0xc9, 0xc0, 0x06, 0x0e, 0x7e, 0xca, 0xfe, 0x2f, 0xfe, 0x76, 0xd1, 0xc0, 0xd8, 0xe8, + 0x22, 0x39, 0x78, 0xd2, 0xbc, 0x8e, 0xac, 0xda, 0x27, 0x3c, 0x54, 0x1d, 0x41, 0x90, 0xb3, 0x09, + 0x00, 0xb5, 0xaf, 0x02, 0x28, 0x36, 0x89, 0xd1, 0x70, 0x91, 0x4a, 0x51, 0x23, 0x88, 0xc0, 0xc7, + 0xa0, 0xc0, 0x30, 0x2d, 0x42, 0x55, 0x8a, 0xca, 0xc2, 0x8a, 0xb0, 0x36, 0xbd, 0x55, 0x92, 0x58, + 0x19, 0xa9, 0x5f, 0x46, 0xda, 0xb5, 0x4f, 0x94, 0x69, 0x86, 0x3c, 0xf4, 0x81, 0xf0, 0x39, 0x28, + 0xea, 0xd8, 0x26, 0xc8, 0x26, 0x1e, 0xe1, 0xb9, 0xd9, 0x94, 0xdc, 0xd9, 0x01, 0x98, 0xa5, 0xdf, + 0x06, 0x79, 0x62, 0x1a, 0x36, 0x72, 0xcb, 0x13, 0x2b, 0xc2, 0xda, 0x94, 0xc2, 0x9f, 0x76, 0x8a, + 0x1f, 0xbe, 0x54, 0x33, 0xef, 0xaf, 0x4e, 0xd7, 0xf9, 0x8b, 0xda, 0x33, 0xb0, 0x10, 0xe3, 0xac, + 0x20, 0xe2, 0xf8, 0x87, 0xc1, 0x25, 0x30, 0xc5, 0xb9, 0x9b, 0xed, 0x80, 0xf8, 0x94, 0x72, 0x83, + 0xbd, 0xd8, 0x6f, 0xef, 0xe4, 0xfc, 0x83, 0x6a, 0x9f, 0x98, 0xe4, 0x97, 0x4e, 0xfb, 0x5a, 0x72, + 0x5a, 0x1a, 0x7c, 0x0a, 0x66, 0x79, 0xd0, 0x42, 0x84, 0xa8, 0x46, 0xba, 0xaa, 0x19, 0x86, 0x6d, + 0x32, 0xe8, 0xf8, 0xa2, 0x16, 0x03, 0x51, 0x61, 0x56, 0x7d, 0x51, 0xb5, 0xef, 0x59, 0x70, 0x33, + 0x88, 0x05, 0xb3, 0x30, 0x0e, 0xe5, 0xf8, 0x15, 0x66, 0xff, 0xe3, 0x0a, 0x27, 0xfe, 0xe1, 0x0a, + 0x37, 0x41, 0xc9, 0x71, 0x31, 0xee, 0xb4, 0xf8, 0xdc, 0xb6, 0xd8, 0xd9, 0xe5, 0xdc, 0x8a, 0xb0, + 0x56, 0x50, 0x60, 0x10, 0x8b, 0xca, 0xd8, 0x05, 0xcb, 0xb1, 0x8c, 0x58, 0xf9, 0xc9, 0x20, 0x55, + 0x8c, 0xa4, 0x26, 0xcd, 0x4d, 0x3e, 0xbd, 0xc5, 0x22, 0x28, 0xc7, 0xdb, 0x38, 0xe8, 0xf1, 0x67, + 0x01, 0xcc, 0x37, 0x89, 0x71, 0xe8, 0x69, 0x96, 0x49, 0x9b, 0x26, 0xd1, 0xd0, 0xb1, 0xda, 0x33, + 0xb1, 0xe7, 0xa6, 0x37, 0x7a, 0x1b, 0x14, 0xac, 0x10, 0x38, 0xb5, 0xd1, 0x11, 0x64, 0xe2, 0x60, + 0xcc, 0xc5, 0x58, 0x97, 0x85, 0x5a, 0x15, 0x2c, 0x8f, 0xa4, 0x16, 0x26, 0xef, 0x0f, 0x88, 0x82, + 0x74, 0xdc, 0x43, 0x2e, 0xef, 0xec, 0x3a, 0x98, 0x23, 0x9e, 0xf6, 0x1a, 0xe9, 0xb4, 0x15, 0xe7, + 0x5f, 0xe4, 0x81, 0x46, 0x5f, 0xc6, 0x26, 0x28, 0x11, 0x4f, 0x23, 0xd4, 0xa4, 0x1e, 0x45, 0x21, + 0x78, 0x36, 0x80, 0xc3, 0xeb, 0xd8, 0x20, 0x63, 0xec, 0xb9, 0x66, 0x4d, 0x8f, 0x50, 0x1b, 0xf0, + 0xfe, 0xc6, 0x9a, 0xbe, 0xbf, 0xd7, 0x38, 0xc4, 0x1d, 0xfa, 0x46, 0x75, 0x11, 0xbf, 0x1c, 0xf8, + 0x08, 0xe4, 0x9c, 0xae, 0x6a, 0x73, 0xef, 0xb9, 0x23, 0x31, 0x7b, 0x94, 0xfa, 0x76, 0xc8, 0xed, + 0x51, 0x3a, 0xe8, 0xaa, 0xf6, 0x5e, 0xee, 0xec, 0x67, 0x35, 0xa3, 0x04, 0x78, 0xf8, 0x02, 0xcc, + 0x73, 0x4c, 0xbb, 0x35, 0xf6, 0x06, 0xdc, 0xea, 0xa7, 0x34, 0x42, 0x9b, 0x90, 0x24, 0x70, 0x3a, + 0x2c, 0x8e, 0xdd, 0xcc, 0x30, 0xff, 0x81, 0x42, 0x1a, 0xf2, 0x9a, 0x03, 0xd5, 0x55, 0x2d, 0x12, + 0x3a, 0x58, 0x08, 0x1f, 0x0c, 0xb7, 0x41, 0xde, 0x09, 0x10, 0x9c, 0xab, 0x28, 0x0d, 0xff, 0x81, + 0x48, 0xec, 0x0c, 0x2e, 0x99, 0xe3, 0xd3, 0xbd, 0x84, 0x65, 0xf4, 0x09, 0x6d, 0xfd, 0x9e, 0x04, + 0x13, 0x4d, 0x62, 0xc0, 0x23, 0x50, 0x88, 0x98, 0xfe, 0xdd, 0x51, 0xd5, 0x62, 0x2e, 0x2b, 0xde, + 0x1f, 0x03, 0x34, 0xb0, 0xe2, 0x23, 0x50, 0x88, 0x78, 0x6c, 0x52, 0x85, 0x30, 0x28, 0xb1, 0xc2, + 0x28, 0x5f, 0x84, 0x3a, 0x98, 0x89, 0x9a, 0xc9, 0x6a, 0x62, 0x76, 0x08, 0x25, 0x3e, 0x18, 0x07, + 0x35, 0x28, 0xe2, 0x02, 0x38, 0xc2, 0x14, 0xee, 0x25, 0x9c, 0x31, 0x0c, 0x15, 0xeb, 0x63, 0x43, + 0xc3, 0xc2, 0xa2, 0xbb, 0x9c, 0x24, 0x2c, 0x82, 0x4a, 0x14, 0x36, 0x72, 0xf9, 0x7c, 0x61, 0x23, + 0x16, 0x2f, 0x49, 0xd8, 0x30, 0x34, 0x51, 0x58, 0xf2, 0x3a, 0xc0, 0x0e, 0x80, 0xe1, 0x9b, 0xe4, + 0x1b, 0x91, 0x3e, 0x19, 0x0c, 0xf4, 0x97, 0xc9, 0x88, 0x4e, 0xb9, 0x38, 0xf9, 0xee, 0xea, 0x74, + 0x5d, 0xd8, 0x53, 0xce, 0x2e, 0x2a, 0xc2, 0xf9, 0x45, 0x45, 0xf8, 0x75, 0x51, 0x11, 0x3e, 0x5e, + 0x56, 0x32, 0xe7, 0x97, 0x95, 0xcc, 0x8f, 0xcb, 0x4a, 0xe6, 0xd5, 0xb6, 0x61, 0xd2, 0x63, 0x4f, + 0x93, 0x74, 0x6c, 0xc9, 0xfc, 0xd3, 0xcb, 0xd4, 0xf4, 0x0d, 0x03, 0xcb, 0xbd, 0x27, 0xb2, 0x85, + 0xdb, 0x5e, 0x17, 0x11, 0xf6, 0xe1, 0xb4, 0xb9, 0xb5, 0xc1, 0xbf, 0x9d, 0xe8, 0x89, 0x83, 0x88, + 0x96, 0x0f, 0xac, 0xe3, 0xe1, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0xa7, 0x07, 0xfb, 0xfc, + 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -820,8 +732,6 @@ type MsgClient interface { SubmitMisbehaviour(ctx context.Context, in *MsgSubmitMisbehaviour, opts ...grpc.CallOption) (*MsgSubmitMisbehaviourResponse, error) // RecoverClient defines a rpc handler method for MsgRecoverClient. RecoverClient(ctx context.Context, in *MsgRecoverClient, opts ...grpc.CallOption) (*MsgRecoverClientResponse, error) - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - ProvideCounterparty(ctx context.Context, in *MsgProvideCounterparty, opts ...grpc.CallOption) (*MsgProvideCounterpartyResponse, error) // IBCSoftwareUpgrade defines a rpc handler method for MsgIBCSoftwareUpgrade. IBCSoftwareUpgrade(ctx context.Context, in *MsgIBCSoftwareUpgrade, opts ...grpc.CallOption) (*MsgIBCSoftwareUpgradeResponse, error) // UpdateClientParams defines a rpc handler method for MsgUpdateParams. @@ -881,15 +791,6 @@ func (c *msgClient) RecoverClient(ctx context.Context, in *MsgRecoverClient, opt 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.client.v1.Msg/ProvideCounterparty", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *msgClient) IBCSoftwareUpgrade(ctx context.Context, in *MsgIBCSoftwareUpgrade, opts ...grpc.CallOption) (*MsgIBCSoftwareUpgradeResponse, error) { out := new(MsgIBCSoftwareUpgradeResponse) err := c.cc.Invoke(ctx, "/ibc.core.client.v1.Msg/IBCSoftwareUpgrade", in, out, opts...) @@ -920,8 +821,6 @@ type MsgServer interface { SubmitMisbehaviour(context.Context, *MsgSubmitMisbehaviour) (*MsgSubmitMisbehaviourResponse, error) // RecoverClient defines a rpc handler method for MsgRecoverClient. RecoverClient(context.Context, *MsgRecoverClient) (*MsgRecoverClientResponse, error) - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - ProvideCounterparty(context.Context, *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) // IBCSoftwareUpgrade defines a rpc handler method for MsgIBCSoftwareUpgrade. IBCSoftwareUpgrade(context.Context, *MsgIBCSoftwareUpgrade) (*MsgIBCSoftwareUpgradeResponse, error) // UpdateClientParams defines a rpc handler method for MsgUpdateParams. @@ -947,9 +846,6 @@ func (*UnimplementedMsgServer) SubmitMisbehaviour(ctx context.Context, req *MsgS func (*UnimplementedMsgServer) RecoverClient(ctx context.Context, req *MsgRecoverClient) (*MsgRecoverClientResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RecoverClient not implemented") } -func (*UnimplementedMsgServer) ProvideCounterparty(ctx context.Context, req *MsgProvideCounterparty) (*MsgProvideCounterpartyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ProvideCounterparty not implemented") -} func (*UnimplementedMsgServer) IBCSoftwareUpgrade(ctx context.Context, req *MsgIBCSoftwareUpgrade) (*MsgIBCSoftwareUpgradeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method IBCSoftwareUpgrade not implemented") } @@ -1051,24 +947,6 @@ func _Msg_RecoverClient_Handler(srv interface{}, ctx context.Context, dec func(i 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.client.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) -} - func _Msg_IBCSoftwareUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgIBCSoftwareUpgrade) if err := dec(in); err != nil { @@ -1129,10 +1007,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "RecoverClient", Handler: _Msg_RecoverClient_Handler, }, - { - MethodName: "ProvideCounterparty", - Handler: _Msg_ProvideCounterparty_Handler, - }, { MethodName: "IBCSoftwareUpgrade", Handler: _Msg_IBCSoftwareUpgrade_Handler, @@ -1539,76 +1413,6 @@ func (m *MsgRecoverClientResponse) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } -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 - } - { - size, err := m.Counterparty.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 *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 *MsgIBCSoftwareUpgrade) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1924,34 +1728,6 @@ func (m *MsgRecoverClientResponse) Size() (n int) { return n } -func (m *MsgProvideCounterparty) 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.Counterparty.Size() - 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 *MsgIBCSoftwareUpgrade) Size() (n int) { if m == nil { return 0 @@ -3146,203 +2922,6 @@ func (m *MsgRecoverClientResponse) Unmarshal(dAtA []byte) error { } return nil } -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 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 Counterparty", 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.Counterparty.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 *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 *MsgIBCSoftwareUpgrade) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 51cb2c36d50..2ae9180dcba 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -22,6 +22,7 @@ import ( commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" + packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) var _ porttypes.ICS4Wrapper = (*Keeper)(nil) @@ -98,24 +99,24 @@ func (k *Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel t // GetV2Counterparty returns a version 2 counterparty for the given port and channel ID // by converting the channel into a version 2 counterparty -func (k *Keeper) GetV2Counterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) { +func (k *Keeper) GetV2Counterparty(ctx sdk.Context, portID, channelID string) (packetserver.Counterparty, bool) { channel, ok := k.GetChannel(ctx, portID, channelID) if !ok { - return clienttypes.Counterparty{}, false + return packetserver.Counterparty{}, false } // Do not allow channel to be converted into a version 2 counterparty // if the channel is not OPEN or if it is ORDERED if channel.State != types.OPEN || channel.Ordering == types.ORDERED { - return clienttypes.Counterparty{}, false + return packetserver.Counterparty{}, false } connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !ok { - return clienttypes.Counterparty{}, false + return packetserver.Counterparty{}, false } merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte("")) - counterparty := clienttypes.Counterparty{ - ClientId: connection.ClientId, - MerklePathPrefix: &merklePathPrefix, + counterparty := packetserver.Counterparty{ + ClientId: connection.ClientId, + CounterpartyPacketPath: merklePathPrefix, } return counterparty, true } diff --git a/modules/core/24-host/channel_keys.go b/modules/core/24-host/channel_keys.go index a6d3cee060c..2edf9a9ea9e 100644 --- a/modules/core/24-host/channel_keys.go +++ b/modules/core/24-host/channel_keys.go @@ -2,6 +2,8 @@ package host import "fmt" +var KeyChannelStorePrefix = []byte("channels") + const ( KeyChannelEndPrefix = "channelEnds" KeyChannelPrefix = "channels" diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index da389975107..49b6009ea79 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -56,7 +56,7 @@ func NewKeeper( connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) - packetKeeper := packetserver.NewKeeper(cdc, channelKeeper, clientKeeper) + packetKeeper := packetserver.NewKeeper(cdc, key, channelKeeper, clientKeeper) return &Keeper{ cdc: cdc, diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 5098d411f1e..4efd4d50095 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -17,6 +17,7 @@ import ( porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/internal/telemetry" + packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -143,7 +144,7 @@ func (k *Keeper) IBCSoftwareUpgrade(goCtx context.Context, msg *clienttypes.MsgI } // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. -func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *clienttypes.MsgProvideCounterparty) (*clienttypes.MsgProvideCounterpartyResponse, error) { +func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertypes.MsgProvideCounterparty) (*packetservertypes.MsgProvideCounterpartyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) creator, found := k.ClientKeeper.GetCreator(ctx, msg.ClientId) @@ -155,15 +156,15 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *clienttypes.Msg return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "client creator (%s) must match signer (%s)", creator, msg.Signer) } - if _, ok := k.ClientKeeper.GetCounterparty(ctx, msg.ClientId); ok { - return nil, errorsmod.Wrapf(clienttypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.ClientId) + if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ClientId); ok { + return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.ClientId) } - k.ClientKeeper.SetCounterparty(ctx, msg.ClientId, msg.Counterparty) + k.PacketServerKeeper.SetCounterparty(ctx, msg.ClientId, msg.Counterparty) // Delete client creator from state as it is not needed after this point. k.ClientKeeper.DeleteCreator(ctx, msg.ClientId) - return &clienttypes.MsgProvideCounterpartyResponse{}, nil + return &packetservertypes.MsgProvideCounterpartyResponse{}, nil } // ConnectionOpenInit defines a rpc handler method for MsgConnectionOpenInit. diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index b815a76e4b0..8cb762e8112 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -1,19 +1,14 @@ package keeper import ( - "bytes" - "strconv" + "fmt" - errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" - clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" - channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" 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" @@ -21,13 +16,15 @@ import ( type Keeper struct { cdc codec.BinaryCodec + storeKey storetypes.StoreKey ChannelKeeper types.ChannelKeeper ClientKeeper types.ClientKeeper } -func NewKeeper(cdc codec.BinaryCodec, channelKeeper types.ChannelKeeper, clientKeeper types.ClientKeeper) *Keeper { +func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, channelKeeper types.ChannelKeeper, clientKeeper types.ClientKeeper) *Keeper { return &Keeper{ cdc: cdc, + storeKey: storeKey, ChannelKeeper: channelKeeper, ClientKeeper: clientKeeper, } @@ -39,367 +36,26 @@ func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+exported.ModuleName) } -// TODO: add godoc -func (k Keeper) SendPacket( - ctx sdk.Context, - _ *capabilitytypes.Capability, - sourceChannel string, - sourcePort string, - destPort string, - timeoutHeight clienttypes.Height, - timeoutTimestamp uint64, - version string, - data []byte, -) (uint64, error) { - // Lookup counterparty associated with our source channel to retrieve the destination channel - counterparty, ok := k.GetCounterparty(ctx, sourcePort, sourceChannel) - if !ok { - return 0, channeltypes.ErrChannelNotFound - } - destChannel := counterparty.ClientId - - // retrieve the sequence send for this channel - // if no packets have been sent yet, initialize the sequence to 1. - sequence, found := k.ChannelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) - if !found { - sequence = 1 - } - - // construct packet from given fields and channel state - packet := channeltypes.NewPacketWithVersion(data, sequence, sourcePort, sourceChannel, - destPort, destChannel, timeoutHeight, timeoutTimestamp, version) - - if err := packet.ValidateBasic(); err != nil { - return 0, errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "constructed packet failed basic validation: %v", err) - } - - // check that the client of counterparty chain is still active - if status := k.ClientKeeper.GetClientStatus(ctx, sourceChannel); status != exported.Active { - return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", sourceChannel, status) - } - - // retrieve latest height and timestamp of the client of counterparty chain - latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, sourceChannel) - if latestHeight.IsZero() { - return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", sourceChannel) - } - - latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, sourceChannel, latestHeight) - if err != nil { - return 0, err - } - - // check if packet is timed out on the receiving chain - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if timeout.Elapsed(latestHeight, latestTimestamp) { - return 0, errorsmod.Wrap(timeout.ErrTimeoutElapsed(latestHeight, latestTimestamp), "invalid packet timeout") - } - - commitment := channeltypes.CommitPacket(packet) - - // bump the sequence and set the packet commitment so it is provable by the counterparty - k.ChannelKeeper.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) - k.ChannelKeeper.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) - - // log that a packet has been sent - k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - channelkeeper.EmitSendPacketEvent(ctx, packet, sentinelChannel(sourceChannel), timeoutHeight) - - // return the sequence - return sequence, nil +func (k Keeper) ChannelStore(ctx sdk.Context, channelID string) storetypes.KVStore { + channelPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyChannelStorePrefix, channelID)) + return prefix.NewStore(ctx.KVStore(k.storeKey), channelPrefix) } -// TODO: add godoc -func (k Keeper) RecvPacket( - ctx sdk.Context, - _ *capabilitytypes.Capability, - packet channeltypes.Packet, - proof []byte, - proofHeight exported.Height, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. - // Note: This can be implemented by the current keeper - counterparty, ok := k.GetCounterparty(ctx, packet.DestinationPort, packet.DestinationChannel) - if !ok { - return "", channeltypes.ErrChannelNotFound - } - if counterparty.ClientId != packet.SourceChannel { - return "", channeltypes.ErrInvalidChannelIdentifier - } - - // check if packet timed out by comparing it with the latest height of the chain - selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if timeout.Elapsed(selfHeight, selfTimestamp) { - return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") - } - - // REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received - // on unordered channels. Packet receipts must not be pruned, unless it has been marked stale - // by the increase of the recvStartSequence. - _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - if found { - channelkeeper.EmitRecvPacketEvent(ctx, packet, sentinelChannel(packet.DestinationChannel)) - // This error indicates that the packet has already been relayed. Core IBC will - // treat this error as a no-op in order to prevent an entire relay transaction - // from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg - } - - // create key/value pair for proof verification by appending the ICS24 path to the last element of the counterparty merklepath - // TODO: allow for custom prefix - path := host.PacketCommitmentKey(packet.SourcePort, packet.SourceChannel, packet.Sequence) - merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path) - - commitment := channeltypes.CommitPacket(packet) - - if err := k.ClientKeeper.VerifyMembership( - ctx, - packet.DestinationChannel, - proofHeight, - 0, 0, - proof, - merklePath, - commitment, - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationChannel) - } - - // Set Packet Receipt to prevent timeout from occurring on counterparty - k.ChannelKeeper.SetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - - // log that a packet has been received & executed - k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - // emit the same events as receive packet without channel fields - channelkeeper.EmitRecvPacketEvent(ctx, packet, sentinelChannel(packet.DestinationChannel)) - - return packet.AppVersion, nil +// SetCounterparty sets the Counterparty for a given channel identifier. +func (k *Keeper) SetCounterparty(ctx sdk.Context, channelID string, counterparty types.Counterparty) { + bz := k.cdc.MustMarshal(&counterparty) + k.ChannelStore(ctx, channelID).Set([]byte(types.CounterpartyKey), bz) } -// TODO: add godoc -func (k Keeper) WriteAcknowledgement( - ctx sdk.Context, - _ *capabilitytypes.Capability, - packetI exported.PacketI, - ack exported.Acknowledgement, -) error { - packet, ok := packetI.(channeltypes.Packet) - if !ok { - return errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "expected type %T, got %T", &channeltypes.Packet{}, packetI) - } - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return channeltypes.ErrInvalidPacket - } - - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. - counterparty, ok := k.GetCounterparty(ctx, packet.DestinationPort, packet.DestinationChannel) - if !ok { - return channeltypes.ErrChannelNotFound - } - if counterparty.ClientId != packet.SourceChannel { - return channeltypes.ErrInvalidChannelIdentifier - } - - // NOTE: IBC app modules might have written the acknowledgement synchronously on - // the OnRecvPacket callback so we need to check if the acknowledgement is already - // set on the store and return an error if so. - if k.ChannelKeeper.HasPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) { - return channeltypes.ErrAcknowledgementExists - } - - if _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence); !found { - return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet") - } - - if ack == nil { - return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") - } - - bz := ack.Acknowledgement() +// GetCounterparty gets the Counterparty for a given client identifier. +func (k *Keeper) GetCounterparty(ctx sdk.Context, clientID string) (types.Counterparty, bool) { + store := k.ChannelStore(ctx, clientID) + bz := store.Get([]byte(types.CounterpartyKey)) if len(bz) == 0 { - return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") - } - - k.ChannelKeeper.SetPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence, channeltypes.CommitAcknowledgement(bz)) - - // log that a packet acknowledgement has been written - k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - // emit the same events as write acknowledgement without channel fields - channelkeeper.EmitWriteAcknowledgementEvent(ctx, packet, sentinelChannel(packet.DestinationChannel), bz) - - return nil -} - -// TODO: add godoc -func (k Keeper) AcknowledgePacket( - ctx sdk.Context, - _ *capabilitytypes.Capability, - packet channeltypes.Packet, - acknowledgement []byte, - proofAcked []byte, - proofHeight exported.Height, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. - counterparty, ok := k.GetCounterparty(ctx, packet.SourcePort, packet.SourceChannel) - if !ok { - return "", channeltypes.ErrChannelNotFound - } - - if counterparty.ClientId != packet.DestinationChannel { - return "", channeltypes.ErrInvalidChannelIdentifier - } - - commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - if len(commitment) == 0 { - channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) - - // This error indicates that the acknowledgement has already been relayed - // or there is a misconfigured relayer attempting to prove an acknowledgement - // for a packet never sent. Core IBC will treat this error as a no-op in order to - // prevent an entire relay transaction from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg + return types.Counterparty{}, false } - packetCommitment := channeltypes.CommitPacket(packet) - - // verify we sent the packet and haven't cleared it out yet - if !bytes.Equal(commitment, packetCommitment) { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) - } - - path := host.PacketAcknowledgementKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path) - - if err := k.ClientKeeper.VerifyMembership( - ctx, - packet.SourceChannel, - proofHeight, - 0, 0, - proofAcked, - merklePath, - channeltypes.CommitAcknowledgement(acknowledgement), - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", packet.SourceChannel) - } - - k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - - // log that a packet has been acknowledged - k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "src_port", packet.GetSourcePort(), "src_channel", packet.GetSourceChannel(), "dst_port", packet.GetDestPort(), "dst_channel", packet.GetDestChannel()) - - // emit the same events as acknowledge packet without channel fields - channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) - - return packet.AppVersion, nil -} - -// TODO: add godoc -func (k Keeper) TimeoutPacket( - ctx sdk.Context, - _ *capabilitytypes.Capability, - packet channeltypes.Packet, - proof []byte, - proofHeight exported.Height, - _ uint64, -) (string, error) { - if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { - return "", channeltypes.ErrInvalidPacket - } - // Lookup counterparty associated with our channel and ensure that destination channel - // is the expected counterparty - counterparty, ok := k.GetCounterparty(ctx, packet.SourcePort, packet.SourceChannel) - if !ok { - return "", channeltypes.ErrChannelNotFound - } - - if counterparty.ClientId != packet.DestinationChannel { - return "", channeltypes.ErrInvalidChannelIdentifier - } - - // check that timeout height or timeout timestamp has passed on the other end - proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, packet.SourceChannel, proofHeight) - if err != nil { - return "", err - } - - timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) - if !timeout.Elapsed(proofHeight.(clienttypes.Height), proofTimestamp) { - return "", errorsmod.Wrap(timeout.ErrTimeoutNotReached(proofHeight.(clienttypes.Height), proofTimestamp), "packet timeout not reached") - } - - // check that the commitment has not been cleared and that it matches the packet sent by relayer - commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - - if len(commitment) == 0 { - channelkeeper.EmitTimeoutPacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) - // This error indicates that the timeout has already been relayed - // or there is a misconfigured relayer attempting to prove a timeout - // for a packet never sent. Core IBC will treat this error as a no-op in order to - // prevent an entire relay transaction from failing and consuming unnecessary fees. - return "", channeltypes.ErrNoOpMsg - } - - packetCommitment := channeltypes.CommitPacket(packet) - // verify we sent the packet and haven't cleared it out yet - if !bytes.Equal(commitment, packetCommitment) { - return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) - } - - // verify packet receipt absence - path := host.PacketReceiptKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(counterparty.MerklePathPrefix, path) - - if err := k.ClientKeeper.VerifyNonMembership( - ctx, - packet.SourceChannel, - proofHeight, - 0, 0, - proof, - merklePath, - ); err != nil { - return "", errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", packet.SourceChannel) - } - - // delete packet commitment to prevent replay - k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) - - // log that a packet has been timed out - k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) - - // emit timeout events - channelkeeper.EmitTimeoutPacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) - - return packet.AppVersion, nil -} - -// sentinelChannel creates a sentinel channel for use in events for Eureka protocol handlers. -func sentinelChannel(clientID string) channeltypes.Channel { - return channeltypes.Channel{Ordering: channeltypes.UNORDERED, ConnectionHops: []string{clientID}} -} - -// GetCounterparty returns the v2 counterparty for a given portID and channelID. -// If the portID and channel ID resolves to a v1 channel, then we create a v2 counterparty -// using the channel information -// If the channel ID resolves to client, then we can directly retrieve the v2 counterparty -func (k Keeper) GetCounterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) { - counterparty, ok := k.ChannelKeeper.GetV2Counterparty(ctx, portID, channelID) - if ok { - return counterparty, true - } - // get the counterparty directly from the client keeper using the channel id as a client identifier - return k.ClientKeeper.GetCounterparty(ctx, channelID) + var counterparty types.Counterparty + k.cdc.MustUnmarshal(bz, &counterparty) + return counterparty, true } diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go new file mode 100644 index 00000000000..6878844ba80 --- /dev/null +++ b/modules/core/packet-server/keeper/relay.go @@ -0,0 +1,370 @@ +package keeper + +import ( + "bytes" + "strconv" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + channelkeeper "github.com/cosmos/ibc-go/v9/modules/core/04-channel/keeper" + channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + 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" +) + +// TODO: add godoc +func (k Keeper) SendPacket( + ctx sdk.Context, + _ *capabilitytypes.Capability, + sourceChannel string, + sourcePort string, + destPort string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + version string, + data []byte, +) (uint64, error) { + // Lookup counterparty associated with our source channel to retrieve the destination channel + counterparty, ok := k.GetCounterparty(ctx, sourceChannel) + if !ok { + return 0, channeltypes.ErrChannelNotFound + } + destChannel := counterparty.ClientId + + // retrieve the sequence send for this channel + // if no packets have been sent yet, initialize the sequence to 1. + sequence, found := k.ChannelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) + if !found { + sequence = 1 + } + + // construct packet from given fields and channel state + packet := channeltypes.NewPacketWithVersion(data, sequence, sourcePort, sourceChannel, + destPort, destChannel, timeoutHeight, timeoutTimestamp, version) + + if err := packet.ValidateBasic(); err != nil { + return 0, errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "constructed packet failed basic validation: %v", err) + } + + // check that the client of counterparty chain is still active + if status := k.ClientKeeper.GetClientStatus(ctx, sourceChannel); status != exported.Active { + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", sourceChannel, status) + } + + // retrieve latest height and timestamp of the client of counterparty chain + latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, sourceChannel) + if latestHeight.IsZero() { + return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", sourceChannel) + } + + latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, sourceChannel, latestHeight) + if err != nil { + return 0, err + } + + // check if packet is timed out on the receiving chain + timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) + if timeout.Elapsed(latestHeight, latestTimestamp) { + return 0, errorsmod.Wrap(timeout.ErrTimeoutElapsed(latestHeight, latestTimestamp), "invalid packet timeout") + } + + commitment := channeltypes.CommitPacket(packet) + + // bump the sequence and set the packet commitment so it is provable by the counterparty + k.ChannelKeeper.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1) + k.ChannelKeeper.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) + + // log that a packet has been sent + k.Logger(ctx).Info("packet sent", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) + + channelkeeper.EmitSendPacketEvent(ctx, packet, sentinelChannel(sourceChannel), timeoutHeight) + + // return the sequence + return sequence, nil +} + +// TODO: add godoc +func (k Keeper) RecvPacket( + ctx sdk.Context, + _ *capabilitytypes.Capability, + packet channeltypes.Packet, + proof []byte, + proofHeight exported.Height, +) (string, error) { + if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { + return "", channeltypes.ErrInvalidPacket + } + + // Lookup counterparty associated with our channel and ensure that it was packet was indeed + // sent by our counterparty. + // Note: This can be implemented by the current keeper + counterparty, ok := k.GetCounterparty(ctx, packet.DestinationChannel) + if !ok { + return "", channeltypes.ErrChannelNotFound + } + if counterparty.ClientId != packet.SourceChannel { + return "", channeltypes.ErrInvalidChannelIdentifier + } + + // check if packet timed out by comparing it with the latest height of the chain + selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) + timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) + if timeout.Elapsed(selfHeight, selfTimestamp) { + return "", errorsmod.Wrap(timeout.ErrTimeoutElapsed(selfHeight, selfTimestamp), "packet timeout elapsed") + } + + // REPLAY PROTECTION: Packet receipts will indicate that a packet has already been received + // on unordered channels. Packet receipts must not be pruned, unless it has been marked stale + // by the increase of the recvStartSequence. + _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) + if found { + channelkeeper.EmitRecvPacketEvent(ctx, packet, sentinelChannel(packet.DestinationChannel)) + // This error indicates that the packet has already been relayed. Core IBC will + // treat this error as a no-op in order to prevent an entire relay transaction + // from failing and consuming unnecessary fees. + return "", channeltypes.ErrNoOpMsg + } + + // create key/value pair for proof verification by appending the ICS24 path to the last element of the counterparty merklepath + // TODO: allow for custom prefix + path := host.PacketCommitmentKey(packet.SourcePort, packet.SourceChannel, packet.Sequence) + merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + + commitment := channeltypes.CommitPacket(packet) + + if err := k.ClientKeeper.VerifyMembership( + ctx, + packet.DestinationChannel, + proofHeight, + 0, 0, + proof, + merklePath, + commitment, + ); err != nil { + return "", errorsmod.Wrapf(err, "failed packet commitment verification for client (%s)", packet.DestinationChannel) + } + + // Set Packet Receipt to prevent timeout from occurring on counterparty + k.ChannelKeeper.SetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) + + // log that a packet has been received & executed + k.Logger(ctx).Info("packet received", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) + + // emit the same events as receive packet without channel fields + channelkeeper.EmitRecvPacketEvent(ctx, packet, sentinelChannel(packet.DestinationChannel)) + + return packet.AppVersion, nil +} + +// TODO: add godoc +func (k Keeper) WriteAcknowledgement( + ctx sdk.Context, + _ *capabilitytypes.Capability, + packetI exported.PacketI, + ack exported.Acknowledgement, +) error { + packet, ok := packetI.(channeltypes.Packet) + if !ok { + return errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "expected type %T, got %T", &channeltypes.Packet{}, packetI) + } + if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { + return channeltypes.ErrInvalidPacket + } + + // Lookup counterparty associated with our channel and ensure that it was packet was indeed + // sent by our counterparty. + counterparty, ok := k.GetCounterparty(ctx, packet.DestinationChannel) + if !ok { + return channeltypes.ErrChannelNotFound + } + if counterparty.ClientId != packet.SourceChannel { + return channeltypes.ErrInvalidChannelIdentifier + } + + // NOTE: IBC app modules might have written the acknowledgement synchronously on + // the OnRecvPacket callback so we need to check if the acknowledgement is already + // set on the store and return an error if so. + if k.ChannelKeeper.HasPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence) { + return channeltypes.ErrAcknowledgementExists + } + + if _, found := k.ChannelKeeper.GetPacketReceipt(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence); !found { + return errorsmod.Wrap(channeltypes.ErrInvalidPacket, "receipt not found for packet") + } + + if ack == nil { + return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be nil") + } + + bz := ack.Acknowledgement() + if len(bz) == 0 { + return errorsmod.Wrap(channeltypes.ErrInvalidAcknowledgement, "acknowledgement cannot be empty") + } + + k.ChannelKeeper.SetPacketAcknowledgement(ctx, packet.DestinationPort, packet.DestinationChannel, packet.Sequence, channeltypes.CommitAcknowledgement(bz)) + + // log that a packet acknowledgement has been written + k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) + + // emit the same events as write acknowledgement without channel fields + channelkeeper.EmitWriteAcknowledgementEvent(ctx, packet, sentinelChannel(packet.DestinationChannel), bz) + + return nil +} + +// TODO: add godoc +func (k Keeper) AcknowledgePacket( + ctx sdk.Context, + _ *capabilitytypes.Capability, + packet channeltypes.Packet, + acknowledgement []byte, + proofAcked []byte, + proofHeight exported.Height, +) (string, error) { + if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { + return "", channeltypes.ErrInvalidPacket + } + + // Lookup counterparty associated with our channel and ensure that it was packet was indeed + // sent by our counterparty. + counterparty, ok := k.GetCounterparty(ctx, packet.SourceChannel) + if !ok { + return "", channeltypes.ErrChannelNotFound + } + + if counterparty.ClientId != packet.DestinationChannel { + return "", channeltypes.ErrInvalidChannelIdentifier + } + + commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) + if len(commitment) == 0 { + channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) + + // This error indicates that the acknowledgement has already been relayed + // or there is a misconfigured relayer attempting to prove an acknowledgement + // for a packet never sent. Core IBC will treat this error as a no-op in order to + // prevent an entire relay transaction from failing and consuming unnecessary fees. + return "", channeltypes.ErrNoOpMsg + } + + packetCommitment := channeltypes.CommitPacket(packet) + + // verify we sent the packet and haven't cleared it out yet + if !bytes.Equal(commitment, packetCommitment) { + return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment) + } + + path := host.PacketAcknowledgementKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) + merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + + if err := k.ClientKeeper.VerifyMembership( + ctx, + packet.SourceChannel, + proofHeight, + 0, 0, + proofAcked, + merklePath, + channeltypes.CommitAcknowledgement(acknowledgement), + ); err != nil { + return "", errorsmod.Wrapf(err, "failed packet acknowledgement verification for client (%s)", packet.SourceChannel) + } + + k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) + + // log that a packet has been acknowledged + k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "src_port", packet.GetSourcePort(), "src_channel", packet.GetSourceChannel(), "dst_port", packet.GetDestPort(), "dst_channel", packet.GetDestChannel()) + + // emit the same events as acknowledge packet without channel fields + channelkeeper.EmitAcknowledgePacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) + + return packet.AppVersion, nil +} + +// TODO: add godoc +func (k Keeper) TimeoutPacket( + ctx sdk.Context, + _ *capabilitytypes.Capability, + packet channeltypes.Packet, + proof []byte, + proofHeight exported.Height, + _ uint64, +) (string, error) { + if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { + return "", channeltypes.ErrInvalidPacket + } + // Lookup counterparty associated with our channel and ensure that destination channel + // is the expected counterparty + counterparty, ok := k.GetCounterparty(ctx, packet.SourceChannel) + if !ok { + return "", channeltypes.ErrChannelNotFound + } + + if counterparty.ClientId != packet.DestinationChannel { + return "", channeltypes.ErrInvalidChannelIdentifier + } + + // check that timeout height or timeout timestamp has passed on the other end + proofTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, packet.SourceChannel, proofHeight) + if err != nil { + return "", err + } + + timeout := channeltypes.NewTimeout(packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp()) + if !timeout.Elapsed(proofHeight.(clienttypes.Height), proofTimestamp) { + return "", errorsmod.Wrap(timeout.ErrTimeoutNotReached(proofHeight.(clienttypes.Height), proofTimestamp), "packet timeout not reached") + } + + // check that the commitment has not been cleared and that it matches the packet sent by relayer + commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) + + if len(commitment) == 0 { + channelkeeper.EmitTimeoutPacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) + // This error indicates that the timeout has already been relayed + // or there is a misconfigured relayer attempting to prove a timeout + // for a packet never sent. Core IBC will treat this error as a no-op in order to + // prevent an entire relay transaction from failing and consuming unnecessary fees. + return "", channeltypes.ErrNoOpMsg + } + + packetCommitment := channeltypes.CommitPacket(packet) + // verify we sent the packet and haven't cleared it out yet + if !bytes.Equal(commitment, packetCommitment) { + return "", errorsmod.Wrapf(channeltypes.ErrInvalidPacket, "packet commitment bytes are not equal: got (%v), expected (%v)", commitment, packetCommitment) + } + + // verify packet receipt absence + path := host.PacketReceiptKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) + merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + + if err := k.ClientKeeper.VerifyNonMembership( + ctx, + packet.SourceChannel, + proofHeight, + 0, 0, + proof, + merklePath, + ); err != nil { + return "", errorsmod.Wrapf(err, "failed packet receipt absence verification for client (%s)", packet.SourceChannel) + } + + // delete packet commitment to prevent replay + k.ChannelKeeper.DeletePacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) + + // log that a packet has been timed out + k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_port", packet.SourcePort, "src_channel", packet.SourceChannel, "dst_port", packet.DestinationPort, "dst_channel", packet.DestinationChannel) + + // emit timeout events + channelkeeper.EmitTimeoutPacketEvent(ctx, packet, sentinelChannel(packet.SourceChannel)) + + return packet.AppVersion, nil +} + +// sentinelChannel creates a sentinel channel for use in events for Eureka protocol handlers. +func sentinelChannel(clientID string) channeltypes.Channel { + return channeltypes.Channel{Ordering: channeltypes.UNORDERED, ConnectionHops: []string{clientID}} +} diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/relay_test.go similarity index 100% rename from modules/core/packet-server/keeper/keeper_test.go rename to modules/core/packet-server/keeper/relay_test.go diff --git a/modules/core/packet-server/types/codec.go b/modules/core/packet-server/types/codec.go new file mode 100644 index 00000000000..6d4476be76a --- /dev/null +++ b/modules/core/packet-server/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterInterfaces registers the packet-server interfaces to protobuf Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgProvideCounterparty{}, + ) +} diff --git a/modules/core/packet-server/types/counterparty.go b/modules/core/packet-server/types/counterparty.go new file mode 100644 index 00000000000..d6ce9fb5216 --- /dev/null +++ b/modules/core/packet-server/types/counterparty.go @@ -0,0 +1,29 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" +) + +// NewCounterparty creates a new Counterparty instance +func NewCounterparty(clientID string, counterpartyPacketPath commitmenttypes.MerklePath) Counterparty { + return Counterparty{ + ClientId: clientID, + CounterpartyPacketPath: counterpartyPacketPath, + } +} + +// Validate validates the Counterparty +func (c Counterparty) Validate() error { + if err := host.ClientIdentifierValidator(c.ClientId); err != nil { + return err + } + + if c.CounterpartyPacketPath.Empty() { + return errorsmod.Wrap(ErrInvalidCounterparty, "prefix cannot be empty") + } + + return nil +} diff --git a/modules/core/packet-server/types/counterparty.pb.go b/modules/core/packet-server/types/counterparty.pb.go new file mode 100644 index 00000000000..fa8736059c3 --- /dev/null +++ b/modules/core/packet-server/types/counterparty.pb.go @@ -0,0 +1,440 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/packetserver/v1/counterparty.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Counterparty defines the counterparty for a light client to implement IBC eureka protocol +type Counterparty struct { + // the client identifier of 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 intended for the counterparty + // here we do not prefix with the IBC store path because the SDK already prefixes + // the key for us. + PacketPath []byte `protobuf:"bytes,2,opt,name=packet_path,json=packetPath,proto3" json:"packet_path,omitempty"` + // the key path used to store packet flow messages that the counterparty + // will use to send to us. + CounterpartyPacketPath v2.MerklePath `protobuf:"bytes,3,opt,name=counterparty_packet_path,json=counterpartyPacketPath,proto3" json:"counterparty_packet_path"` +} + +func (m *Counterparty) Reset() { *m = Counterparty{} } +func (m *Counterparty) String() string { return proto.CompactTextString(m) } +func (*Counterparty) ProtoMessage() {} +func (*Counterparty) Descriptor() ([]byte, []int) { + return fileDescriptor_e0c60a0709a0040c, []int{0} +} +func (m *Counterparty) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Counterparty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Counterparty.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 *Counterparty) XXX_Merge(src proto.Message) { + xxx_messageInfo_Counterparty.Merge(m, src) +} +func (m *Counterparty) XXX_Size() int { + return m.Size() +} +func (m *Counterparty) XXX_DiscardUnknown() { + xxx_messageInfo_Counterparty.DiscardUnknown(m) +} + +var xxx_messageInfo_Counterparty proto.InternalMessageInfo + +func (m *Counterparty) GetClientId() string { + if m != nil { + return m.ClientId + } + return "" +} + +func (m *Counterparty) GetPacketPath() []byte { + if m != nil { + return m.PacketPath + } + return nil +} + +func (m *Counterparty) GetCounterpartyPacketPath() v2.MerklePath { + if m != nil { + return m.CounterpartyPacketPath + } + return v2.MerklePath{} +} + +func init() { + proto.RegisterType((*Counterparty)(nil), "ibc.core.packetserver.v1.Counterparty") +} + +func init() { + proto.RegisterFile("ibc/core/packetserver/v1/counterparty.proto", fileDescriptor_e0c60a0709a0040c) +} + +var fileDescriptor_e0c60a0709a0040c = []byte{ + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x6a, 0xeb, 0x30, + 0x14, 0x86, 0xad, 0x7b, 0x4b, 0x69, 0x94, 0x4c, 0xa6, 0x14, 0x93, 0x82, 0x12, 0xb2, 0xd4, 0x50, + 0x22, 0x11, 0x77, 0x2a, 0x74, 0x4a, 0xa7, 0x0e, 0x85, 0xe0, 0xa1, 0x43, 0x17, 0x63, 0xc9, 0xc2, + 0x16, 0xb1, 0x2d, 0x23, 0xcb, 0x82, 0xbc, 0x45, 0x1f, 0xa5, 0x8f, 0x91, 0x31, 0x63, 0xa7, 0x52, + 0xec, 0x17, 0x29, 0x8e, 0x8b, 0xd1, 0x26, 0x1d, 0x3e, 0xbe, 0xff, 0x9c, 0x1f, 0xde, 0x0b, 0xca, + 0x08, 0x93, 0x8a, 0x93, 0x2a, 0x66, 0x7b, 0xae, 0x6b, 0xae, 0x0c, 0x57, 0xc4, 0x6c, 0x08, 0x93, + 0x4d, 0xa9, 0xb9, 0xaa, 0x62, 0xa5, 0x0f, 0xb8, 0x52, 0x52, 0x4b, 0xd7, 0x13, 0x94, 0xe1, 0x1e, + 0xc6, 0x36, 0x8c, 0xcd, 0x66, 0x7e, 0x9d, 0xca, 0x54, 0x9e, 0x21, 0xd2, 0xbf, 0x06, 0x7e, 0x7e, + 0x37, 0xca, 0x99, 0x2c, 0x0a, 0xa1, 0x0b, 0x5e, 0x6a, 0x62, 0x02, 0xeb, 0x37, 0x80, 0xab, 0x4f, + 0x00, 0x67, 0xcf, 0x56, 0x9e, 0x7b, 0x0b, 0x27, 0x2c, 0x17, 0xbc, 0xd4, 0x91, 0x48, 0x3c, 0xb0, + 0x04, 0xfe, 0x24, 0xbc, 0x1a, 0x06, 0x2f, 0x89, 0xbb, 0x80, 0xd3, 0x21, 0x3f, 0xaa, 0x62, 0x9d, + 0x79, 0xff, 0x96, 0xc0, 0x9f, 0x85, 0x70, 0x18, 0xed, 0x62, 0x9d, 0xb9, 0x14, 0x7a, 0xf6, 0xf6, + 0x91, 0x4d, 0xff, 0x5f, 0x02, 0x7f, 0x1a, 0xac, 0xf0, 0x78, 0x8a, 0xb5, 0x8c, 0x09, 0xf0, 0x2b, + 0x57, 0xfb, 0x9c, 0xf7, 0x96, 0xed, 0xc5, 0xf1, 0x7b, 0xe1, 0x84, 0x37, 0xb6, 0x69, 0x37, 0x66, + 0x6c, 0xdf, 0x8e, 0x2d, 0x02, 0xa7, 0x16, 0x81, 0x9f, 0x16, 0x81, 0x8f, 0x0e, 0x39, 0xa7, 0x0e, + 0x39, 0x5f, 0x1d, 0x72, 0xde, 0x9f, 0x52, 0xa1, 0xb3, 0x86, 0xf6, 0x62, 0xc2, 0x64, 0x5d, 0xc8, + 0x9a, 0x08, 0xca, 0xd6, 0xa9, 0x24, 0xe6, 0x91, 0x14, 0x32, 0x69, 0x72, 0x5e, 0xdb, 0x95, 0xaf, + 0xff, 0x3a, 0xd7, 0x87, 0x8a, 0xd7, 0xf4, 0xf2, 0xdc, 0xc8, 0xc3, 0x6f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xfb, 0xa6, 0x1a, 0x97, 0x99, 0x01, 0x00, 0x00, +} + +func (m *Counterparty) 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 *Counterparty) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Counterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.CounterpartyPacketPath.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCounterparty(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.PacketPath) > 0 { + i -= len(m.PacketPath) + copy(dAtA[i:], m.PacketPath) + i = encodeVarintCounterparty(dAtA, i, uint64(len(m.PacketPath))) + i-- + dAtA[i] = 0x12 + } + if len(m.ClientId) > 0 { + i -= len(m.ClientId) + copy(dAtA[i:], m.ClientId) + i = encodeVarintCounterparty(dAtA, i, uint64(len(m.ClientId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintCounterparty(dAtA []byte, offset int, v uint64) int { + offset -= sovCounterparty(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Counterparty) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ClientId) + if l > 0 { + n += 1 + l + sovCounterparty(uint64(l)) + } + l = len(m.PacketPath) + if l > 0 { + n += 1 + l + sovCounterparty(uint64(l)) + } + l = m.CounterpartyPacketPath.Size() + n += 1 + l + sovCounterparty(uint64(l)) + return n +} + +func sovCounterparty(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCounterparty(x uint64) (n int) { + return sovCounterparty(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Counterparty) 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 ErrIntOverflowCounterparty + } + 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: Counterparty: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Counterparty: 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 ErrIntOverflowCounterparty + } + 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 ErrInvalidLengthCounterparty + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + 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 PacketPath", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCounterparty + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCounterparty + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PacketPath = append(m.PacketPath[:0], dAtA[iNdEx:postIndex]...) + if m.PacketPath == nil { + m.PacketPath = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyPacketPath", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCounterparty + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCounterparty + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CounterpartyPacketPath.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCounterparty(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCounterparty + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCounterparty(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, ErrIntOverflowCounterparty + } + 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, ErrIntOverflowCounterparty + } + 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, ErrIntOverflowCounterparty + } + 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, ErrInvalidLengthCounterparty + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCounterparty + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCounterparty + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCounterparty = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCounterparty = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCounterparty = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/packet-server/types/counterparty_test.go b/modules/core/packet-server/types/counterparty_test.go new file mode 100644 index 00000000000..9e036c4c51c --- /dev/null +++ b/modules/core/packet-server/types/counterparty_test.go @@ -0,0 +1,54 @@ +package types_test + +import ( + "testing" + + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" + "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" + ibctesting "github.com/cosmos/ibc-go/v9/testing" + "github.com/stretchr/testify/require" +) + +func TestValidateCounterparty(t *testing.T) { + testCases := []struct { + name string + clientID string + merklePathPrefix commitmenttypes.MerklePath + expError error + }{ + { + "success", + ibctesting.FirstClientID, + commitmenttypes.NewMerklePath([]byte("ibc")), + nil, + }, + { + "failure: invalid client id", + "", + commitmenttypes.NewMerklePath([]byte("ibc")), + host.ErrInvalidID, + }, + { + "failure: empty merkle path prefix", + ibctesting.FirstClientID, + commitmenttypes.NewMerklePath(), + types.ErrInvalidCounterparty, + }, + } + + for _, tc := range testCases { + tc := tc + + counterparty := types.NewCounterparty(tc.clientID, tc.merklePathPrefix) + err := counterparty.Validate() + + expPass := tc.expError == nil + if expPass { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + require.ErrorIs(t, err, tc.expError) + } + } +} diff --git a/modules/core/packet-server/types/errors.go b/modules/core/packet-server/types/errors.go new file mode 100644 index 00000000000..820864cb5b3 --- /dev/null +++ b/modules/core/packet-server/types/errors.go @@ -0,0 +1,10 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" +) + +// IBC packet server sentinel errors +var ( + ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 1, "invalid counterparty") +) diff --git a/modules/core/packet-server/types/expected_keepers.go b/modules/core/packet-server/types/expected_keepers.go index dd4a8aea7c1..cd6b116a95f 100644 --- a/modules/core/packet-server/types/expected_keepers.go +++ b/modules/core/packet-server/types/expected_keepers.go @@ -40,7 +40,7 @@ type ChannelKeeper interface { SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) // GetChannel returns a version 2 counterparty for a given portID and channel ID - GetV2Counterparty(ctx sdk.Context, portID, channelID string) (clienttypes.Counterparty, bool) + GetV2Counterparty(ctx sdk.Context, portID, channelID string) (Counterparty, bool) } type ClientKeeper interface { @@ -48,10 +48,6 @@ type ClientKeeper interface { VerifyMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path, value []byte) error // VerifyNonMembership retrieves the light client module for the clientID and verifies the absence of a given key at a specified height. VerifyNonMembership(ctx sdk.Context, clientID string, height exported.Height, delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, path exported.Path) error - // GetCounterparty returns the counterparty client given the client ID on - // the executing chain - // This is a private path that is only used by the IBC lite module - GetCounterparty(ctx sdk.Context, clientID string) (clienttypes.Counterparty, bool) // GetClientStatus returns the status of a client given the client ID GetClientStatus(ctx sdk.Context, clientID string) exported.Status // GetClientLatestHeight returns the latest height of a client given the client ID diff --git a/modules/core/packet-server/types/keys.go b/modules/core/packet-server/types/keys.go new file mode 100644 index 00000000000..6b684551fac --- /dev/null +++ b/modules/core/packet-server/types/keys.go @@ -0,0 +1,11 @@ +package types + +const ( + // SubModuleName defines the IBC packet server name + SubModuleName string = "packetserver" + + // CounterpartyKey is the key used to store counterparty in the client store. + // the counterparty key is imported from types instead of host because + // the counterparty key is not a part of the ics-24 host specification + CounterpartyKey = "counterparty" +) diff --git a/modules/core/packet-server/types/msgs.go b/modules/core/packet-server/types/msgs.go new file mode 100644 index 00000000000..46d67a133c0 --- /dev/null +++ b/modules/core/packet-server/types/msgs.go @@ -0,0 +1,45 @@ +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(signer, clientID, counterpartyID string, counterpartyPacketPath commitmenttypes.MerklePath) *MsgProvideCounterparty { + counterparty := NewCounterparty(counterpartyID, counterpartyPacketPath) + + return &MsgProvideCounterparty{ + Signer: signer, + ClientId: clientID, + Counterparty: counterparty, + } +} + +// 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.ClientIdentifierValidator(msg.ClientId); err != nil { + return err + } + + if err := msg.Counterparty.Validate(); err != nil { + return err + } + + return nil +} diff --git a/modules/core/packet-server/types/tx.pb.go b/modules/core/packet-server/types/tx.pb.go new file mode 100644 index 00000000000..8350e3a7fd0 --- /dev/null +++ b/modules/core/packet-server/types/tx.pb.go @@ -0,0 +1,624 @@ +// 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" + 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 { + // client unique identifier + ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // counterparty client + Counterparty Counterparty `protobuf:"bytes,2,opt,name=counterparty,proto3" json:"counterparty"` + // 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 + +func init() { + proto.RegisterType((*MsgProvideCounterparty)(nil), "ibc.core.packetserver.v1.MsgProvideCounterparty") + proto.RegisterType((*MsgProvideCounterpartyResponse)(nil), "ibc.core.packetserver.v1.MsgProvideCounterpartyResponse") +} + +func init() { proto.RegisterFile("ibc/core/packetserver/v1/tx.proto", fileDescriptor_3c556aec8b7966db) } + +var fileDescriptor_3c556aec8b7966db = []byte{ + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x4c, 0x4a, 0xd6, + 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x48, 0x4c, 0xce, 0x4e, 0x2d, 0x29, 0x4e, 0x2d, 0x2a, 0x4b, + 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xc8, + 0x4c, 0x4a, 0xd6, 0x03, 0x29, 0xd1, 0x43, 0x56, 0xa2, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, + 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x4b, 0x69, 0xe3, 0x34, 0x32, 0x39, 0xbf, 0x34, + 0xaf, 0x24, 0xb5, 0xa8, 0x20, 0xb1, 0xa8, 0xa4, 0x12, 0xaa, 0x58, 0x3c, 0x39, 0xbf, 0x38, 0x37, + 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0xa4, 0x22, 0xb7, 0x38, 0x1d, 0x22, 0xa1, 0xb4, 0x81, 0x91, + 0x4b, 0xcc, 0xb7, 0x38, 0x3d, 0xa0, 0x28, 0xbf, 0x2c, 0x33, 0x25, 0xd5, 0x19, 0x49, 0xa7, 0x90, + 0x34, 0x17, 0x67, 0x72, 0x4e, 0x66, 0x6a, 0x5e, 0x49, 0x7c, 0x66, 0x8a, 0x04, 0xa3, 0x02, 0xa3, + 0x06, 0x67, 0x10, 0x07, 0x44, 0xc0, 0x33, 0x45, 0x28, 0x80, 0x8b, 0x07, 0xd9, 0x1a, 0x09, 0x26, + 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x35, 0x3d, 0x5c, 0x9e, 0xd0, 0x43, 0x36, 0xda, 0x89, 0xe5, 0xc4, + 0x3d, 0x79, 0x86, 0x20, 0x14, 0x13, 0x84, 0xc4, 0xb8, 0xd8, 0x8a, 0x33, 0xd3, 0xf3, 0x52, 0x8b, + 0x24, 0x98, 0xc1, 0x76, 0x41, 0x79, 0x56, 0xfc, 0x1d, 0x0b, 0xe4, 0x19, 0x9a, 0x9e, 0x6f, 0xd0, + 0x82, 0x0a, 0x28, 0x29, 0x70, 0xc9, 0x61, 0x77, 0x71, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, + 0xaa, 0xd1, 0x04, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x46, 0x46, 0x2e, 0x61, 0x6c, 0x3e, + 0x33, 0xc0, 0xed, 0x4c, 0xec, 0x26, 0x4b, 0x59, 0x90, 0xaa, 0x03, 0xe6, 0x16, 0x29, 0xd6, 0x86, + 0xe7, 0x1b, 0xb4, 0x18, 0x9d, 0xc2, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, + 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, + 0xca, 0x26, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x1a, 0x4b, 0x99, + 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0x65, 0x96, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, 0x39, 0xa9, 0xc5, + 0xc8, 0xf1, 0xac, 0x0b, 0x8d, 0xe8, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x34, 0x1a, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x61, 0x52, 0xe3, 0xab, 0x61, 0x02, 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 { + // 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) 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 { + // 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) 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_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: "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 + } + { + size, err := m.Counterparty.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 *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 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.ClientId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Counterparty.Size() + 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 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 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 Counterparty", 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.Counterparty.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 *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 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/proto/ibc/core/client/v1/client.proto b/proto/ibc/core/client/v1/client.proto index 08c9591e26b..d2ff2a2801c 100644 --- a/proto/ibc/core/client/v1/client.proto +++ b/proto/ibc/core/client/v1/client.proto @@ -6,7 +6,6 @@ option go_package = "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; -import "ibc/core/commitment/v2/commitment.proto"; // IdentifiedClientState defines a client state with an additional client // identifier field. @@ -35,14 +34,6 @@ message ClientConsensusStates { repeated ConsensusStateWithHeight consensus_states = 2 [(gogoproto.nullable) = false]; } -// Counterparty defines the counterparty for a light client to implement IBC eureka protocol -message Counterparty { - // the client identifier of the counterparty chain - string client_id = 1; - // the merkle path that all ICS24 paths will be stored under - ibc.core.commitment.v2.MerklePath merkle_path_prefix = 2; -} - // Height is a monotonically increasing data type // that can be compared against another Height for the purposes of updating and // freezing clients diff --git a/proto/ibc/core/client/v1/tx.proto b/proto/ibc/core/client/v1/tx.proto index 357c5a7d0a1..1e9e4f47ada 100644 --- a/proto/ibc/core/client/v1/tx.proto +++ b/proto/ibc/core/client/v1/tx.proto @@ -29,9 +29,6 @@ service Msg { // RecoverClient defines a rpc handler method for MsgRecoverClient. rpc RecoverClient(MsgRecoverClient) returns (MsgRecoverClientResponse); - // ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty. - rpc ProvideCounterparty(MsgProvideCounterparty) returns (MsgProvideCounterpartyResponse); - // IBCSoftwareUpgrade defines a rpc handler method for MsgIBCSoftwareUpgrade. rpc IBCSoftwareUpgrade(MsgIBCSoftwareUpgrade) returns (MsgIBCSoftwareUpgradeResponse); @@ -143,25 +140,6 @@ message MsgRecoverClient { // MsgRecoverClientResponse defines the Msg/RecoverClient response type. message MsgRecoverClientResponse {} -// 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; - - // client unique identifier - string client_id = 1; - // counterparty client - Counterparty counterparty = 2 [(gogoproto.nullable) = false]; - // signer address - string signer = 3; -} - -// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. -message MsgProvideCounterpartyResponse {} - // MsgIBCSoftwareUpgrade defines the message used to schedule an upgrade of an IBC client using a v1 governance proposal message MsgIBCSoftwareUpgrade { option (cosmos.msg.v1.signer) = "signer"; diff --git a/proto/ibc/core/packetserver/v1/counterparty.proto b/proto/ibc/core/packetserver/v1/counterparty.proto new file mode 100644 index 00000000000..34a41650fd1 --- /dev/null +++ b/proto/ibc/core/packetserver/v1/counterparty.proto @@ -0,0 +1,21 @@ +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"; + +// Counterparty defines the counterparty for a light client to implement IBC eureka protocol +// this value is stored under our side's channel ID. which we will use to write all packet messages +// sent to counterparty +message Counterparty { + // the client identifier of the counterparty chain + // client id of the counterparty stored on our chain + string client_id = 1; + // the key path used to store packet flow messages that the counterparty + // will use to send to us. + // ["ibc", "channel/channel-4"] => ["ibc", "channel/channel-4/port/transfer/sequence/1"] + ibc.core.commitment.v2.MerklePath counterparty_packet_path = 3 [(gogoproto.nullable) = false]; +} diff --git a/proto/ibc/core/packetserver/v1/tx.proto b/proto/ibc/core/packetserver/v1/tx.proto new file mode 100644 index 00000000000..00e2e8c5c78 --- /dev/null +++ b/proto/ibc/core/packetserver/v1/tx.proto @@ -0,0 +1,36 @@ +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/packetserver/v1/counterparty.proto"; +import "cosmos/msg/v1/msg.proto"; + +// Msg defines the ibc/packetserver Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // 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 packetPath = 1; + // counterparty client + Counterparty counterparty = 2 [(gogoproto.nullable) = false]; + // signer address + string signer = 3; +} + +// MsgProvideCounterpartyResponse defines the Msg/ProvideCounterparty response type. +message MsgProvideCounterpartyResponse {} From ae910a808bb7531d38526ae82cfc29f02c85625f Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:11:50 +0200 Subject: [PATCH 3/8] get all tests passing with new counterparty msg/handler in new package --- e2e/testsuite/codec.go | 2 + modules/apps/callbacks/testing/simapp/app.go | 2 +- modules/core/02-client/keeper/keeper_test.go | 17 ---- modules/core/keeper/msg_server.go | 11 ++- modules/core/keeper/msg_server_test.go | 13 +-- modules/core/module.go | 2 + .../core/packet-server/keeper/keeper_test.go | 73 ++++++++++++++ .../core/packet-server/keeper/relay_test.go | 35 ------- .../packet-server/types/counterparty.pb.go | 99 +++++-------------- modules/core/packet-server/types/errors.go | 1 + modules/core/packet-server/types/msgs.go | 13 +-- modules/core/packet-server/types/tx.pb.go | 48 ++++----- modules/core/types/codec.go | 2 + .../08-wasm/testing/simapp/app.go | 2 +- proto/ibc/core/packetserver/v1/tx.proto | 2 +- testing/endpoint.go | 3 +- testing/simapp/app.go | 2 +- 17 files changed, 153 insertions(+), 174 deletions(-) create mode 100644 modules/core/packet-server/keeper/keeper_test.go diff --git a/e2e/testsuite/codec.go b/e2e/testsuite/codec.go index adcd74c67e5..5de0570cd18 100644 --- a/e2e/testsuite/codec.go +++ b/e2e/testsuite/codec.go @@ -32,6 +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" 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" @@ -69,6 +70,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, testutil.TestEncodingConfig) { connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry) ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry) wasmtypes.RegisterInterfaces(cfg.InterfaceRegistry) + packetservertypes.RegisterInterfaces(cfg.InterfaceRegistry) // all other types upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry) diff --git a/modules/apps/callbacks/testing/simapp/app.go b/modules/apps/callbacks/testing/simapp/app.go index 2a4e28925a9..5b536c2626b 100644 --- a/modules/apps/callbacks/testing/simapp/app.go +++ b/modules/apps/callbacks/testing/simapp/app.go @@ -409,7 +409,7 @@ func NewSimApp( app.IBCKeeper = ibckeeper.NewKeeper( appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) + app.PacketServer = packetserverkeeper.NewKeeper(appCodec, keys[ibcexported.StoreKey], app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) // NOTE: The mock ContractKeeper is only created for testing. // Real applications should not use the mock ContractKeeper diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index 79595e5c12d..e132bd929fc 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -129,23 +129,6 @@ func (suite *KeeperTestSuite) TestSetClientState() { suite.Require().Equal(clientState, retrievedState, "Client states are not equal") } -func (suite *KeeperTestSuite) TestSetCounterparty() { - merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) - counterparty := types.Counterparty{ - ClientId: testClientID, - MerklePathPrefix: &merklePathPrefix, - } - suite.keeper.SetCounterparty(suite.ctx, testClientID, counterparty) - - retrievedCounterparty, found := suite.keeper.GetCounterparty(suite.ctx, testClientID) - suite.Require().True(found, "GetCounterparty does not return counterparty") - suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparty retrieved not equal") - - retrievedCounterparty, found = suite.keeper.GetCounterparty(suite.ctx, "client-0") - suite.Require().False(found, "GetCounterparty unexpectedly returned a counterparty") - suite.Require().Equal(types.Counterparty{}, retrievedCounterparty, "Counterparty retrieved not empty") -} - func (suite *KeeperTestSuite) TestSetCreator() { clientID := "test-client" expectedCreator := "test-creator" diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 4efd4d50095..7b46379f126 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -26,6 +26,7 @@ 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. @@ -147,7 +148,7 @@ func (k *Keeper) IBCSoftwareUpgrade(goCtx context.Context, msg *clienttypes.MsgI func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertypes.MsgProvideCounterparty) (*packetservertypes.MsgProvideCounterpartyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - creator, found := k.ClientKeeper.GetCreator(ctx, msg.ClientId) + creator, found := k.ClientKeeper.GetCreator(ctx, msg.Counterparty.ClientId) if !found { return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "client creator must be set") } @@ -156,13 +157,13 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertyp return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "client creator (%s) must match signer (%s)", creator, msg.Signer) } - if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ClientId); ok { - return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.ClientId) + if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.PacketPath); ok { + return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.Counterparty.ClientId) } - k.PacketServerKeeper.SetCounterparty(ctx, msg.ClientId, msg.Counterparty) + k.PacketServerKeeper.SetCounterparty(ctx, msg.PacketPath, msg.Counterparty) // Delete client creator from state as it is not needed after this point. - k.ClientKeeper.DeleteCreator(ctx, msg.ClientId) + k.ClientKeeper.DeleteCreator(ctx, msg.Counterparty.ClientId) return &packetservertypes.MsgProvideCounterpartyResponse{}, nil } diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 839e519414b..079aa705313 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -22,6 +22,7 @@ import ( 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" + 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" ibcmock "github.com/cosmos/ibc-go/v9/testing/mock" @@ -781,7 +782,7 @@ func (suite *KeeperTestSuite) TestHandleTimeoutOnClosePacket() { func (suite *KeeperTestSuite) TestProvideCounterparty() { var ( path *ibctesting.Path - msg *clienttypes.MsgProvideCounterparty + msg *packetservertypes.MsgProvideCounterparty ) cases := []struct { name string @@ -796,7 +797,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() { { "failure: unknown client identifier", func() { - msg.ClientId = ibctesting.InvalidID + msg.Counterparty.ClientId = ibctesting.InvalidID }, ibcerrors.ErrUnauthorized, }, @@ -811,9 +812,9 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() { "failure: counterparty already exists", func() { // set it before handler - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ClientId, msg.Counterparty) + suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.PacketPath, msg.Counterparty) }, - clienttypes.ErrInvalidCounterparty, + packetservertypes.ErrInvalidCounterparty, }, } @@ -824,7 +825,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() { signer := path.EndpointA.Chain.SenderAccount.GetAddress().String() merklePrefix := commitmenttypesv2.NewMerklePath([]byte("mock-key")) - msg = clienttypes.NewMsgProvideCounterparty(signer, path.EndpointA.ClientID, path.EndpointB.ClientID, &merklePrefix) + msg = packetservertypes.NewMsgProvideCounterparty(signer, path.EndpointA.ClientID, path.EndpointB.ClientID, merklePrefix) tc.malleate() @@ -837,7 +838,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() { suite.Require().Nil(err) // Assert counterparty set and creator deleted - counterparty, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetCounterparty(suite.chainA.GetContext(), path.EndpointA.ClientID) + counterparty, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCounterparty(suite.chainA.GetContext(), path.EndpointA.ClientID) suite.Require().True(found) suite.Require().Equal(counterparty, msg.Counterparty) diff --git a/modules/core/module.go b/modules/core/module.go index 1dc35eec4a8..f81c9f54bda 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -27,6 +27,7 @@ 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" + 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" ) @@ -132,6 +133,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { connectiontypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) channeltypes.RegisterPacketMsgServer(cfg.MsgServer(), am.keeper) + packetservertypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) clienttypes.RegisterQueryServer(cfg.QueryServer(), clientkeeper.NewQueryServer(am.keeper.ClientKeeper)) connectiontypes.RegisterQueryServer(cfg.QueryServer(), connectionkeeper.NewQueryServer(am.keeper.ConnectionKeeper)) diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go new file mode 100644 index 00000000000..23f7312f31f --- /dev/null +++ b/modules/core/packet-server/keeper/keeper_test.go @@ -0,0 +1,73 @@ +package keeper_test + +import ( + "testing" + + testifysuite "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/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" +) + +const ( + testClientID = "tendermint-0" +) + +var ( + defaultTimeoutHeight = clienttypes.NewHeight(1, 100) + disabledTimeoutTimestamp = uint64(0) +) + +// KeeperTestSuite is a testing suite to test keeper functions. +type KeeperTestSuite struct { + testifysuite.Suite + + coordinator *ibctesting.Coordinator + + // testing chains used for convenience and readability + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain + + ctx sdk.Context + keeper *keeper.Keeper +} + +// TestKeeperTestSuite runs all the tests within this package. +func TestKeeperTestSuite(t *testing.T) { + testifysuite.Run(t, new(KeeperTestSuite)) +} + +// SetupTest creates a coordinator with 2 test chains. +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) + + // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) + suite.coordinator.CommitNBlocks(suite.chainA, 2) + suite.coordinator.CommitNBlocks(suite.chainB, 2) + + suite.ctx = suite.chainA.GetContext() + suite.keeper = suite.chainA.App.GetPacketServer() +} + +func (suite *KeeperTestSuite) TestSetCounterparty() { + merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) + counterparty := types.Counterparty{ + ClientId: testClientID, + CounterpartyPacketPath: merklePathPrefix, + } + suite.keeper.SetCounterparty(suite.ctx, testClientID, counterparty) + + retrievedCounterparty, found := suite.keeper.GetCounterparty(suite.ctx, testClientID) + suite.Require().True(found, "GetCounterparty does not return counterparty") + suite.Require().Equal(counterparty, retrievedCounterparty, "Counterparty retrieved not equal") + + retrievedCounterparty, found = suite.keeper.GetCounterparty(suite.ctx, "client-0") + suite.Require().False(found, "GetCounterparty unexpectedly returned a counterparty") + suite.Require().Equal(types.Counterparty{}, retrievedCounterparty, "Counterparty retrieved not empty") +} diff --git a/modules/core/packet-server/keeper/relay_test.go b/modules/core/packet-server/keeper/relay_test.go index 513a5412dbb..bbb4111d37e 100644 --- a/modules/core/packet-server/keeper/relay_test.go +++ b/modules/core/packet-server/keeper/relay_test.go @@ -2,9 +2,6 @@ package keeper_test import ( "fmt" - "testing" - - testifysuite "github.com/stretchr/testify/suite" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -15,38 +12,6 @@ import ( "github.com/cosmos/ibc-go/v9/testing/mock" ) -var ( - defaultTimeoutHeight = clienttypes.NewHeight(1, 100) - disabledTimeoutTimestamp = uint64(0) -) - -// KeeperTestSuite is a testing suite to test keeper functions. -type KeeperTestSuite struct { - testifysuite.Suite - - coordinator *ibctesting.Coordinator - - // testing chains used for convenience and readability - chainA *ibctesting.TestChain - chainB *ibctesting.TestChain -} - -// TestKeeperTestSuite runs all the tests within this package. -func TestKeeperTestSuite(t *testing.T) { - testifysuite.Run(t, new(KeeperTestSuite)) -} - -// SetupTest creates a coordinator with 2 test chains. -func (suite *KeeperTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - - // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) - suite.coordinator.CommitNBlocks(suite.chainA, 2) - suite.coordinator.CommitNBlocks(suite.chainB, 2) -} - func (suite *KeeperTestSuite) TestSendPacket() { var ( path *ibctesting.Path diff --git a/modules/core/packet-server/types/counterparty.pb.go b/modules/core/packet-server/types/counterparty.pb.go index fa8736059c3..6caa224c556 100644 --- a/modules/core/packet-server/types/counterparty.pb.go +++ b/modules/core/packet-server/types/counterparty.pb.go @@ -25,15 +25,15 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Counterparty defines the counterparty for a light client to implement IBC eureka protocol +// this value is stored under our side's channel ID. which we will use to write all packet messages +// sent to counterparty type Counterparty struct { // the client identifier of the counterparty chain + // client id of the counterparty stored on our 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 intended for the counterparty - // here we do not prefix with the IBC store path because the SDK already prefixes - // the key for us. - PacketPath []byte `protobuf:"bytes,2,opt,name=packet_path,json=packetPath,proto3" json:"packet_path,omitempty"` // the key path used to store packet flow messages that the counterparty // will use to send to us. + // ["ibc", "channel/channel-4"] => ["ibc", "channel/channel-4/port/transfer/sequence/1"] CounterpartyPacketPath v2.MerklePath `protobuf:"bytes,3,opt,name=counterparty_packet_path,json=counterpartyPacketPath,proto3" json:"counterparty_packet_path"` } @@ -77,13 +77,6 @@ func (m *Counterparty) GetClientId() string { return "" } -func (m *Counterparty) GetPacketPath() []byte { - if m != nil { - return m.PacketPath - } - return nil -} - func (m *Counterparty) GetCounterpartyPacketPath() v2.MerklePath { if m != nil { return m.CounterpartyPacketPath @@ -100,26 +93,25 @@ func init() { } var fileDescriptor_e0c60a0709a0040c = []byte{ - // 297 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x6a, 0xeb, 0x30, - 0x14, 0x86, 0xad, 0x7b, 0x4b, 0x69, 0x94, 0x4c, 0xa6, 0x14, 0x93, 0x82, 0x12, 0xb2, 0xd4, 0x50, - 0x22, 0x11, 0x77, 0x2a, 0x74, 0x4a, 0xa7, 0x0e, 0x85, 0xe0, 0xa1, 0x43, 0x17, 0x63, 0xc9, 0xc2, - 0x16, 0xb1, 0x2d, 0x23, 0xcb, 0x82, 0xbc, 0x45, 0x1f, 0xa5, 0x8f, 0x91, 0x31, 0x63, 0xa7, 0x52, - 0xec, 0x17, 0x29, 0x8e, 0x8b, 0xd1, 0x26, 0x1d, 0x3e, 0xbe, 0xff, 0x9c, 0x1f, 0xde, 0x0b, 0xca, - 0x08, 0x93, 0x8a, 0x93, 0x2a, 0x66, 0x7b, 0xae, 0x6b, 0xae, 0x0c, 0x57, 0xc4, 0x6c, 0x08, 0x93, - 0x4d, 0xa9, 0xb9, 0xaa, 0x62, 0xa5, 0x0f, 0xb8, 0x52, 0x52, 0x4b, 0xd7, 0x13, 0x94, 0xe1, 0x1e, - 0xc6, 0x36, 0x8c, 0xcd, 0x66, 0x7e, 0x9d, 0xca, 0x54, 0x9e, 0x21, 0xd2, 0xbf, 0x06, 0x7e, 0x7e, - 0x37, 0xca, 0x99, 0x2c, 0x0a, 0xa1, 0x0b, 0x5e, 0x6a, 0x62, 0x02, 0xeb, 0x37, 0x80, 0xab, 0x4f, - 0x00, 0x67, 0xcf, 0x56, 0x9e, 0x7b, 0x0b, 0x27, 0x2c, 0x17, 0xbc, 0xd4, 0x91, 0x48, 0x3c, 0xb0, - 0x04, 0xfe, 0x24, 0xbc, 0x1a, 0x06, 0x2f, 0x89, 0xbb, 0x80, 0xd3, 0x21, 0x3f, 0xaa, 0x62, 0x9d, - 0x79, 0xff, 0x96, 0xc0, 0x9f, 0x85, 0x70, 0x18, 0xed, 0x62, 0x9d, 0xb9, 0x14, 0x7a, 0xf6, 0xf6, - 0x91, 0x4d, 0xff, 0x5f, 0x02, 0x7f, 0x1a, 0xac, 0xf0, 0x78, 0x8a, 0xb5, 0x8c, 0x09, 0xf0, 0x2b, - 0x57, 0xfb, 0x9c, 0xf7, 0x96, 0xed, 0xc5, 0xf1, 0x7b, 0xe1, 0x84, 0x37, 0xb6, 0x69, 0x37, 0x66, - 0x6c, 0xdf, 0x8e, 0x2d, 0x02, 0xa7, 0x16, 0x81, 0x9f, 0x16, 0x81, 0x8f, 0x0e, 0x39, 0xa7, 0x0e, - 0x39, 0x5f, 0x1d, 0x72, 0xde, 0x9f, 0x52, 0xa1, 0xb3, 0x86, 0xf6, 0x62, 0xc2, 0x64, 0x5d, 0xc8, - 0x9a, 0x08, 0xca, 0xd6, 0xa9, 0x24, 0xe6, 0x91, 0x14, 0x32, 0x69, 0x72, 0x5e, 0xdb, 0x95, 0xaf, - 0xff, 0x3a, 0xd7, 0x87, 0x8a, 0xd7, 0xf4, 0xf2, 0xdc, 0xc8, 0xc3, 0x6f, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xfb, 0xa6, 0x1a, 0x97, 0x99, 0x01, 0x00, 0x00, + // 281 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x3f, 0x4b, 0xc3, 0x40, + 0x18, 0xc6, 0x73, 0x28, 0x62, 0xa3, 0x53, 0x11, 0x09, 0x15, 0xce, 0xd2, 0xc5, 0x82, 0xf4, 0x8e, + 0xd6, 0x49, 0x70, 0xd2, 0xc9, 0x41, 0x28, 0x1d, 0x1c, 0x5c, 0x42, 0xee, 0x72, 0x24, 0x47, 0x93, + 0xbc, 0xe1, 0xf2, 0xe6, 0xa0, 0x9f, 0x42, 0x3f, 0x56, 0xc7, 0x8e, 0x4e, 0x22, 0xc9, 0x17, 0x91, + 0x24, 0x52, 0x6e, 0xbb, 0x3f, 0x3f, 0x7e, 0xef, 0xf3, 0x3e, 0xfe, 0xbd, 0x16, 0x92, 0x4b, 0x30, + 0x8a, 0x97, 0x91, 0xdc, 0x2a, 0xac, 0x94, 0xb1, 0xca, 0x70, 0xbb, 0xe4, 0x12, 0xea, 0x02, 0x95, + 0x29, 0x23, 0x83, 0x3b, 0x56, 0x1a, 0x40, 0x18, 0x07, 0x5a, 0x48, 0xd6, 0xc1, 0xcc, 0x85, 0x99, + 0x5d, 0x4e, 0xae, 0x12, 0x48, 0xa0, 0x87, 0x78, 0x77, 0x1a, 0xf8, 0xc9, 0xdd, 0x51, 0x2e, 0x21, + 0xcf, 0x35, 0xe6, 0xaa, 0x40, 0x6e, 0x57, 0xce, 0x6d, 0x00, 0x67, 0x9f, 0xc4, 0xbf, 0x7c, 0x71, + 0xe6, 0x8d, 0x6f, 0xfc, 0x91, 0xcc, 0xb4, 0x2a, 0x30, 0xd4, 0x71, 0x40, 0xa6, 0x64, 0x3e, 0xda, + 0x9c, 0x0f, 0x0f, 0xaf, 0xf1, 0x58, 0xf8, 0x81, 0x1b, 0x2e, 0x1c, 0xc2, 0x84, 0x65, 0x84, 0x69, + 0x70, 0x32, 0x25, 0xf3, 0x8b, 0xd5, 0x8c, 0x1d, 0x93, 0x3a, 0xb3, 0xec, 0x8a, 0xbd, 0x29, 0xb3, + 0xcd, 0xd4, 0x3a, 0xc2, 0xf4, 0xf9, 0x74, 0xff, 0x73, 0xeb, 0x6d, 0xae, 0x5d, 0xd3, 0xba, 0x17, + 0xf5, 0xbf, 0xef, 0xfb, 0x86, 0x92, 0x43, 0x43, 0xc9, 0x6f, 0x43, 0xc9, 0x57, 0x4b, 0xbd, 0x43, + 0x4b, 0xbd, 0xef, 0x96, 0x7a, 0x1f, 0x4f, 0x89, 0xc6, 0xb4, 0x16, 0x9d, 0x98, 0x4b, 0xa8, 0x72, + 0xa8, 0xb8, 0x16, 0x72, 0x91, 0x00, 0xb7, 0x8f, 0x3c, 0x87, 0xb8, 0xce, 0x54, 0xe5, 0x36, 0xba, + 0xf8, 0xaf, 0x14, 0x77, 0xa5, 0xaa, 0xc4, 0x59, 0xbf, 0xf0, 0xc3, 0x5f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x71, 0xdd, 0x46, 0x83, 0x78, 0x01, 0x00, 0x00, } func (m *Counterparty) Marshal() (dAtA []byte, err error) { @@ -152,13 +144,6 @@ func (m *Counterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x1a - if len(m.PacketPath) > 0 { - i -= len(m.PacketPath) - copy(dAtA[i:], m.PacketPath) - i = encodeVarintCounterparty(dAtA, i, uint64(len(m.PacketPath))) - i-- - dAtA[i] = 0x12 - } if len(m.ClientId) > 0 { i -= len(m.ClientId) copy(dAtA[i:], m.ClientId) @@ -190,10 +175,6 @@ func (m *Counterparty) Size() (n int) { if l > 0 { n += 1 + l + sovCounterparty(uint64(l)) } - l = len(m.PacketPath) - if l > 0 { - n += 1 + l + sovCounterparty(uint64(l)) - } l = m.CounterpartyPacketPath.Size() n += 1 + l + sovCounterparty(uint64(l)) return n @@ -266,40 +247,6 @@ func (m *Counterparty) Unmarshal(dAtA []byte) error { } m.ClientId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketPath", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCounterparty - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCounterparty - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCounterparty - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PacketPath = append(m.PacketPath[:0], dAtA[iNdEx:postIndex]...) - if m.PacketPath == nil { - m.PacketPath = []byte{} - } - iNdEx = postIndex case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyPacketPath", wireType) diff --git a/modules/core/packet-server/types/errors.go b/modules/core/packet-server/types/errors.go index 820864cb5b3..2322b7a34ce 100644 --- a/modules/core/packet-server/types/errors.go +++ b/modules/core/packet-server/types/errors.go @@ -7,4 +7,5 @@ import ( // IBC packet server sentinel errors var ( ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 1, "invalid counterparty") + ErrInvalidPacketPath = errorsmod.Register(SubModuleName, 2, "invalid packet path") ) diff --git a/modules/core/packet-server/types/msgs.go b/modules/core/packet-server/types/msgs.go index 46d67a133c0..fc297999a4b 100644 --- a/modules/core/packet-server/types/msgs.go +++ b/modules/core/packet-server/types/msgs.go @@ -1,12 +1,13 @@ package types import ( + "strings" + 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" ) @@ -17,12 +18,12 @@ var ( ) // NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance -func NewMsgProvideCounterparty(signer, clientID, counterpartyID string, counterpartyPacketPath commitmenttypes.MerklePath) *MsgProvideCounterparty { - counterparty := NewCounterparty(counterpartyID, counterpartyPacketPath) +func NewMsgProvideCounterparty(signer, packetPath, clientID string, counterpartyPacketPath commitmenttypes.MerklePath) *MsgProvideCounterparty { + counterparty := NewCounterparty(clientID, counterpartyPacketPath) return &MsgProvideCounterparty{ Signer: signer, - ClientId: clientID, + PacketPath: packetPath, Counterparty: counterparty, } } @@ -33,8 +34,8 @@ func (msg *MsgProvideCounterparty) ValidateBasic() error { 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 strings.TrimSpace(msg.PacketPath) == "" { + return errorsmod.Wrap(ErrInvalidPacketPath, "packet path cannot be empty") } if err := msg.Counterparty.Validate(); err != nil { diff --git a/modules/core/packet-server/types/tx.pb.go b/modules/core/packet-server/types/tx.pb.go index 8350e3a7fd0..3970ac1ceff 100644 --- a/modules/core/packet-server/types/tx.pb.go +++ b/modules/core/packet-server/types/tx.pb.go @@ -33,8 +33,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // 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 { - // client unique identifier - ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // unique identifier we will use to write all packet messages sent to counterparty + PacketPath string `protobuf:"bytes,1,opt,name=packet_path,json=packetPath,proto3" json:"packet_path,omitempty"` // counterparty client Counterparty Counterparty `protobuf:"bytes,2,opt,name=counterparty,proto3" json:"counterparty"` // signer address @@ -126,22 +126,22 @@ var fileDescriptor_3c556aec8b7966db = []byte{ 0x4c, 0x4a, 0xd6, 0x03, 0x29, 0xd1, 0x43, 0x56, 0xa2, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x4b, 0x69, 0xe3, 0x34, 0x32, 0x39, 0xbf, 0x34, 0xaf, 0x24, 0xb5, 0xa8, 0x20, 0xb1, 0xa8, 0xa4, 0x12, 0xaa, 0x58, 0x3c, 0x39, 0xbf, 0x38, 0x37, - 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0xa4, 0x22, 0xb7, 0x38, 0x1d, 0x22, 0xa1, 0xb4, 0x81, 0x91, + 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0xa4, 0x22, 0xb7, 0x38, 0x1d, 0x22, 0xa1, 0xb4, 0x85, 0x91, 0x4b, 0xcc, 0xb7, 0x38, 0x3d, 0xa0, 0x28, 0xbf, 0x2c, 0x33, 0x25, 0xd5, 0x19, 0x49, 0xa7, 0x90, - 0x34, 0x17, 0x67, 0x72, 0x4e, 0x66, 0x6a, 0x5e, 0x49, 0x7c, 0x66, 0x8a, 0x04, 0xa3, 0x02, 0xa3, - 0x06, 0x67, 0x10, 0x07, 0x44, 0xc0, 0x33, 0x45, 0x28, 0x80, 0x8b, 0x07, 0xd9, 0x1a, 0x09, 0x26, - 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x35, 0x3d, 0x5c, 0x9e, 0xd0, 0x43, 0x36, 0xda, 0x89, 0xe5, 0xc4, - 0x3d, 0x79, 0x86, 0x20, 0x14, 0x13, 0x84, 0xc4, 0xb8, 0xd8, 0x8a, 0x33, 0xd3, 0xf3, 0x52, 0x8b, - 0x24, 0x98, 0xc1, 0x76, 0x41, 0x79, 0x56, 0xfc, 0x1d, 0x0b, 0xe4, 0x19, 0x9a, 0x9e, 0x6f, 0xd0, - 0x82, 0x0a, 0x28, 0x29, 0x70, 0xc9, 0x61, 0x77, 0x71, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, - 0xaa, 0xd1, 0x04, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x46, 0x46, 0x2e, 0x61, 0x6c, 0x3e, - 0x33, 0xc0, 0xed, 0x4c, 0xec, 0x26, 0x4b, 0x59, 0x90, 0xaa, 0x03, 0xe6, 0x16, 0x29, 0xd6, 0x86, - 0xe7, 0x1b, 0xb4, 0x18, 0x9d, 0xc2, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, - 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, - 0xca, 0x26, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x1a, 0x4b, 0x99, - 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0x65, 0x96, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, 0x39, 0xa9, 0xc5, - 0xc8, 0xf1, 0xac, 0x0b, 0x8d, 0xe8, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x34, 0x1a, - 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x61, 0x52, 0xe3, 0xab, 0x61, 0x02, 0x00, 0x00, + 0x3c, 0x17, 0x37, 0xc4, 0xe4, 0xf8, 0x82, 0xc4, 0x92, 0x0c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, + 0x20, 0x2e, 0x88, 0x50, 0x40, 0x62, 0x49, 0x86, 0x50, 0x00, 0x17, 0x0f, 0xb2, 0x55, 0x12, 0x4c, + 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x6a, 0x7a, 0xb8, 0x3c, 0xa2, 0x87, 0x6c, 0xbc, 0x13, 0xcb, 0x89, + 0x7b, 0xf2, 0x0c, 0x41, 0x28, 0x26, 0x08, 0x89, 0x71, 0xb1, 0x15, 0x67, 0xa6, 0xe7, 0xa5, 0x16, + 0x49, 0x30, 0x83, 0x6d, 0x83, 0xf2, 0xac, 0xf8, 0x3b, 0x16, 0xc8, 0x33, 0x34, 0x3d, 0xdf, 0xa0, + 0x05, 0x15, 0x50, 0x52, 0xe0, 0x92, 0xc3, 0xee, 0xea, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, + 0x54, 0xa3, 0x09, 0x8c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0x8d, 0x8c, 0x5c, 0xc2, 0xd8, 0x7c, + 0x67, 0x80, 0xdb, 0x99, 0xd8, 0x4d, 0x96, 0xb2, 0x20, 0x55, 0x07, 0xcc, 0x2d, 0x52, 0xac, 0x0d, + 0xcf, 0x37, 0x68, 0x31, 0x3a, 0x85, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, + 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, + 0x94, 0x4d, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0xa6, 0x32, + 0x93, 0x92, 0x75, 0xd3, 0xf3, 0xf5, 0xcb, 0x2c, 0xf5, 0x73, 0xf3, 0x53, 0x4a, 0x73, 0x52, 0x8b, + 0x91, 0xe3, 0x5a, 0x17, 0x1a, 0xd9, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xa8, 0x34, + 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x7b, 0xc6, 0x4b, 0xac, 0x65, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -263,10 +263,10 @@ func (m *MsgProvideCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) } 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))) + if len(m.PacketPath) > 0 { + i -= len(m.PacketPath) + copy(dAtA[i:], m.PacketPath) + i = encodeVarintTx(dAtA, i, uint64(len(m.PacketPath))) i-- dAtA[i] = 0xa } @@ -313,7 +313,7 @@ func (m *MsgProvideCounterparty) Size() (n int) { } var l int _ = l - l = len(m.ClientId) + l = len(m.PacketPath) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -372,7 +372,7 @@ func (m *MsgProvideCounterparty) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientId", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PacketPath", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -400,7 +400,7 @@ func (m *MsgProvideCounterparty) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ClientId = string(dAtA[iNdEx:postIndex]) + m.PacketPath = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { diff --git a/modules/core/types/codec.go b/modules/core/types/codec.go index 270096bc88d..28b008ce3f6 100644 --- a/modules/core/types/codec.go +++ b/modules/core/types/codec.go @@ -7,6 +7,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/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. @@ -15,5 +16,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { clienttypes.RegisterInterfaces(registry) connectiontypes.RegisterInterfaces(registry) channeltypes.RegisterInterfaces(registry) + packetservertypes.RegisterInterfaces(registry) commitmenttypes.RegisterInterfaces(registry) } diff --git a/modules/light-clients/08-wasm/testing/simapp/app.go b/modules/light-clients/08-wasm/testing/simapp/app.go index 5f09c0a47cc..583cb82e709 100644 --- a/modules/light-clients/08-wasm/testing/simapp/app.go +++ b/modules/light-clients/08-wasm/testing/simapp/app.go @@ -418,7 +418,7 @@ func NewSimApp( ) // setup packet server keeper for Eureka tests - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) + app.PacketServer = packetserverkeeper.NewKeeper(appCodec, keys[ibcexported.StoreKey], app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) govConfig := govtypes.DefaultConfig() /* diff --git a/proto/ibc/core/packetserver/v1/tx.proto b/proto/ibc/core/packetserver/v1/tx.proto index 00e2e8c5c78..446fe811f95 100644 --- a/proto/ibc/core/packetserver/v1/tx.proto +++ b/proto/ibc/core/packetserver/v1/tx.proto @@ -25,7 +25,7 @@ message MsgProvideCounterparty { option (gogoproto.goproto_getters) = false; // unique identifier we will use to write all packet messages sent to counterparty - string packetPath = 1; + string packet_path = 1; // counterparty client Counterparty counterparty = 2 [(gogoproto.nullable) = false]; // signer address diff --git a/testing/endpoint.go b/testing/endpoint.go index 89b4125fb78..9a398b8e3ff 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -19,6 +19,7 @@ import ( 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" ) @@ -179,7 +180,7 @@ func (endpoint *Endpoint) FreezeClient() { func (endpoint *Endpoint) ProvideCounterparty() (err error) { merklePath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) - msg := clienttypes.NewMsgProvideCounterparty(endpoint.Chain.SenderAccount.GetAddress().String(), endpoint.ClientID, endpoint.Counterparty.ClientID, &merklePath) + msg := packetservertypes.NewMsgProvideCounterparty(endpoint.Chain.SenderAccount.GetAddress().String(), endpoint.ClientID, endpoint.Counterparty.ClientID, merklePath) // setup counterparty _, err = endpoint.Chain.SendMsgs(msg) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 87c5f1c7b43..cb5a7d3745e 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -373,7 +373,7 @@ func NewSimApp( ) // Setup packet server to call on Eureka tests - app.PacketServer = packetserverkeeper.NewKeeper(appCodec, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) + app.PacketServer = packetserverkeeper.NewKeeper(appCodec, keys[ibcexported.StoreKey], app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper) govConfig := govtypes.DefaultConfig() /* From faa9add6b380740ddbdf5acfe3ab3a2f7611c748 Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:47:10 +0200 Subject: [PATCH 4/8] add in channel id and leave merkle path as a prefix --- modules/core/02-client/types/keys.go | 5 - modules/core/04-channel/keeper/keeper.go | 4 +- modules/core/keeper/msg_server.go | 4 +- modules/core/keeper/msg_server_test.go | 2 +- .../core/packet-server/keeper/keeper_test.go | 4 +- modules/core/packet-server/keeper/relay.go | 6 +- .../core/packet-server/types/counterparty.go | 13 ++- .../packet-server/types/counterparty.pb.go | 109 +++++++++++++----- .../packet-server/types/counterparty_test.go | 13 ++- modules/core/packet-server/types/msgs.go | 15 +-- modules/core/packet-server/types/tx.pb.go | 48 ++++---- .../core/packetserver/v1/counterparty.proto | 7 +- proto/ibc/core/packetserver/v1/tx.proto | 2 +- 13 files changed, 149 insertions(+), 83 deletions(-) diff --git a/modules/core/02-client/types/keys.go b/modules/core/02-client/types/keys.go index 29604c2816e..2a37e3588fe 100644 --- a/modules/core/02-client/types/keys.go +++ b/modules/core/02-client/types/keys.go @@ -37,11 +37,6 @@ const ( // 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" - - // CounterpartyKey is the key used to store counterparty in the client store. - // the counterparty key is imported from types instead of host because - // the counterparty key is not a part of the ics-24 host specification - CounterpartyKey = "counterparty" ) // FormatClientIdentifier returns the client identifier with the sequence appended. diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 2ae9180dcba..5055c5d8624 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -115,8 +115,8 @@ func (k *Keeper) GetV2Counterparty(ctx sdk.Context, portID, channelID string) (p } merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte("")) counterparty := packetserver.Counterparty{ - ClientId: connection.ClientId, - CounterpartyPacketPath: merklePathPrefix, + ClientId: connection.ClientId, + MerklePathPrefix: merklePathPrefix, } return counterparty, true } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 7b46379f126..97a85e40dc6 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -157,11 +157,11 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertyp return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "client creator (%s) must match signer (%s)", creator, msg.Signer) } - if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.PacketPath); ok { + if _, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ChannelId); ok { return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty already exists for client %s", msg.Counterparty.ClientId) } - k.PacketServerKeeper.SetCounterparty(ctx, msg.PacketPath, msg.Counterparty) + k.PacketServerKeeper.SetCounterparty(ctx, msg.ChannelId, msg.Counterparty) // Delete client creator from state as it is not needed after this point. k.ClientKeeper.DeleteCreator(ctx, msg.Counterparty.ClientId) diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 079aa705313..1c81eba7371 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -812,7 +812,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() { "failure: counterparty already exists", func() { // set it before handler - suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.PacketPath, msg.Counterparty) + suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ChannelId, msg.Counterparty) }, packetservertypes.ErrInvalidCounterparty, }, diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go index 23f7312f31f..0a2cf57444b 100644 --- a/modules/core/packet-server/keeper/keeper_test.go +++ b/modules/core/packet-server/keeper/keeper_test.go @@ -58,8 +58,8 @@ func (suite *KeeperTestSuite) SetupTest() { func (suite *KeeperTestSuite) TestSetCounterparty() { merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) counterparty := types.Counterparty{ - ClientId: testClientID, - CounterpartyPacketPath: merklePathPrefix, + ClientId: testClientID, + MerklePathPrefix: merklePathPrefix, } suite.keeper.SetCounterparty(suite.ctx, testClientID, counterparty) diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go index 6878844ba80..1be8df18373 100644 --- a/modules/core/packet-server/keeper/relay.go +++ b/modules/core/packet-server/keeper/relay.go @@ -133,7 +133,7 @@ func (k Keeper) RecvPacket( // create key/value pair for proof verification by appending the ICS24 path to the last element of the counterparty merklepath // TODO: allow for custom prefix path := host.PacketCommitmentKey(packet.SourcePort, packet.SourceChannel, packet.Sequence) - merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + merklePath := types.BuildMerklePath(&counterparty.MerklePathPrefix, path) commitment := channeltypes.CommitPacket(packet) @@ -260,7 +260,7 @@ func (k Keeper) AcknowledgePacket( } path := host.PacketAcknowledgementKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + merklePath := types.BuildMerklePath(&counterparty.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyMembership( ctx, @@ -339,7 +339,7 @@ func (k Keeper) TimeoutPacket( // verify packet receipt absence path := host.PacketReceiptKey(packet.DestinationPort, packet.DestinationChannel, packet.Sequence) - merklePath := types.BuildMerklePath(&counterparty.CounterpartyPacketPath, path) + merklePath := types.BuildMerklePath(&counterparty.MerklePathPrefix, path) if err := k.ClientKeeper.VerifyNonMembership( ctx, diff --git a/modules/core/packet-server/types/counterparty.go b/modules/core/packet-server/types/counterparty.go index d6ce9fb5216..5073e7c36d3 100644 --- a/modules/core/packet-server/types/counterparty.go +++ b/modules/core/packet-server/types/counterparty.go @@ -8,10 +8,11 @@ import ( ) // NewCounterparty creates a new Counterparty instance -func NewCounterparty(clientID string, counterpartyPacketPath commitmenttypes.MerklePath) Counterparty { +func NewCounterparty(clientID, channelID string, merklePathPrefix commitmenttypes.MerklePath) Counterparty { return Counterparty{ - ClientId: clientID, - CounterpartyPacketPath: counterpartyPacketPath, + ClientId: clientID, + CounterpartyChannel: channelID, + MerklePathPrefix: merklePathPrefix, } } @@ -21,7 +22,11 @@ func (c Counterparty) Validate() error { return err } - if c.CounterpartyPacketPath.Empty() { + if err := host.ChannelIdentifierValidator(c.CounterpartyChannel); err != nil { + return err + } + + if c.MerklePathPrefix.Empty() { return errorsmod.Wrap(ErrInvalidCounterparty, "prefix cannot be empty") } diff --git a/modules/core/packet-server/types/counterparty.pb.go b/modules/core/packet-server/types/counterparty.pb.go index 6caa224c556..5d898f114e5 100644 --- a/modules/core/packet-server/types/counterparty.pb.go +++ b/modules/core/packet-server/types/counterparty.pb.go @@ -31,10 +31,11 @@ type Counterparty struct { // the client identifier of the counterparty chain // client id of the counterparty stored on our chain ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + // the counterparty channel identifier that must be used by the packet + CounterpartyChannel string `protobuf:"bytes,2,opt,name=counterparty_channel,json=counterpartyChannel,proto3" json:"counterparty_channel,omitempty"` // the key path used to store packet flow messages that the counterparty - // will use to send to us. - // ["ibc", "channel/channel-4"] => ["ibc", "channel/channel-4/port/transfer/sequence/1"] - CounterpartyPacketPath v2.MerklePath `protobuf:"bytes,3,opt,name=counterparty_packet_path,json=counterpartyPacketPath,proto3" json:"counterparty_packet_path"` + // will use to send to us. We will append the channelID and sequence in order to create the final path. + MerklePathPrefix v2.MerklePath `protobuf:"bytes,3,opt,name=merkle_path_prefix,json=merklePathPrefix,proto3" json:"merkle_path_prefix"` } func (m *Counterparty) Reset() { *m = Counterparty{} } @@ -77,9 +78,16 @@ func (m *Counterparty) GetClientId() string { return "" } -func (m *Counterparty) GetCounterpartyPacketPath() v2.MerklePath { +func (m *Counterparty) GetCounterpartyChannel() string { if m != nil { - return m.CounterpartyPacketPath + return m.CounterpartyChannel + } + return "" +} + +func (m *Counterparty) GetMerklePathPrefix() v2.MerklePath { + if m != nil { + return m.MerklePathPrefix } return v2.MerklePath{} } @@ -93,25 +101,27 @@ func init() { } var fileDescriptor_e0c60a0709a0040c = []byte{ - // 281 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x3f, 0x4b, 0xc3, 0x40, - 0x18, 0xc6, 0x73, 0x28, 0x62, 0xa3, 0x53, 0x11, 0x09, 0x15, 0xce, 0xd2, 0xc5, 0x82, 0xf4, 0x8e, - 0xd6, 0x49, 0x70, 0xd2, 0xc9, 0x41, 0x28, 0x1d, 0x1c, 0x5c, 0x42, 0xee, 0x72, 0x24, 0x47, 0x93, - 0xbc, 0xe1, 0xf2, 0xe6, 0xa0, 0x9f, 0x42, 0x3f, 0x56, 0xc7, 0x8e, 0x4e, 0x22, 0xc9, 0x17, 0x91, - 0x24, 0x52, 0x6e, 0xbb, 0x3f, 0x3f, 0x7e, 0xef, 0xf3, 0x3e, 0xfe, 0xbd, 0x16, 0x92, 0x4b, 0x30, - 0x8a, 0x97, 0x91, 0xdc, 0x2a, 0xac, 0x94, 0xb1, 0xca, 0x70, 0xbb, 0xe4, 0x12, 0xea, 0x02, 0x95, - 0x29, 0x23, 0x83, 0x3b, 0x56, 0x1a, 0x40, 0x18, 0x07, 0x5a, 0x48, 0xd6, 0xc1, 0xcc, 0x85, 0x99, - 0x5d, 0x4e, 0xae, 0x12, 0x48, 0xa0, 0x87, 0x78, 0x77, 0x1a, 0xf8, 0xc9, 0xdd, 0x51, 0x2e, 0x21, - 0xcf, 0x35, 0xe6, 0xaa, 0x40, 0x6e, 0x57, 0xce, 0x6d, 0x00, 0x67, 0x9f, 0xc4, 0xbf, 0x7c, 0x71, - 0xe6, 0x8d, 0x6f, 0xfc, 0x91, 0xcc, 0xb4, 0x2a, 0x30, 0xd4, 0x71, 0x40, 0xa6, 0x64, 0x3e, 0xda, - 0x9c, 0x0f, 0x0f, 0xaf, 0xf1, 0x58, 0xf8, 0x81, 0x1b, 0x2e, 0x1c, 0xc2, 0x84, 0x65, 0x84, 0x69, - 0x70, 0x32, 0x25, 0xf3, 0x8b, 0xd5, 0x8c, 0x1d, 0x93, 0x3a, 0xb3, 0xec, 0x8a, 0xbd, 0x29, 0xb3, - 0xcd, 0xd4, 0x3a, 0xc2, 0xf4, 0xf9, 0x74, 0xff, 0x73, 0xeb, 0x6d, 0xae, 0x5d, 0xd3, 0xba, 0x17, - 0xf5, 0xbf, 0xef, 0xfb, 0x86, 0x92, 0x43, 0x43, 0xc9, 0x6f, 0x43, 0xc9, 0x57, 0x4b, 0xbd, 0x43, - 0x4b, 0xbd, 0xef, 0x96, 0x7a, 0x1f, 0x4f, 0x89, 0xc6, 0xb4, 0x16, 0x9d, 0x98, 0x4b, 0xa8, 0x72, - 0xa8, 0xb8, 0x16, 0x72, 0x91, 0x00, 0xb7, 0x8f, 0x3c, 0x87, 0xb8, 0xce, 0x54, 0xe5, 0x36, 0xba, - 0xf8, 0xaf, 0x14, 0x77, 0xa5, 0xaa, 0xc4, 0x59, 0xbf, 0xf0, 0xc3, 0x5f, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x71, 0xdd, 0x46, 0x83, 0x78, 0x01, 0x00, 0x00, + // 307 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x31, 0x4e, 0xc3, 0x30, + 0x18, 0x85, 0x63, 0x40, 0x88, 0x06, 0x06, 0x14, 0x3a, 0x44, 0x45, 0x32, 0x55, 0x17, 0x2a, 0xa1, + 0xda, 0x6a, 0x99, 0x90, 0x98, 0xda, 0x89, 0x01, 0xa9, 0xea, 0xd0, 0x81, 0x25, 0x4a, 0xdc, 0x9f, + 0xc4, 0x6a, 0x1c, 0x5b, 0x8e, 0x6b, 0xd1, 0x5b, 0x70, 0x1a, 0xce, 0xd0, 0xb1, 0x23, 0x13, 0x42, + 0xed, 0x45, 0x50, 0x12, 0x14, 0x79, 0xb3, 0xff, 0xf7, 0xf9, 0xf9, 0xfd, 0xcf, 0x7f, 0xe0, 0x09, + 0xa3, 0x4c, 0x6a, 0xa0, 0x2a, 0x66, 0x6b, 0x30, 0x25, 0x68, 0x0b, 0x9a, 0xda, 0x31, 0x65, 0x72, + 0x53, 0x18, 0xd0, 0x2a, 0xd6, 0x66, 0x4b, 0x94, 0x96, 0x46, 0x06, 0x21, 0x4f, 0x18, 0xa9, 0x60, + 0xe2, 0xc2, 0xc4, 0x8e, 0x7b, 0xdd, 0x54, 0xa6, 0xb2, 0x86, 0x68, 0x75, 0x6a, 0xf8, 0xde, 0x7d, + 0x6b, 0xce, 0xa4, 0x10, 0xdc, 0x08, 0x28, 0x0c, 0xb5, 0x13, 0xe7, 0xd6, 0x80, 0x83, 0x2f, 0xe4, + 0x5f, 0xcd, 0x9c, 0xff, 0x82, 0x5b, 0xbf, 0xc3, 0x72, 0x0e, 0x85, 0x89, 0xf8, 0x2a, 0x44, 0x7d, + 0x34, 0xec, 0x2c, 0x2e, 0x9a, 0xc1, 0xcb, 0x2a, 0x18, 0xfb, 0x5d, 0x37, 0x5c, 0xc4, 0xb2, 0xb8, + 0x28, 0x20, 0x0f, 0x4f, 0x6a, 0xee, 0xc6, 0xd5, 0x66, 0x8d, 0x14, 0x2c, 0xfd, 0x40, 0x80, 0x5e, + 0xe7, 0x10, 0xa9, 0xd8, 0x64, 0x91, 0xd2, 0xf0, 0xce, 0x3f, 0xc2, 0xd3, 0x3e, 0x1a, 0x5e, 0x4e, + 0x06, 0xa4, 0x5d, 0xcb, 0x09, 0x66, 0x27, 0xe4, 0xb5, 0x7e, 0x31, 0x8f, 0x4d, 0x36, 0x3d, 0xdb, + 0xfd, 0xdc, 0x79, 0x8b, 0x6b, 0xd1, 0x4e, 0xe6, 0xb5, 0xc3, 0x74, 0xb9, 0x3b, 0x60, 0xb4, 0x3f, + 0x60, 0xf4, 0x7b, 0xc0, 0xe8, 0xf3, 0x88, 0xbd, 0xfd, 0x11, 0x7b, 0xdf, 0x47, 0xec, 0xbd, 0x3d, + 0xa7, 0xdc, 0x64, 0x9b, 0xa4, 0xb2, 0xa4, 0x4c, 0x96, 0x42, 0x96, 0x94, 0x27, 0x6c, 0x94, 0x4a, + 0x6a, 0x9f, 0xa8, 0x90, 0xab, 0x4d, 0x0e, 0xa5, 0x5b, 0xfc, 0xe8, 0xbf, 0x79, 0xb3, 0x55, 0x50, + 0x26, 0xe7, 0x75, 0x2f, 0x8f, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8e, 0x3b, 0xa6, 0xaa, 0x9f, + 0x01, 0x00, 0x00, } func (m *Counterparty) Marshal() (dAtA []byte, err error) { @@ -135,7 +145,7 @@ func (m *Counterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.CounterpartyPacketPath.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.MerklePathPrefix.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -144,6 +154,13 @@ func (m *Counterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) { } i-- dAtA[i] = 0x1a + if len(m.CounterpartyChannel) > 0 { + i -= len(m.CounterpartyChannel) + copy(dAtA[i:], m.CounterpartyChannel) + i = encodeVarintCounterparty(dAtA, i, uint64(len(m.CounterpartyChannel))) + i-- + dAtA[i] = 0x12 + } if len(m.ClientId) > 0 { i -= len(m.ClientId) copy(dAtA[i:], m.ClientId) @@ -175,7 +192,11 @@ func (m *Counterparty) Size() (n int) { if l > 0 { n += 1 + l + sovCounterparty(uint64(l)) } - l = m.CounterpartyPacketPath.Size() + l = len(m.CounterpartyChannel) + if l > 0 { + n += 1 + l + sovCounterparty(uint64(l)) + } + l = m.MerklePathPrefix.Size() n += 1 + l + sovCounterparty(uint64(l)) return n } @@ -247,9 +268,41 @@ func (m *Counterparty) Unmarshal(dAtA []byte) error { } m.ClientId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyChannel", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCounterparty + } + 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 ErrInvalidLengthCounterparty + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCounterparty + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CounterpartyChannel = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CounterpartyPacketPath", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MerklePathPrefix", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -276,7 +329,7 @@ func (m *Counterparty) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.CounterpartyPacketPath.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.MerklePathPrefix.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/modules/core/packet-server/types/counterparty_test.go b/modules/core/packet-server/types/counterparty_test.go index 9e036c4c51c..d79db9ceacb 100644 --- a/modules/core/packet-server/types/counterparty_test.go +++ b/modules/core/packet-server/types/counterparty_test.go @@ -14,24 +14,35 @@ func TestValidateCounterparty(t *testing.T) { testCases := []struct { name string clientID string + channelID string merklePathPrefix commitmenttypes.MerklePath expError error }{ { "success", ibctesting.FirstClientID, + ibctesting.FirstChannelID, commitmenttypes.NewMerklePath([]byte("ibc")), nil, }, { "failure: invalid client id", "", + ibctesting.FirstChannelID, + commitmenttypes.NewMerklePath([]byte("ibc")), + host.ErrInvalidID, + }, + { + "failure: invalid counterparty channel id", + ibctesting.FirstClientID, + "", commitmenttypes.NewMerklePath([]byte("ibc")), host.ErrInvalidID, }, { "failure: empty merkle path prefix", ibctesting.FirstClientID, + ibctesting.FirstChannelID, commitmenttypes.NewMerklePath(), types.ErrInvalidCounterparty, }, @@ -40,7 +51,7 @@ func TestValidateCounterparty(t *testing.T) { for _, tc := range testCases { tc := tc - counterparty := types.NewCounterparty(tc.clientID, tc.merklePathPrefix) + counterparty := types.NewCounterparty(tc.clientID, tc.channelID, tc.merklePathPrefix) err := counterparty.Validate() expPass := tc.expError == nil diff --git a/modules/core/packet-server/types/msgs.go b/modules/core/packet-server/types/msgs.go index fc297999a4b..33fab11e606 100644 --- a/modules/core/packet-server/types/msgs.go +++ b/modules/core/packet-server/types/msgs.go @@ -1,13 +1,12 @@ package types import ( - "strings" - 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" ) @@ -18,12 +17,14 @@ var ( ) // NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance -func NewMsgProvideCounterparty(signer, packetPath, clientID string, counterpartyPacketPath commitmenttypes.MerklePath) *MsgProvideCounterparty { - counterparty := NewCounterparty(clientID, counterpartyPacketPath) +// MsgProvideCounterparty will set the channel id to the client id for this chain. It is only allowed to be different +// for existing v1 channels that are aliased to a new Eureka counterparty. +func NewMsgProvideCounterparty(signer, clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath) *MsgProvideCounterparty { + counterparty := NewCounterparty(clientID, counterpartyChannelID, merklePathPrefix) return &MsgProvideCounterparty{ Signer: signer, - PacketPath: packetPath, + ChannelId: clientID, Counterparty: counterparty, } } @@ -34,8 +35,8 @@ func (msg *MsgProvideCounterparty) ValidateBasic() error { return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } - if strings.TrimSpace(msg.PacketPath) == "" { - return errorsmod.Wrap(ErrInvalidPacketPath, "packet path cannot be empty") + if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil { + return err } if err := msg.Counterparty.Validate(); err != nil { diff --git a/modules/core/packet-server/types/tx.pb.go b/modules/core/packet-server/types/tx.pb.go index 3970ac1ceff..46212f381ec 100644 --- a/modules/core/packet-server/types/tx.pb.go +++ b/modules/core/packet-server/types/tx.pb.go @@ -34,7 +34,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // 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 - PacketPath string `protobuf:"bytes,1,opt,name=packet_path,json=packetPath,proto3" json:"packet_path,omitempty"` + ChannelId string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` // counterparty client Counterparty Counterparty `protobuf:"bytes,2,opt,name=counterparty,proto3" json:"counterparty"` // signer address @@ -119,29 +119,29 @@ func init() { func init() { proto.RegisterFile("ibc/core/packetserver/v1/tx.proto", fileDescriptor_3c556aec8b7966db) } var fileDescriptor_3c556aec8b7966db = []byte{ - // 350 bytes of a gzipped FileDescriptorProto + // 351 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x4c, 0x4a, 0xd6, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x48, 0x4c, 0xce, 0x4e, 0x2d, 0x29, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xc8, 0x4c, 0x4a, 0xd6, 0x03, 0x29, 0xd1, 0x43, 0x56, 0xa2, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa4, 0x0f, 0x62, 0x41, 0xd4, 0x4b, 0x69, 0xe3, 0x34, 0x32, 0x39, 0xbf, 0x34, 0xaf, 0x24, 0xb5, 0xa8, 0x20, 0xb1, 0xa8, 0xa4, 0x12, 0xaa, 0x58, 0x3c, 0x39, 0xbf, 0x38, 0x37, - 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0xa4, 0x22, 0xb7, 0x38, 0x1d, 0x22, 0xa1, 0xb4, 0x85, 0x91, + 0xbf, 0x58, 0x3f, 0xb7, 0x38, 0x1d, 0xa4, 0x22, 0xb7, 0x38, 0x1d, 0x22, 0xa1, 0xb4, 0x89, 0x91, 0x4b, 0xcc, 0xb7, 0x38, 0x3d, 0xa0, 0x28, 0xbf, 0x2c, 0x33, 0x25, 0xd5, 0x19, 0x49, 0xa7, 0x90, - 0x3c, 0x17, 0x37, 0xc4, 0xe4, 0xf8, 0x82, 0xc4, 0x92, 0x0c, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, - 0x20, 0x2e, 0x88, 0x50, 0x40, 0x62, 0x49, 0x86, 0x50, 0x00, 0x17, 0x0f, 0xb2, 0x55, 0x12, 0x4c, - 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x6a, 0x7a, 0xb8, 0x3c, 0xa2, 0x87, 0x6c, 0xbc, 0x13, 0xcb, 0x89, - 0x7b, 0xf2, 0x0c, 0x41, 0x28, 0x26, 0x08, 0x89, 0x71, 0xb1, 0x15, 0x67, 0xa6, 0xe7, 0xa5, 0x16, - 0x49, 0x30, 0x83, 0x6d, 0x83, 0xf2, 0xac, 0xf8, 0x3b, 0x16, 0xc8, 0x33, 0x34, 0x3d, 0xdf, 0xa0, - 0x05, 0x15, 0x50, 0x52, 0xe0, 0x92, 0xc3, 0xee, 0xea, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, - 0x54, 0xa3, 0x09, 0x8c, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0x8d, 0x8c, 0x5c, 0xc2, 0xd8, 0x7c, - 0x67, 0x80, 0xdb, 0x99, 0xd8, 0x4d, 0x96, 0xb2, 0x20, 0x55, 0x07, 0xcc, 0x2d, 0x52, 0xac, 0x0d, - 0xcf, 0x37, 0x68, 0x31, 0x3a, 0x85, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, - 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, - 0x94, 0x4d, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x34, 0xa6, 0x32, - 0x93, 0x92, 0x75, 0xd3, 0xf3, 0xf5, 0xcb, 0x2c, 0xf5, 0x73, 0xf3, 0x53, 0x4a, 0x73, 0x52, 0x8b, - 0x91, 0xe3, 0x5a, 0x17, 0x1a, 0xd9, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xa8, 0x34, - 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x7b, 0xc6, 0x4b, 0xac, 0x65, 0x02, 0x00, 0x00, + 0x2c, 0x17, 0x57, 0x72, 0x46, 0x62, 0x5e, 0x5e, 0x6a, 0x4e, 0x7c, 0x66, 0x8a, 0x04, 0xa3, 0x02, + 0xa3, 0x06, 0x67, 0x10, 0x27, 0x54, 0xc4, 0x33, 0x45, 0x28, 0x80, 0x8b, 0x07, 0xd9, 0x22, 0x09, + 0x26, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x35, 0x3d, 0x5c, 0xde, 0xd0, 0x43, 0x36, 0xdc, 0x89, 0xe5, + 0xc4, 0x3d, 0x79, 0x86, 0x20, 0x14, 0x13, 0x84, 0xc4, 0xb8, 0xd8, 0x8a, 0x33, 0xd3, 0xf3, 0x52, + 0x8b, 0x24, 0x98, 0xc1, 0x96, 0x41, 0x79, 0x56, 0xfc, 0x1d, 0x0b, 0xe4, 0x19, 0x9a, 0x9e, 0x6f, + 0xd0, 0x82, 0x0a, 0x28, 0x29, 0x70, 0xc9, 0x61, 0x77, 0x73, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, + 0x71, 0xaa, 0xd1, 0x04, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x46, 0x46, 0x2e, 0x61, 0x6c, + 0x7e, 0x33, 0xc0, 0xed, 0x4c, 0xec, 0x26, 0x4b, 0x59, 0x90, 0xaa, 0x03, 0xe6, 0x16, 0x29, 0xd6, + 0x86, 0xe7, 0x1b, 0xb4, 0x18, 0x9d, 0xc2, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, + 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, + 0x21, 0xca, 0x26, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x1a, 0x4f, + 0x99, 0x49, 0xc9, 0xba, 0xe9, 0xf9, 0xfa, 0x65, 0x96, 0xfa, 0xb9, 0xf9, 0x29, 0xa5, 0x39, 0xa9, + 0xc5, 0xc8, 0x31, 0xad, 0x0b, 0x8d, 0xea, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0x44, + 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x77, 0x6d, 0x15, 0x38, 0x63, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -263,10 +263,10 @@ func (m *MsgProvideCounterparty) MarshalToSizedBuffer(dAtA []byte) (int, error) } i-- dAtA[i] = 0x12 - if len(m.PacketPath) > 0 { - i -= len(m.PacketPath) - copy(dAtA[i:], m.PacketPath) - i = encodeVarintTx(dAtA, i, uint64(len(m.PacketPath))) + 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 } @@ -313,7 +313,7 @@ func (m *MsgProvideCounterparty) Size() (n int) { } var l int _ = l - l = len(m.PacketPath) + l = len(m.ChannelId) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -372,7 +372,7 @@ func (m *MsgProvideCounterparty) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PacketPath", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -400,7 +400,7 @@ func (m *MsgProvideCounterparty) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PacketPath = string(dAtA[iNdEx:postIndex]) + m.ChannelId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { diff --git a/proto/ibc/core/packetserver/v1/counterparty.proto b/proto/ibc/core/packetserver/v1/counterparty.proto index 34a41650fd1..f85bd2d4728 100644 --- a/proto/ibc/core/packetserver/v1/counterparty.proto +++ b/proto/ibc/core/packetserver/v1/counterparty.proto @@ -14,8 +14,9 @@ message Counterparty { // the client identifier of the counterparty chain // client id of the counterparty stored on our chain string client_id = 1; + // the counterparty channel identifier that must be used by the packet + string counterparty_channel = 2; // the key path used to store packet flow messages that the counterparty - // will use to send to us. - // ["ibc", "channel/channel-4"] => ["ibc", "channel/channel-4/port/transfer/sequence/1"] - ibc.core.commitment.v2.MerklePath counterparty_packet_path = 3 [(gogoproto.nullable) = false]; + // will use to send to us. We will append the channelID and sequence in order to create the final path. + ibc.core.commitment.v2.MerklePath merkle_path_prefix = 3 [(gogoproto.nullable) = false]; } diff --git a/proto/ibc/core/packetserver/v1/tx.proto b/proto/ibc/core/packetserver/v1/tx.proto index 446fe811f95..99507067561 100644 --- a/proto/ibc/core/packetserver/v1/tx.proto +++ b/proto/ibc/core/packetserver/v1/tx.proto @@ -25,7 +25,7 @@ message MsgProvideCounterparty { option (gogoproto.goproto_getters) = false; // unique identifier we will use to write all packet messages sent to counterparty - string packet_path = 1; + string channel_id = 1; // counterparty client Counterparty counterparty = 2 [(gogoproto.nullable) = false]; // signer address From 5b7152028f74407c8fd4b5283904c2c37584db7b Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:59:42 +0200 Subject: [PATCH 5/8] change relay logic to separate client id from channel id --- modules/core/packet-server/keeper/relay.go | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go index 1be8df18373..bb4ea8e5899 100644 --- a/modules/core/packet-server/keeper/relay.go +++ b/modules/core/packet-server/keeper/relay.go @@ -34,7 +34,8 @@ func (k Keeper) SendPacket( if !ok { return 0, channeltypes.ErrChannelNotFound } - destChannel := counterparty.ClientId + destChannel := counterparty.CounterpartyChannel + clientId := counterparty.ClientId // retrieve the sequence send for this channel // if no packets have been sent yet, initialize the sequence to 1. @@ -52,17 +53,17 @@ func (k Keeper) SendPacket( } // check that the client of counterparty chain is still active - if status := k.ClientKeeper.GetClientStatus(ctx, sourceChannel); status != exported.Active { - return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", sourceChannel, status) + if status := k.ClientKeeper.GetClientStatus(ctx, clientId); status != exported.Active { + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientId, status) } // retrieve latest height and timestamp of the client of counterparty chain - latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, sourceChannel) + latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, clientId) if latestHeight.IsZero() { return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", sourceChannel) } - latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, sourceChannel, latestHeight) + latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientId, latestHeight) if err != nil { return 0, err } @@ -107,9 +108,10 @@ func (k Keeper) RecvPacket( if !ok { return "", channeltypes.ErrChannelNotFound } - if counterparty.ClientId != packet.SourceChannel { + if counterparty.CounterpartyChannel != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier } + clientId := counterparty.ClientId // check if packet timed out by comparing it with the latest height of the chain selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) @@ -139,7 +141,7 @@ func (k Keeper) RecvPacket( if err := k.ClientKeeper.VerifyMembership( ctx, - packet.DestinationChannel, + clientId, proofHeight, 0, 0, proof, @@ -182,7 +184,7 @@ func (k Keeper) WriteAcknowledgement( if !ok { return channeltypes.ErrChannelNotFound } - if counterparty.ClientId != packet.SourceChannel { + if counterparty.CounterpartyChannel != packet.SourceChannel { return channeltypes.ErrInvalidChannelIdentifier } @@ -237,9 +239,10 @@ func (k Keeper) AcknowledgePacket( return "", channeltypes.ErrChannelNotFound } - if counterparty.ClientId != packet.DestinationChannel { + if counterparty.CounterpartyChannel != packet.DestinationChannel { return "", channeltypes.ErrInvalidChannelIdentifier } + clientId := counterparty.ClientId commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) if len(commitment) == 0 { @@ -264,7 +267,7 @@ func (k Keeper) AcknowledgePacket( if err := k.ClientKeeper.VerifyMembership( ctx, - packet.SourceChannel, + clientId, proofHeight, 0, 0, proofAcked, @@ -303,8 +306,9 @@ func (k Keeper) TimeoutPacket( if !ok { return "", channeltypes.ErrChannelNotFound } + clientId := counterparty.ClientId - if counterparty.ClientId != packet.DestinationChannel { + if counterparty.CounterpartyChannel != packet.DestinationChannel { return "", channeltypes.ErrInvalidChannelIdentifier } @@ -343,7 +347,7 @@ func (k Keeper) TimeoutPacket( if err := k.ClientKeeper.VerifyNonMembership( ctx, - packet.SourceChannel, + clientId, proofHeight, 0, 0, proof, From f4dc2b2f64ced4c4ac9c4de89524bbfb3a335440 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 9 Sep 2024 09:16:54 +0200 Subject: [PATCH 6/8] lint --- modules/core/packet-server/keeper/keeper.go | 1 + modules/core/packet-server/types/counterparty_test.go | 3 ++- modules/core/packet-server/types/msgs_test.go | 3 --- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index 75ce7681397..4a2bb47b981 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/exported" "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" diff --git a/modules/core/packet-server/types/counterparty_test.go b/modules/core/packet-server/types/counterparty_test.go index d79db9ceacb..ddf1cb0fe18 100644 --- a/modules/core/packet-server/types/counterparty_test.go +++ b/modules/core/packet-server/types/counterparty_test.go @@ -3,11 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v9/modules/core/24-host" "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ibctesting "github.com/cosmos/ibc-go/v9/testing" - "github.com/stretchr/testify/require" ) func TestValidateCounterparty(t *testing.T) { diff --git a/modules/core/packet-server/types/msgs_test.go b/modules/core/packet-server/types/msgs_test.go index 19a2cc5f629..b5e86540385 100644 --- a/modules/core/packet-server/types/msgs_test.go +++ b/modules/core/packet-server/types/msgs_test.go @@ -1,9 +1,6 @@ package types_test import ( - - //nolint:staticcheck - 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" From a752e415189a357273021a5e2b0801da29596b9f Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 9 Sep 2024 09:23:39 +0200 Subject: [PATCH 7/8] lint redux --- modules/core/packet-server/keeper/relay.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go index 8737a8eb92a..48d7dfe35b0 100644 --- a/modules/core/packet-server/keeper/relay.go +++ b/modules/core/packet-server/keeper/relay.go @@ -38,7 +38,7 @@ func (k Keeper) SendPacket( return 0, errorsmod.Wrap(types.ErrCounterpartyNotFound, sourceChannel) } destChannel := counterparty.CounterpartyChannel - clientId := counterparty.ClientId + clientID := counterparty.ClientId // retrieve the sequence send for this channel // if no packets have been sent yet, initialize the sequence to 1. @@ -56,17 +56,17 @@ func (k Keeper) SendPacket( } // check that the client of counterparty chain is still active - if status := k.ClientKeeper.GetClientStatus(ctx, clientId); status != exported.Active { - return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientId, status) + if status := k.ClientKeeper.GetClientStatus(ctx, clientID); status != exported.Active { + return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } // retrieve latest height and timestamp of the client of counterparty chain - latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, clientId) + latestHeight := k.ClientKeeper.GetClientLatestHeight(ctx, clientID) if latestHeight.IsZero() { return 0, errorsmod.Wrapf(clienttypes.ErrInvalidHeight, "cannot send packet using client (%s) with zero height", sourceChannel) } - latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientId, latestHeight) + latestTimestamp, err := k.ClientKeeper.GetClientTimestampAtHeight(ctx, clientID, latestHeight) if err != nil { return 0, err } @@ -120,7 +120,7 @@ func (k Keeper) RecvPacket( if counterparty.CounterpartyChannel != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier } - clientId := counterparty.ClientId + clientID := counterparty.ClientId // check if packet timed out by comparing it with the latest height of the chain selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano()) @@ -150,7 +150,7 @@ func (k Keeper) RecvPacket( if err := k.ClientKeeper.VerifyMembership( ctx, - clientId, + clientID, proofHeight, 0, 0, proof, @@ -260,7 +260,7 @@ func (k Keeper) AcknowledgePacket( if counterparty.CounterpartyChannel != packet.DestinationChannel { return "", channeltypes.ErrInvalidChannelIdentifier } - clientId := counterparty.ClientId + clientID := counterparty.ClientId commitment := k.ChannelKeeper.GetPacketCommitment(ctx, packet.SourcePort, packet.SourceChannel, packet.Sequence) if len(commitment) == 0 { @@ -285,7 +285,7 @@ func (k Keeper) AcknowledgePacket( if err := k.ClientKeeper.VerifyMembership( ctx, - clientId, + clientID, proofHeight, 0, 0, proofAcked, @@ -330,7 +330,7 @@ func (k Keeper) TimeoutPacket( if !ok { return "", errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.SourceChannel) } - clientId := counterparty.ClientId + clientID := counterparty.ClientId if counterparty.CounterpartyChannel != packet.DestinationChannel { return "", channeltypes.ErrInvalidChannelIdentifier @@ -371,7 +371,7 @@ func (k Keeper) TimeoutPacket( if err := k.ClientKeeper.VerifyNonMembership( ctx, - clientId, + clientID, proofHeight, 0, 0, proof, From a8b85692aeed499b4e00ae378ecf1fa769f8ed32 Mon Sep 17 00:00:00 2001 From: Aditya Sripal <14364734+AdityaSripal@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:35:11 +0200 Subject: [PATCH 8/8] wire GetV2Counterparty to packet server --- modules/core/packet-server/keeper/relay.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/core/packet-server/keeper/relay.go b/modules/core/packet-server/keeper/relay.go index bb4ea8e5899..46dcac74154 100644 --- a/modules/core/packet-server/keeper/relay.go +++ b/modules/core/packet-server/keeper/relay.go @@ -32,7 +32,16 @@ func (k Keeper) SendPacket( // Lookup counterparty associated with our source channel to retrieve the destination channel counterparty, ok := k.GetCounterparty(ctx, sourceChannel) if !ok { - return 0, channeltypes.ErrChannelNotFound + // If the counterparty is not found, attempt to retrieve a v1 channel from the channel keeper + // if it exists, then we will convert it to a v2 counterparty and store it in the packet server keeper + // for future use. + if counterparty, ok = k.ChannelKeeper.GetV2Counterparty(ctx, sourcePort, sourceChannel); ok { + // we can key on just the source channel here since channel ids are globally unique + k.SetCounterparty(ctx, sourceChannel, counterparty) + } else { + // if neither a counterparty nor channel is found then simply return an error + return 0, channeltypes.ErrChannelNotFound + } } destChannel := counterparty.CounterpartyChannel clientId := counterparty.ClientId @@ -106,7 +115,16 @@ func (k Keeper) RecvPacket( // Note: This can be implemented by the current keeper counterparty, ok := k.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + // If the counterparty is not found, attempt to retrieve a v1 channel from the channel keeper + // if it exists, then we will convert it to a v2 counterparty and store it in the packet server keeper + // for future use. + if counterparty, ok = k.ChannelKeeper.GetV2Counterparty(ctx, packet.DestinationPort, packet.DestinationChannel); ok { + // we can key on just the destination channel here since channel ids are globally unique + k.SetCounterparty(ctx, packet.DestinationChannel, counterparty) + } else { + // if neither a counterparty nor channel is found then simply return an error + return "", channeltypes.ErrChannelNotFound + } } if counterparty.CounterpartyChannel != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier