From f830bf5b51d98224ed8a666b7f1af64163ae2c80 Mon Sep 17 00:00:00 2001 From: Lior Zilpa Date: Mon, 12 Sep 2022 13:03:01 +0300 Subject: [PATCH] use EmitTypedEvent instead of EmitEvent --- docs/static/openapi.yml | 40 -- proto/rollapp/event.proto | 20 + x/rollapp/keeper/msg_server_update_state.go | 18 +- x/rollapp/types/event.pb.go | 483 ++++++++++++++++++++ x/rollapp/types/events.go | 11 - 5 files changed, 511 insertions(+), 61 deletions(-) create mode 100644 proto/rollapp/event.proto create mode 100644 x/rollapp/types/event.pb.go delete mode 100644 x/rollapp/types/events.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index b54a146e9..8328a31ab 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -20280,16 +20280,6 @@ paths: in: query required: false type: boolean - - name: pagination.reverse - description: >- - reverse is set to true if results are to be returned in the - descending order. - - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean tags: - Query '/dymensionxyz/dymension/rollapp/block_height_to_finalization_queue/{finalizationHeight}': @@ -20516,16 +20506,6 @@ paths: in: query required: false type: boolean - - name: pagination.reverse - description: >- - reverse is set to true if results are to be returned in the - descending order. - - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean tags: - Query '/dymensionxyz/dymension/rollapp/latest_state_info_index/{rollappId}': @@ -20818,16 +20798,6 @@ paths: in: query required: false type: boolean - - name: pagination.reverse - description: >- - reverse is set to true if results are to be returned in the - descending order. - - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean tags: - Query '/dymensionxyz/dymension/rollapp/rollapp/{rollappId}': @@ -21148,16 +21118,6 @@ paths: in: query required: false type: boolean - - name: pagination.reverse - description: >- - reverse is set to true if results are to be returned in the - descending order. - - - Since: cosmos-sdk 0.43 - in: query - required: false - type: boolean tags: - Query '/dymensionxyz/dymension/rollapp/state_info/{rollappId}/{index}': diff --git a/proto/rollapp/event.proto b/proto/rollapp/event.proto new file mode 100644 index 000000000..08a1045c4 --- /dev/null +++ b/proto/rollapp/event.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package dymensionxyz.dymension.rollapp; + +option go_package = "github.com/dymensionxyz/dymension/x/rollapp/types"; + +// EventGrant is emitted on Msg/Grant +message EventStateUpdate { + // rollappId is the rollapp that was updated + // The rollappId follows the same standard as cosmos chain_id + string rollappId = 1; + // latestStateInfoIndex is a sequential increasing number, updating on each + // state update used for indexing to a specific state info + uint64 index = 2; + // startHeight is the block height of the first block in the batch + uint64 startHeight = 3; + // numBlocks is the number of blocks included in this batch update + uint64 numBlocks = 4; + // DAPath is the description of the location on the DA layer + string DAPath = 5; +} \ No newline at end of file diff --git a/x/rollapp/keeper/msg_server_update_state.go b/x/rollapp/keeper/msg_server_update_state.go index 7378543c8..1775f162b 100644 --- a/x/rollapp/keeper/msg_server_update_state.go +++ b/x/rollapp/keeper/msg_server_update_state.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "strconv" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -132,15 +131,14 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState) FinalizationQueue: newFinalizationQueue, }) - ctx.EventManager().EmitEvent( - sdk.NewEvent(types.EventTypeStateUpdate, - sdk.NewAttribute(types.AttributeKeyRollappId, msg.RollappId), - sdk.NewAttribute(types.AttributeKeyStateInfoIndex, strconv.FormatUint(stateInfoIndex.Index, 10)), - sdk.NewAttribute(types.AttributeKeyStartHeight, strconv.FormatUint(msg.StartHeight, 10)), - sdk.NewAttribute(types.AttributeKeyNumBlocks, strconv.FormatUint(msg.NumBlocks, 10)), - sdk.NewAttribute(types.AttributeKeyDAPath, msg.DAPath), - ), - ) + // nolint: errcheck, gosec + ctx.EventManager().EmitTypedEvent(&types.EventStateUpdate{ + RollappId: msg.RollappId, + Index: newIndex, + StartHeight: msg.StartHeight, + NumBlocks: msg.NumBlocks, + DAPath: msg.DAPath, + }) return &types.MsgUpdateStateResponse{}, nil } diff --git a/x/rollapp/types/event.pb.go b/x/rollapp/types/event.pb.go new file mode 100644 index 000000000..4f9acb8fe --- /dev/null +++ b/x/rollapp/types/event.pb.go @@ -0,0 +1,483 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollapp/event.proto + +package types + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/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 + +// EventGrant is emitted on Msg/Grant +type EventStateUpdate struct { + // rollappId is the rollapp that was updated + // The rollappId follows the same standard as cosmos chain_id + RollappId string `protobuf:"bytes,1,opt,name=rollappId,proto3" json:"rollappId,omitempty"` + // latestStateInfoIndex is a sequential increasing number, updating on each + // state update used for indexing to a specific state info + Index uint64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + // startHeight is the block height of the first block in the batch + StartHeight uint64 `protobuf:"varint,3,opt,name=startHeight,proto3" json:"startHeight,omitempty"` + // numBlocks is the number of blocks included in this batch update + NumBlocks uint64 `protobuf:"varint,4,opt,name=numBlocks,proto3" json:"numBlocks,omitempty"` + // DAPath is the description of the location on the DA layer + DAPath string `protobuf:"bytes,5,opt,name=DAPath,proto3" json:"DAPath,omitempty"` +} + +func (m *EventStateUpdate) Reset() { *m = EventStateUpdate{} } +func (m *EventStateUpdate) String() string { return proto.CompactTextString(m) } +func (*EventStateUpdate) ProtoMessage() {} +func (*EventStateUpdate) Descriptor() ([]byte, []int) { + return fileDescriptor_cc3f4d0bf284d156, []int{0} +} +func (m *EventStateUpdate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventStateUpdate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventStateUpdate.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 *EventStateUpdate) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventStateUpdate.Merge(m, src) +} +func (m *EventStateUpdate) XXX_Size() int { + return m.Size() +} +func (m *EventStateUpdate) XXX_DiscardUnknown() { + xxx_messageInfo_EventStateUpdate.DiscardUnknown(m) +} + +var xxx_messageInfo_EventStateUpdate proto.InternalMessageInfo + +func (m *EventStateUpdate) GetRollappId() string { + if m != nil { + return m.RollappId + } + return "" +} + +func (m *EventStateUpdate) GetIndex() uint64 { + if m != nil { + return m.Index + } + return 0 +} + +func (m *EventStateUpdate) GetStartHeight() uint64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *EventStateUpdate) GetNumBlocks() uint64 { + if m != nil { + return m.NumBlocks + } + return 0 +} + +func (m *EventStateUpdate) GetDAPath() string { + if m != nil { + return m.DAPath + } + return "" +} + +func init() { + proto.RegisterType((*EventStateUpdate)(nil), "dymensionxyz.dymension.rollapp.EventStateUpdate") +} + +func init() { proto.RegisterFile("rollapp/event.proto", fileDescriptor_cc3f4d0bf284d156) } + +var fileDescriptor_cc3f4d0bf284d156 = []byte{ + // 232 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0xca, 0xcf, 0xc9, + 0x49, 0x2c, 0x28, 0xd0, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x92, 0x4b, 0xa9, 0xcc, 0x4d, 0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0xab, 0xa8, 0xac, 0xd2, 0x83, 0x73, + 0xf4, 0xa0, 0x6a, 0x95, 0xe6, 0x31, 0x72, 0x09, 0xb8, 0x82, 0xd4, 0x07, 0x97, 0x24, 0x96, 0xa4, + 0x86, 0x16, 0xa4, 0x24, 0x96, 0xa4, 0x0a, 0xc9, 0x70, 0x71, 0x42, 0xe5, 0x3d, 0x53, 0x24, 0x18, + 0x15, 0x18, 0x35, 0x38, 0x83, 0x10, 0x02, 0x42, 0x22, 0x5c, 0xac, 0x99, 0x79, 0x29, 0xa9, 0x15, + 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x10, 0x8e, 0x90, 0x02, 0x17, 0x77, 0x71, 0x49, 0x62, + 0x51, 0x89, 0x47, 0x6a, 0x66, 0x7a, 0x46, 0x89, 0x04, 0x33, 0x58, 0x0e, 0x59, 0x08, 0x64, 0x6a, + 0x5e, 0x69, 0xae, 0x53, 0x4e, 0x7e, 0x72, 0x76, 0xb1, 0x04, 0x0b, 0x58, 0x1e, 0x21, 0x20, 0x24, + 0xc6, 0xc5, 0xe6, 0xe2, 0x18, 0x90, 0x58, 0x92, 0x21, 0xc1, 0x0a, 0xb6, 0x10, 0xca, 0x73, 0xf2, + 0x3e, 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, 0xc3, 0xf4, 0xcc, 0x92, 0x8c, + 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x64, 0x5f, 0x22, 0x38, 0xfa, 0x15, 0xfa, 0xb0, 0x30, + 0x29, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x07, 0x8a, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, + 0x39, 0xe4, 0xa7, 0xdd, 0x2b, 0x01, 0x00, 0x00, +} + +func (m *EventStateUpdate) 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 *EventStateUpdate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventStateUpdate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DAPath) > 0 { + i -= len(m.DAPath) + copy(dAtA[i:], m.DAPath) + i = encodeVarintEvent(dAtA, i, uint64(len(m.DAPath))) + i-- + dAtA[i] = 0x2a + } + if m.NumBlocks != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.NumBlocks)) + i-- + dAtA[i] = 0x20 + } + if m.StartHeight != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.StartHeight)) + i-- + dAtA[i] = 0x18 + } + if m.Index != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x10 + } + if len(m.RollappId) > 0 { + i -= len(m.RollappId) + copy(dAtA[i:], m.RollappId) + i = encodeVarintEvent(dAtA, i, uint64(len(m.RollappId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { + offset -= sovEvent(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventStateUpdate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RollappId) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + if m.Index != 0 { + n += 1 + sovEvent(uint64(m.Index)) + } + if m.StartHeight != 0 { + n += 1 + sovEvent(uint64(m.StartHeight)) + } + if m.NumBlocks != 0 { + n += 1 + sovEvent(uint64(m.NumBlocks)) + } + l = len(m.DAPath) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func sovEvent(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvent(x uint64) (n int) { + return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventStateUpdate) 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 ErrIntOverflowEvent + } + 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: EventStateUpdate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventStateUpdate: 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 ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RollappId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartHeight", wireType) + } + m.StartHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NumBlocks", wireType) + } + m.NumBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NumBlocks |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DAPath", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + 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 ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DAPath = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvent(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, ErrIntOverflowEvent + } + 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, ErrIntOverflowEvent + } + 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, ErrIntOverflowEvent + } + 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, ErrInvalidLengthEvent + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvent + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvent + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvent = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvent = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvent = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/rollapp/types/events.go b/x/rollapp/types/events.go deleted file mode 100644 index 9a46f76dd..000000000 --- a/x/rollapp/types/events.go +++ /dev/null @@ -1,11 +0,0 @@ -package types - -const ( - EventTypeStateUpdate = "state_update" - - AttributeKeyRollappId = "rollapp_id" - AttributeKeyStateInfoIndex = "state_info_index" - AttributeKeyStartHeight = "start_height" - AttributeKeyNumBlocks = "num_blocks" - AttributeKeyDAPath = "da_path" -)