From 0cad2f1e1554ebb0b67f82ec48d8cd63965fe215 Mon Sep 17 00:00:00 2001 From: Daniel T <30197399+danwt@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:31:34 +0100 Subject: [PATCH] feat(lightclient): add an event when canonical channel is set (#1310) --- .../dymension/lightclient/events.proto | 12 + .../ante/ibc_msg_channel_open_ack.go | 10 +- x/lightclient/types/events.pb.go | 373 ++++++++++++++++++ 3 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 proto/dymensionxyz/dymension/lightclient/events.proto create mode 100644 x/lightclient/types/events.pb.go diff --git a/proto/dymensionxyz/dymension/lightclient/events.proto b/proto/dymensionxyz/dymension/lightclient/events.proto new file mode 100644 index 000000000..6ed67ef3e --- /dev/null +++ b/proto/dymensionxyz/dymension/lightclient/events.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; +package dymensionxyz.dymension.lightclient; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/dymensionxyz/dymension/v3/x/lightclient/types"; + +// EventSetCanonicalChannel : when the canonical channel of the rollapp is set +message EventSetCanonicalChannel { + string rollapp_id = 1; + string channel_id = 2; +} diff --git a/x/lightclient/ante/ibc_msg_channel_open_ack.go b/x/lightclient/ante/ibc_msg_channel_open_ack.go index 1ae00c0fb..066ef76e6 100644 --- a/x/lightclient/ante/ibc_msg_channel_open_ack.go +++ b/x/lightclient/ante/ibc_msg_channel_open_ack.go @@ -5,7 +5,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/dymensionxyz/dymension/v3/x/lightclient/types" "github.com/dymensionxyz/gerr-cosmos/gerrc" + "github.com/dymensionxyz/sdk-utils/utils/uevent" ) func (i IBCMessagesDecorator) HandleMsgChannelOpenAck(ctx sdk.Context, msg *ibcchanneltypes.MsgChannelOpenAck) error { @@ -31,9 +33,15 @@ func (i IBCMessagesDecorator) HandleMsgChannelOpenAck(ctx sdk.Context, msg *ibcc return errorsmod.Wrap(gerrc.ErrFailedPrecondition, "canonical channel already exists for the rollapp") } // Set this channel as the canonical channel for the rollapp - // TODO: emit event/log rollapp.ChannelId = msg.ChannelId i.rollappKeeper.SetRollapp(ctx, rollapp) + if err := uevent.EmitTypedEvent(ctx, &types.EventSetCanonicalChannel{ + RollappId: rollappID, + ChannelId: rollapp.ChannelId, + }); err != nil { + return errorsmod.Wrap(err, "emit typed event") + } + return nil } diff --git a/x/lightclient/types/events.pb.go b/x/lightclient/types/events.pb.go new file mode 100644 index 000000000..62f5aa4b7 --- /dev/null +++ b/x/lightclient/types/events.pb.go @@ -0,0 +1,373 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dymensionxyz/dymension/lightclient/events.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + 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 + +// EventSetCanonicalChannel : when the canonical channel of the rollapp is set +type EventSetCanonicalChannel struct { + RollappId string `protobuf:"bytes,1,opt,name=rollapp_id,json=rollappId,proto3" json:"rollapp_id,omitempty"` + ChannelId string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` +} + +func (m *EventSetCanonicalChannel) Reset() { *m = EventSetCanonicalChannel{} } +func (m *EventSetCanonicalChannel) String() string { return proto.CompactTextString(m) } +func (*EventSetCanonicalChannel) ProtoMessage() {} +func (*EventSetCanonicalChannel) Descriptor() ([]byte, []int) { + return fileDescriptor_95574d182027cfd8, []int{0} +} +func (m *EventSetCanonicalChannel) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventSetCanonicalChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventSetCanonicalChannel.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 *EventSetCanonicalChannel) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventSetCanonicalChannel.Merge(m, src) +} +func (m *EventSetCanonicalChannel) XXX_Size() int { + return m.Size() +} +func (m *EventSetCanonicalChannel) XXX_DiscardUnknown() { + xxx_messageInfo_EventSetCanonicalChannel.DiscardUnknown(m) +} + +var xxx_messageInfo_EventSetCanonicalChannel proto.InternalMessageInfo + +func (m *EventSetCanonicalChannel) GetRollappId() string { + if m != nil { + return m.RollappId + } + return "" +} + +func (m *EventSetCanonicalChannel) GetChannelId() string { + if m != nil { + return m.ChannelId + } + return "" +} + +func init() { + proto.RegisterType((*EventSetCanonicalChannel)(nil), "dymensionxyz.dymension.lightclient.EventSetCanonicalChannel") +} + +func init() { + proto.RegisterFile("dymensionxyz/dymension/lightclient/events.proto", fileDescriptor_95574d182027cfd8) +} + +var fileDescriptor_95574d182027cfd8 = []byte{ + // 212 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4f, 0xa9, 0xcc, 0x4d, + 0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0xab, 0xa8, 0xac, 0x42, 0x70, 0xf4, 0x73, 0x32, 0xd3, 0x33, 0x4a, + 0x92, 0x73, 0x32, 0x53, 0xf3, 0x4a, 0xf4, 0x53, 0xcb, 0x52, 0xf3, 0x4a, 0x8a, 0xf5, 0x0a, 0x8a, + 0xf2, 0x4b, 0xf2, 0x85, 0x94, 0x90, 0x35, 0xe8, 0xc1, 0x39, 0x7a, 0x48, 0x1a, 0xa4, 0x44, 0xd2, + 0xf3, 0xd3, 0xf3, 0xc1, 0xca, 0xf5, 0x41, 0x2c, 0x88, 0x4e, 0xa5, 0x08, 0x2e, 0x09, 0x57, 0x90, + 0x49, 0xc1, 0xa9, 0x25, 0xce, 0x89, 0x79, 0xf9, 0x79, 0x99, 0xc9, 0x89, 0x39, 0xce, 0x19, 0x89, + 0x79, 0x79, 0xa9, 0x39, 0x42, 0xb2, 0x5c, 0x5c, 0x45, 0xf9, 0x39, 0x39, 0x89, 0x05, 0x05, 0xf1, + 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x9c, 0x50, 0x11, 0xcf, 0x14, 0x90, 0x74, + 0x32, 0x44, 0x25, 0x48, 0x9a, 0x09, 0x22, 0x0d, 0x15, 0xf1, 0x4c, 0x71, 0x0a, 0x3a, 0xf1, 0x48, + 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, + 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x8b, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, + 0xe4, 0xfc, 0x5c, 0x5c, 0x3e, 0x2d, 0x33, 0xd6, 0xaf, 0x40, 0xf1, 0x6e, 0x49, 0x65, 0x41, 0x6a, + 0x71, 0x12, 0x1b, 0xd8, 0xd1, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x42, 0xb1, 0x88, 0x2d, + 0x21, 0x01, 0x00, 0x00, +} + +func (m *EventSetCanonicalChannel) 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 *EventSetCanonicalChannel) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventSetCanonicalChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChannelId) > 0 { + i -= len(m.ChannelId) + copy(dAtA[i:], m.ChannelId) + i = encodeVarintEvents(dAtA, i, uint64(len(m.ChannelId))) + i-- + dAtA[i] = 0x12 + } + if len(m.RollappId) > 0 { + i -= len(m.RollappId) + copy(dAtA[i:], m.RollappId) + i = encodeVarintEvents(dAtA, i, uint64(len(m.RollappId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { + offset -= sovEvents(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventSetCanonicalChannel) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RollappId) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + l = len(m.ChannelId) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + +func sovEvents(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvents(x uint64) (n int) { + return sovEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventSetCanonicalChannel) 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 ErrIntOverflowEvents + } + 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: EventSetCanonicalChannel: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventSetCanonicalChannel: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RollappId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RollappId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChannelId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChannelId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvents(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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrInvalidLengthEvents + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvents + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvents + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvents = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvents = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvents = fmt.Errorf("proto: unexpected end of group") +)