From 9c574953febc6d33ccc7b90aeb1b9d68eb39fc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Fri, 18 Aug 2023 13:10:30 +0700 Subject: [PATCH 01/14] proto for tx-boundary module --- .../txboundary/v1beta1/boundary.proto | 14 + .../centauri/txboundary/v1beta1/genesis.proto | 21 + x/tx-boundary/types/boundary.pb.go | 344 ++++++++++++++++ x/tx-boundary/types/genesis.pb.go | 380 ++++++++++++++++++ 4 files changed, 759 insertions(+) create mode 100644 proto/centauri/txboundary/v1beta1/boundary.proto create mode 100644 proto/centauri/txboundary/v1beta1/genesis.proto create mode 100644 x/tx-boundary/types/boundary.pb.go create mode 100644 x/tx-boundary/types/genesis.pb.go diff --git a/proto/centauri/txboundary/v1beta1/boundary.proto b/proto/centauri/txboundary/v1beta1/boundary.proto new file mode 100644 index 000000000..fd273cb37 --- /dev/null +++ b/proto/centauri/txboundary/v1beta1/boundary.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package centauri.txboundary.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "x/tx-boundary/types"; + +// Boundary defines the number of tx limit and block per tx generation time +message Boundary { + uint64 boundary = 1; + uint64 blocks_per_generation = 2; +} \ No newline at end of file diff --git a/proto/centauri/txboundary/v1beta1/genesis.proto b/proto/centauri/txboundary/v1beta1/genesis.proto new file mode 100644 index 000000000..93f9b6e85 --- /dev/null +++ b/proto/centauri/txboundary/v1beta1/genesis.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package centauri.txboundary.v1beta1; + +import "gogoproto/gogo.proto"; +import "centauri/txboundary/v1beta1/boundary.proto"; + +option go_package = "x/tx-boundary/types"; + +// GenesisState defines the module various parameters when first +// initialized +message GenesisState { + Boundary delegate_boundary = 1 [ + (gogoproto.moretags) = "yaml:\"delegate_boundary\"", + (gogoproto.nullable) = false + ]; + Boundary redelegate_boundary = 2 [ + (gogoproto.moretags) = "yaml:\"redelegate_boundary\"", + (gogoproto.nullable) = false + ]; +} + diff --git a/x/tx-boundary/types/boundary.pb.go b/x/tx-boundary/types/boundary.pb.go new file mode 100644 index 000000000..81b5835e6 --- /dev/null +++ b/x/tx-boundary/types/boundary.pb.go @@ -0,0 +1,344 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/txboundary/v1beta1/boundary.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/timestamppb" + 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 + +// Boundary defines the number of tx limit and block per tx generation time +type Boundary struct { + Boundary uint64 `protobuf:"varint,1,opt,name=boundary,proto3" json:"boundary,omitempty"` + BlocksPerGeneration uint64 `protobuf:"varint,2,opt,name=blocks_per_generation,json=blocksPerGeneration,proto3" json:"blocks_per_generation,omitempty"` +} + +func (m *Boundary) Reset() { *m = Boundary{} } +func (m *Boundary) String() string { return proto.CompactTextString(m) } +func (*Boundary) ProtoMessage() {} +func (*Boundary) Descriptor() ([]byte, []int) { + return fileDescriptor_668b8d6584310f2c, []int{0} +} +func (m *Boundary) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Boundary) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Boundary.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 *Boundary) XXX_Merge(src proto.Message) { + xxx_messageInfo_Boundary.Merge(m, src) +} +func (m *Boundary) XXX_Size() int { + return m.Size() +} +func (m *Boundary) XXX_DiscardUnknown() { + xxx_messageInfo_Boundary.DiscardUnknown(m) +} + +var xxx_messageInfo_Boundary proto.InternalMessageInfo + +func (m *Boundary) GetBoundary() uint64 { + if m != nil { + return m.Boundary + } + return 0 +} + +func (m *Boundary) GetBlocksPerGeneration() uint64 { + if m != nil { + return m.BlocksPerGeneration + } + return 0 +} + +func init() { + proto.RegisterType((*Boundary)(nil), "centauri.txboundary.v1beta1.Boundary") +} + +func init() { + proto.RegisterFile("centauri/txboundary/v1beta1/boundary.proto", fileDescriptor_668b8d6584310f2c) +} + +var fileDescriptor_668b8d6584310f2c = []byte{ + // 226 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0xa9, 0x48, 0xca, 0x2f, 0xcd, 0x4b, 0x49, 0x2c, 0xaa, 0xd4, + 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x87, 0x09, 0xe8, 0x15, 0x14, 0xe5, 0x97, 0xe4, + 0x0b, 0x49, 0xc3, 0xd4, 0xea, 0x21, 0xd4, 0xea, 0x41, 0xd5, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, + 0x83, 0xd5, 0xe9, 0x83, 0x58, 0x10, 0x2d, 0x52, 0x72, 0xe9, 0xf9, 0xf9, 0xe9, 0x39, 0xa9, 0xfa, + 0x60, 0x5e, 0x52, 0x69, 0x9a, 0x7e, 0x4a, 0x69, 0x51, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x54, 0x5e, + 0x1e, 0x5d, 0xbe, 0x24, 0x33, 0x37, 0xb5, 0xb8, 0x24, 0x31, 0xb7, 0x00, 0xa2, 0x40, 0x29, 0x8a, + 0x8b, 0xc3, 0x09, 0x6a, 0x95, 0x90, 0x14, 0x17, 0x07, 0xcc, 0x5a, 0x09, 0x46, 0x05, 0x46, 0x0d, + 0x96, 0x20, 0x38, 0x5f, 0xc8, 0x88, 0x4b, 0x34, 0x29, 0x27, 0x3f, 0x39, 0xbb, 0x38, 0xbe, 0x20, + 0xb5, 0x28, 0x3e, 0x3d, 0x35, 0x2f, 0x15, 0x62, 0x8f, 0x04, 0x13, 0x58, 0xa1, 0x30, 0x44, 0x32, + 0x20, 0xb5, 0xc8, 0x1d, 0x2e, 0xe5, 0xa4, 0x7b, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, + 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, + 0x0c, 0x51, 0xc2, 0x15, 0xfa, 0x25, 0x15, 0xba, 0xf0, 0xf0, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, + 0x62, 0x03, 0xbb, 0xc8, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x60, 0xbc, 0x7c, 0x92, 0x33, 0x01, + 0x00, 0x00, +} + +func (m *Boundary) 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 *Boundary) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Boundary) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlocksPerGeneration != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.BlocksPerGeneration)) + i-- + dAtA[i] = 0x10 + } + if m.Boundary != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.Boundary)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintBoundary(dAtA []byte, offset int, v uint64) int { + offset -= sovBoundary(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Boundary) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Boundary != 0 { + n += 1 + sovBoundary(uint64(m.Boundary)) + } + if m.BlocksPerGeneration != 0 { + n += 1 + sovBoundary(uint64(m.BlocksPerGeneration)) + } + return n +} + +func sovBoundary(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBoundary(x uint64) (n int) { + return sovBoundary(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Boundary) 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 ErrIntOverflowBoundary + } + 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: Boundary: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Boundary: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Boundary", wireType) + } + m.Boundary = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBoundary + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Boundary |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlocksPerGeneration", wireType) + } + m.BlocksPerGeneration = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBoundary + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlocksPerGeneration |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipBoundary(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBoundary + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBoundary(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, ErrIntOverflowBoundary + } + 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, ErrIntOverflowBoundary + } + 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, ErrIntOverflowBoundary + } + 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, ErrInvalidLengthBoundary + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBoundary + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBoundary + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBoundary = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBoundary = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBoundary = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/tx-boundary/types/genesis.pb.go b/x/tx-boundary/types/genesis.pb.go new file mode 100644 index 000000000..1b5ebc1c4 --- /dev/null +++ b/x/tx-boundary/types/genesis.pb.go @@ -0,0 +1,380 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/txboundary/v1beta1/genesis.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 + +// GenesisState defines the module various parameters when first +// initialized +type GenesisState struct { + DelegateBoundary Boundary `protobuf:"bytes,1,opt,name=delegate_boundary,json=delegateBoundary,proto3" json:"delegate_boundary" yaml:"delegate_boundary"` + RedelegateBoundary Boundary `protobuf:"bytes,2,opt,name=redelegate_boundary,json=redelegateBoundary,proto3" json:"redelegate_boundary" yaml:"redelegate_boundary"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_bce53872d9978801, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetDelegateBoundary() Boundary { + if m != nil { + return m.DelegateBoundary + } + return Boundary{} +} + +func (m *GenesisState) GetRedelegateBoundary() Boundary { + if m != nil { + return m.RedelegateBoundary + } + return Boundary{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "centauri.txboundary.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("centauri/txboundary/v1beta1/genesis.proto", fileDescriptor_bce53872d9978801) +} + +var fileDescriptor_bce53872d9978801 = []byte{ + // 241 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4c, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0xa9, 0x48, 0xca, 0x2f, 0xcd, 0x4b, 0x49, 0x2c, 0xaa, 0xd4, + 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x86, 0x29, 0xd5, 0x43, 0x28, 0xd5, 0x83, 0x2a, 0x95, + 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd3, 0x07, 0xb1, 0x20, 0x5a, 0xa4, 0xb4, 0xf0, 0x99, + 0x0e, 0x37, 0x03, 0xac, 0x56, 0xa9, 0x81, 0x89, 0x8b, 0xc7, 0x1d, 0x62, 0x61, 0x70, 0x49, 0x62, + 0x49, 0xaa, 0x50, 0x09, 0x97, 0x60, 0x4a, 0x6a, 0x4e, 0x6a, 0x7a, 0x62, 0x49, 0x6a, 0x3c, 0x4c, + 0xad, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0xaa, 0x1e, 0x1e, 0xb7, 0xe8, 0x39, 0x41, 0x05, + 0x9c, 0x14, 0x4e, 0xdc, 0x93, 0x67, 0xf8, 0x74, 0x4f, 0x5e, 0xa2, 0x32, 0x31, 0x37, 0xc7, 0x4a, + 0x09, 0xc3, 0x34, 0xa5, 0x20, 0x01, 0x98, 0x18, 0x4c, 0x8f, 0x50, 0x15, 0x97, 0x70, 0x51, 0x2a, + 0xa6, 0xbd, 0x4c, 0xa4, 0xd8, 0xab, 0x04, 0xb5, 0x57, 0x0a, 0x62, 0x2f, 0x16, 0xf3, 0x94, 0x82, + 0x84, 0x10, 0xa2, 0x70, 0x7d, 0xba, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, + 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, + 0x25, 0x5c, 0xa1, 0x5f, 0x52, 0xa1, 0x0b, 0x0f, 0xc2, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, + 0x70, 0xc0, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x26, 0x2f, 0x29, 0x14, 0xc4, 0x01, 0x00, + 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.RedelegateBoundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.DelegateBoundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.DelegateBoundary.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.RedelegateBoundary.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegateBoundary", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DelegateBoundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RedelegateBoundary", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RedelegateBoundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) From 8e106b26026347a3b465515b29f44c811b32701a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Tue, 22 Aug 2023 17:59:12 +0700 Subject: [PATCH 02/14] update tx-boundary proto --- .../txboundary/v1beta1/boundary.proto | 11 ++- proto/centauri/txboundary/v1beta1/query.proto | 40 +++++++++++ proto/centauri/txboundary/v1beta1/tx.proto | 68 +++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 proto/centauri/txboundary/v1beta1/query.proto create mode 100644 proto/centauri/txboundary/v1beta1/tx.proto diff --git a/proto/centauri/txboundary/v1beta1/boundary.proto b/proto/centauri/txboundary/v1beta1/boundary.proto index fd273cb37..c0b57b644 100644 --- a/proto/centauri/txboundary/v1beta1/boundary.proto +++ b/proto/centauri/txboundary/v1beta1/boundary.proto @@ -9,6 +9,13 @@ option go_package = "x/tx-boundary/types"; // Boundary defines the number of tx limit and block per tx generation time message Boundary { - uint64 boundary = 1; - uint64 blocks_per_generation = 2; + uint64 tx_limit = 1; + int64 blocks_per_generation = 2; +} + +// Boundary defines the number of delegate and redelegate per Addr +message LimitPerAddr { + uint64 delegate_count = 1; + uint64 reledegate_count = 2; + int64 latest_update_block = 3; } \ No newline at end of file diff --git a/proto/centauri/txboundary/v1beta1/query.proto b/proto/centauri/txboundary/v1beta1/query.proto new file mode 100644 index 000000000..33579368f --- /dev/null +++ b/proto/centauri/txboundary/v1beta1/query.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package centauri.txboundary.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "centauri/txboundary/v1beta1/boundary.proto"; + +option go_package = "x/tx-boundary/types"; + +// Query provides defines the gRPC querier service. +service Query { + // DelegateBoundary returns the boundary for the delegate tx. + rpc DelegateBoundary(QueryDelegateBoundaryRequest) returns (QueryDelegateBoundaryResponse) { + option (google.api.http).get = "/cosmos/txboundary/v1beta1/delegateboundary"; + } + + // RedelegateBoundary returns the boundary for the redelegate tx. + rpc RedelegateBoundary(QueryRedelegateBoundaryRequest) returns (QueryRedelegateBoundaryResponse) { + option (google.api.http).get = "/cosmos/txboundary/v1beta1/redelegateboundary"; + } +} + +// QueryDelegateBoundaryRequest is the request type for the Query/DelegateBoundary RPC method. +message QueryDelegateBoundaryRequest {} + +// QueryDelegateBoundaryResponse is the response type for the Query/DelegateBoundary RPC method. +message QueryDelegateBoundaryResponse { + // boundary defines the boundary for the delegate tx + Boundary boundary = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryRedelegateBoundaryRequest is the request type for the Query/ReDelegateBoundary RPC method. +message QueryRedelegateBoundaryRequest {} + +// QueryRedelegateBoundaryResponse is the response type for the Query/ReDelegateBoundary RPC +// method. +message QueryRedelegateBoundaryResponse { + // boundary defines the boundary for the redelegate tx + Boundary boundary = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/centauri/txboundary/v1beta1/tx.proto b/proto/centauri/txboundary/v1beta1/tx.proto new file mode 100644 index 000000000..e131c5f74 --- /dev/null +++ b/proto/centauri/txboundary/v1beta1/tx.proto @@ -0,0 +1,68 @@ +syntax = "proto3"; +package centauri.txboundary.v1beta1; + +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "centauri/txboundary/v1beta1/boundary.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "x/tx-boundary/types"; + +// Msg defines the x/mint Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + rpc UpdateDelegateBoundary(MsgUpdateDelegateBoundary) returns (MsgUpdateDelegateBoundaryResponse); + + rpc UpdateRedelegateBoundary(MsgUpdateRedelegateBoundary) returns (MsgUpdateRedelegateBoundaryResponse); + } + + // MsgUpdateDelegateBoundary is the Msg/UpdateDelegateBoundary request type. + // + // Since: cosmos-sdk 0.47 + message MsgUpdateDelegateBoundary { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "centauri/x/txboundary/MsgUpdateDelegateBoundary"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // boundary defines the x/tx-boundary parameters to update. + // + // NOTE: All parameters must be supplied. + Boundary boundary = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + } + + // MsgUpdateDelegateBoundaryResponse defines the response structure for executing a + // MsgUpdateDelegateBoundary message. + // + // Since: cosmos-sdk 0.47 + message MsgUpdateDelegateBoundaryResponse {} + + // MsgUpdateRedelegateBoundary is the Msg/MsgUpdateRedelegateBoundary request type. + // + // Since: cosmos-sdk 0.47 + message MsgUpdateRedelegateBoundary { + option (cosmos.msg.v1.signer) = "authority"; + option (amino.name) = "centauri/x/txboundary/MsgUpdateDelegateBoundary"; + + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // boundary defines the x/tx-boundary parameters to update. + // + // NOTE: All parameters must be supplied. + Boundary boundary = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + } + + // MsgUpdateRedelegateBoundaryResponse defines the response structure for executing a + // MsgUpdateRedelegateBoundary message. + // + // Since: cosmos-sdk 0.47 + message MsgUpdateRedelegateBoundaryResponse {} \ No newline at end of file From 0535f8af8725aaec571e9f8af07221dce8338809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Tue, 22 Aug 2023 17:59:44 +0700 Subject: [PATCH 03/14] make proto gen --- x/tx-boundary/types/boundary.pb.go | 288 ++++++++- x/tx-boundary/types/query.pb.go | 874 +++++++++++++++++++++++++ x/tx-boundary/types/query.pb.gw.go | 218 +++++++ x/tx-boundary/types/tx.pb.go | 996 +++++++++++++++++++++++++++++ 4 files changed, 2347 insertions(+), 29 deletions(-) create mode 100644 x/tx-boundary/types/query.pb.go create mode 100644 x/tx-boundary/types/query.pb.gw.go create mode 100644 x/tx-boundary/types/tx.pb.go diff --git a/x/tx-boundary/types/boundary.pb.go b/x/tx-boundary/types/boundary.pb.go index 81b5835e6..675954d58 100644 --- a/x/tx-boundary/types/boundary.pb.go +++ b/x/tx-boundary/types/boundary.pb.go @@ -27,8 +27,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Boundary defines the number of tx limit and block per tx generation time type Boundary struct { - Boundary uint64 `protobuf:"varint,1,opt,name=boundary,proto3" json:"boundary,omitempty"` - BlocksPerGeneration uint64 `protobuf:"varint,2,opt,name=blocks_per_generation,json=blocksPerGeneration,proto3" json:"blocks_per_generation,omitempty"` + TxLimit uint64 `protobuf:"varint,1,opt,name=tx_limit,json=txLimit,proto3" json:"tx_limit,omitempty"` + BlocksPerGeneration int64 `protobuf:"varint,2,opt,name=blocks_per_generation,json=blocksPerGeneration,proto3" json:"blocks_per_generation,omitempty"` } func (m *Boundary) Reset() { *m = Boundary{} } @@ -64,22 +64,84 @@ func (m *Boundary) XXX_DiscardUnknown() { var xxx_messageInfo_Boundary proto.InternalMessageInfo -func (m *Boundary) GetBoundary() uint64 { +func (m *Boundary) GetTxLimit() uint64 { if m != nil { - return m.Boundary + return m.TxLimit } return 0 } -func (m *Boundary) GetBlocksPerGeneration() uint64 { +func (m *Boundary) GetBlocksPerGeneration() int64 { if m != nil { return m.BlocksPerGeneration } return 0 } +// Boundary defines the number of delegate and redelegate per Addr +type LimitPerAddr struct { + DelegateCount uint64 `protobuf:"varint,1,opt,name=delegate_count,json=delegateCount,proto3" json:"delegate_count,omitempty"` + ReledegateCount uint64 `protobuf:"varint,2,opt,name=reledegate_count,json=reledegateCount,proto3" json:"reledegate_count,omitempty"` + LatestUpdateBlock int64 `protobuf:"varint,3,opt,name=latest_update_block,json=latestUpdateBlock,proto3" json:"latest_update_block,omitempty"` +} + +func (m *LimitPerAddr) Reset() { *m = LimitPerAddr{} } +func (m *LimitPerAddr) String() string { return proto.CompactTextString(m) } +func (*LimitPerAddr) ProtoMessage() {} +func (*LimitPerAddr) Descriptor() ([]byte, []int) { + return fileDescriptor_668b8d6584310f2c, []int{1} +} +func (m *LimitPerAddr) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LimitPerAddr) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LimitPerAddr.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 *LimitPerAddr) XXX_Merge(src proto.Message) { + xxx_messageInfo_LimitPerAddr.Merge(m, src) +} +func (m *LimitPerAddr) XXX_Size() int { + return m.Size() +} +func (m *LimitPerAddr) XXX_DiscardUnknown() { + xxx_messageInfo_LimitPerAddr.DiscardUnknown(m) +} + +var xxx_messageInfo_LimitPerAddr proto.InternalMessageInfo + +func (m *LimitPerAddr) GetDelegateCount() uint64 { + if m != nil { + return m.DelegateCount + } + return 0 +} + +func (m *LimitPerAddr) GetReledegateCount() uint64 { + if m != nil { + return m.ReledegateCount + } + return 0 +} + +func (m *LimitPerAddr) GetLatestUpdateBlock() int64 { + if m != nil { + return m.LatestUpdateBlock + } + return 0 +} + func init() { proto.RegisterType((*Boundary)(nil), "centauri.txboundary.v1beta1.Boundary") + proto.RegisterType((*LimitPerAddr)(nil), "centauri.txboundary.v1beta1.LimitPerAddr") } func init() { @@ -87,22 +149,27 @@ func init() { } var fileDescriptor_668b8d6584310f2c = []byte{ - // 226 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x4e, 0xcd, 0x2b, - 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0xa9, 0x48, 0xca, 0x2f, 0xcd, 0x4b, 0x49, 0x2c, 0xaa, 0xd4, - 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x87, 0x09, 0xe8, 0x15, 0x14, 0xe5, 0x97, 0xe4, - 0x0b, 0x49, 0xc3, 0xd4, 0xea, 0x21, 0xd4, 0xea, 0x41, 0xd5, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, - 0x83, 0xd5, 0xe9, 0x83, 0x58, 0x10, 0x2d, 0x52, 0x72, 0xe9, 0xf9, 0xf9, 0xe9, 0x39, 0xa9, 0xfa, - 0x60, 0x5e, 0x52, 0x69, 0x9a, 0x7e, 0x4a, 0x69, 0x51, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x54, 0x5e, - 0x1e, 0x5d, 0xbe, 0x24, 0x33, 0x37, 0xb5, 0xb8, 0x24, 0x31, 0xb7, 0x00, 0xa2, 0x40, 0x29, 0x8a, - 0x8b, 0xc3, 0x09, 0x6a, 0x95, 0x90, 0x14, 0x17, 0x07, 0xcc, 0x5a, 0x09, 0x46, 0x05, 0x46, 0x0d, - 0x96, 0x20, 0x38, 0x5f, 0xc8, 0x88, 0x4b, 0x34, 0x29, 0x27, 0x3f, 0x39, 0xbb, 0x38, 0xbe, 0x20, - 0xb5, 0x28, 0x3e, 0x3d, 0x35, 0x2f, 0x15, 0x62, 0x8f, 0x04, 0x13, 0x58, 0xa1, 0x30, 0x44, 0x32, - 0x20, 0xb5, 0xc8, 0x1d, 0x2e, 0xe5, 0xa4, 0x7b, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, - 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, - 0x0c, 0x51, 0xc2, 0x15, 0xfa, 0x25, 0x15, 0xba, 0xf0, 0xf0, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, - 0x62, 0x03, 0xbb, 0xc8, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x60, 0xbc, 0x7c, 0x92, 0x33, 0x01, - 0x00, 0x00, + // 318 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0xcd, 0x4a, 0xf3, 0x40, + 0x14, 0x86, 0x3b, 0xed, 0xc7, 0x67, 0x19, 0xfc, 0x4d, 0x15, 0x6a, 0x85, 0xb1, 0x14, 0x84, 0x2a, + 0x34, 0x43, 0xf5, 0x0a, 0xac, 0x0b, 0x37, 0x2e, 0x4a, 0xc1, 0x85, 0x6e, 0xc2, 0xa4, 0x73, 0x0c, + 0xc1, 0x34, 0x13, 0x26, 0x67, 0x24, 0xbd, 0x8b, 0x5e, 0x96, 0xcb, 0x2e, 0x5d, 0x4a, 0x7b, 0x23, + 0x92, 0x99, 0xa6, 0x15, 0x77, 0x39, 0xef, 0xf3, 0x1c, 0xde, 0x43, 0x86, 0xde, 0x4c, 0x21, 0x45, + 0x61, 0x74, 0xcc, 0xb1, 0x08, 0x95, 0x49, 0xa5, 0xd0, 0x73, 0xfe, 0x31, 0x0c, 0x01, 0xc5, 0x90, + 0x57, 0x81, 0x9f, 0x69, 0x85, 0xca, 0xbb, 0xa8, 0x5c, 0x7f, 0xe7, 0xfa, 0x1b, 0xb7, 0x73, 0x1a, + 0xa9, 0x48, 0x59, 0x8f, 0x97, 0x5f, 0x6e, 0xa5, 0xc3, 0x22, 0xa5, 0xa2, 0x04, 0xb8, 0x9d, 0x42, + 0xf3, 0xc6, 0xa5, 0xd1, 0x02, 0x63, 0x95, 0x6e, 0xf8, 0xe5, 0x5f, 0x8e, 0xf1, 0x0c, 0x72, 0x14, + 0xb3, 0xcc, 0x09, 0xbd, 0x17, 0xda, 0x1c, 0x6d, 0xaa, 0xbc, 0x73, 0xda, 0xc4, 0x22, 0x48, 0xe2, + 0x59, 0x8c, 0x6d, 0xd2, 0x25, 0xfd, 0x7f, 0x93, 0x3d, 0x2c, 0x9e, 0xca, 0xd1, 0xbb, 0xa5, 0x67, + 0x61, 0xa2, 0xa6, 0xef, 0x79, 0x90, 0x81, 0x0e, 0x22, 0x48, 0xc1, 0xd5, 0xb4, 0xeb, 0x5d, 0xd2, + 0x6f, 0x4c, 0x5a, 0x0e, 0x8e, 0x41, 0x3f, 0x6e, 0x51, 0x6f, 0x41, 0xe8, 0xbe, 0xdd, 0x1e, 0x83, + 0xbe, 0x97, 0x52, 0x7b, 0x57, 0xf4, 0x50, 0x42, 0x02, 0x91, 0x40, 0x08, 0xa6, 0xca, 0xa4, 0x55, + 0xcb, 0x41, 0x95, 0x3e, 0x94, 0xa1, 0x77, 0x4d, 0x8f, 0x35, 0x24, 0x20, 0x7f, 0x8b, 0x75, 0x2b, + 0x1e, 0xed, 0x72, 0xa7, 0xfa, 0xb4, 0x95, 0x08, 0x84, 0x1c, 0x03, 0x93, 0xc9, 0xd2, 0xb6, 0x77, + 0xb4, 0x1b, 0xf6, 0xa8, 0x13, 0x87, 0x9e, 0x2d, 0x19, 0x95, 0x60, 0x34, 0xf8, 0x5c, 0x31, 0xb2, + 0x5c, 0x31, 0xf2, 0xbd, 0x62, 0x64, 0xb1, 0x66, 0xb5, 0xe5, 0x9a, 0xd5, 0xbe, 0xd6, 0xac, 0xf6, + 0xda, 0x2a, 0x38, 0x16, 0x83, 0xed, 0x0b, 0xe1, 0x3c, 0x83, 0x3c, 0xfc, 0x6f, 0xff, 0xd1, 0xdd, + 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x16, 0x56, 0x93, 0xc5, 0x01, 0x00, 0x00, } func (m *Boundary) Marshal() (dAtA []byte, err error) { @@ -130,8 +197,46 @@ func (m *Boundary) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x10 } - if m.Boundary != 0 { - i = encodeVarintBoundary(dAtA, i, uint64(m.Boundary)) + if m.TxLimit != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.TxLimit)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *LimitPerAddr) 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 *LimitPerAddr) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LimitPerAddr) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LatestUpdateBlock != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.LatestUpdateBlock)) + i-- + dAtA[i] = 0x18 + } + if m.ReledegateCount != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.ReledegateCount)) + i-- + dAtA[i] = 0x10 + } + if m.DelegateCount != 0 { + i = encodeVarintBoundary(dAtA, i, uint64(m.DelegateCount)) i-- dAtA[i] = 0x8 } @@ -155,8 +260,8 @@ func (m *Boundary) Size() (n int) { } var l int _ = l - if m.Boundary != 0 { - n += 1 + sovBoundary(uint64(m.Boundary)) + if m.TxLimit != 0 { + n += 1 + sovBoundary(uint64(m.TxLimit)) } if m.BlocksPerGeneration != 0 { n += 1 + sovBoundary(uint64(m.BlocksPerGeneration)) @@ -164,6 +269,24 @@ func (m *Boundary) Size() (n int) { return n } +func (m *LimitPerAddr) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DelegateCount != 0 { + n += 1 + sovBoundary(uint64(m.DelegateCount)) + } + if m.ReledegateCount != 0 { + n += 1 + sovBoundary(uint64(m.ReledegateCount)) + } + if m.LatestUpdateBlock != 0 { + n += 1 + sovBoundary(uint64(m.LatestUpdateBlock)) + } + return n +} + func sovBoundary(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -201,9 +324,9 @@ func (m *Boundary) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Boundary", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TxLimit", wireType) } - m.Boundary = 0 + m.TxLimit = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowBoundary @@ -213,7 +336,7 @@ func (m *Boundary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Boundary |= uint64(b&0x7F) << shift + m.TxLimit |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -232,7 +355,114 @@ func (m *Boundary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.BlocksPerGeneration |= uint64(b&0x7F) << shift + m.BlocksPerGeneration |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipBoundary(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBoundary + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *LimitPerAddr) 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 ErrIntOverflowBoundary + } + 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: LimitPerAddr: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LimitPerAddr: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegateCount", wireType) + } + m.DelegateCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBoundary + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DelegateCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReledegateCount", wireType) + } + m.ReledegateCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBoundary + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ReledegateCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestUpdateBlock", wireType) + } + m.LatestUpdateBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBoundary + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LatestUpdateBlock |= int64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/tx-boundary/types/query.pb.go b/x/tx-boundary/types/query.pb.go new file mode 100644 index 000000000..462aaf6d0 --- /dev/null +++ b/x/tx-boundary/types/query.pb.go @@ -0,0 +1,874 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/txboundary/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + 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 + +// QueryDelegateBoundaryRequest is the request type for the Query/DelegateBoundary RPC method. +type QueryDelegateBoundaryRequest struct { +} + +func (m *QueryDelegateBoundaryRequest) Reset() { *m = QueryDelegateBoundaryRequest{} } +func (m *QueryDelegateBoundaryRequest) String() string { return proto.CompactTextString(m) } +func (*QueryDelegateBoundaryRequest) ProtoMessage() {} +func (*QueryDelegateBoundaryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9eb43e8f98660cf8, []int{0} +} +func (m *QueryDelegateBoundaryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegateBoundaryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegateBoundaryRequest.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 *QueryDelegateBoundaryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegateBoundaryRequest.Merge(m, src) +} +func (m *QueryDelegateBoundaryRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegateBoundaryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegateBoundaryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegateBoundaryRequest proto.InternalMessageInfo + +// QueryDelegateBoundaryResponse is the response type for the Query/DelegateBoundary RPC method. +type QueryDelegateBoundaryResponse struct { + // boundary defines the boundary for the delegate tx + Boundary Boundary `protobuf:"bytes,1,opt,name=boundary,proto3" json:"boundary"` +} + +func (m *QueryDelegateBoundaryResponse) Reset() { *m = QueryDelegateBoundaryResponse{} } +func (m *QueryDelegateBoundaryResponse) String() string { return proto.CompactTextString(m) } +func (*QueryDelegateBoundaryResponse) ProtoMessage() {} +func (*QueryDelegateBoundaryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9eb43e8f98660cf8, []int{1} +} +func (m *QueryDelegateBoundaryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryDelegateBoundaryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryDelegateBoundaryResponse.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 *QueryDelegateBoundaryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryDelegateBoundaryResponse.Merge(m, src) +} +func (m *QueryDelegateBoundaryResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryDelegateBoundaryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryDelegateBoundaryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryDelegateBoundaryResponse proto.InternalMessageInfo + +func (m *QueryDelegateBoundaryResponse) GetBoundary() Boundary { + if m != nil { + return m.Boundary + } + return Boundary{} +} + +// QueryRedelegateBoundaryRequest is the request type for the Query/ReDelegateBoundary RPC method. +type QueryRedelegateBoundaryRequest struct { +} + +func (m *QueryRedelegateBoundaryRequest) Reset() { *m = QueryRedelegateBoundaryRequest{} } +func (m *QueryRedelegateBoundaryRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRedelegateBoundaryRequest) ProtoMessage() {} +func (*QueryRedelegateBoundaryRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9eb43e8f98660cf8, []int{2} +} +func (m *QueryRedelegateBoundaryRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRedelegateBoundaryRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRedelegateBoundaryRequest.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 *QueryRedelegateBoundaryRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRedelegateBoundaryRequest.Merge(m, src) +} +func (m *QueryRedelegateBoundaryRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryRedelegateBoundaryRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRedelegateBoundaryRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRedelegateBoundaryRequest proto.InternalMessageInfo + +// QueryRedelegateBoundaryResponse is the response type for the Query/ReDelegateBoundary RPC +// method. +type QueryRedelegateBoundaryResponse struct { + // boundary defines the boundary for the redelegate tx + Boundary Boundary `protobuf:"bytes,1,opt,name=boundary,proto3" json:"boundary"` +} + +func (m *QueryRedelegateBoundaryResponse) Reset() { *m = QueryRedelegateBoundaryResponse{} } +func (m *QueryRedelegateBoundaryResponse) String() string { return proto.CompactTextString(m) } +func (*QueryRedelegateBoundaryResponse) ProtoMessage() {} +func (*QueryRedelegateBoundaryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9eb43e8f98660cf8, []int{3} +} +func (m *QueryRedelegateBoundaryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryRedelegateBoundaryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryRedelegateBoundaryResponse.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 *QueryRedelegateBoundaryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRedelegateBoundaryResponse.Merge(m, src) +} +func (m *QueryRedelegateBoundaryResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryRedelegateBoundaryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRedelegateBoundaryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryRedelegateBoundaryResponse proto.InternalMessageInfo + +func (m *QueryRedelegateBoundaryResponse) GetBoundary() Boundary { + if m != nil { + return m.Boundary + } + return Boundary{} +} + +func init() { + proto.RegisterType((*QueryDelegateBoundaryRequest)(nil), "centauri.txboundary.v1beta1.QueryDelegateBoundaryRequest") + proto.RegisterType((*QueryDelegateBoundaryResponse)(nil), "centauri.txboundary.v1beta1.QueryDelegateBoundaryResponse") + proto.RegisterType((*QueryRedelegateBoundaryRequest)(nil), "centauri.txboundary.v1beta1.QueryRedelegateBoundaryRequest") + proto.RegisterType((*QueryRedelegateBoundaryResponse)(nil), "centauri.txboundary.v1beta1.QueryRedelegateBoundaryResponse") +} + +func init() { + proto.RegisterFile("centauri/txboundary/v1beta1/query.proto", fileDescriptor_9eb43e8f98660cf8) +} + +var fileDescriptor_9eb43e8f98660cf8 = []byte{ + // 340 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x52, 0x3d, 0x4b, 0xc3, 0x40, + 0x18, 0xce, 0xf9, 0x85, 0x9c, 0x8b, 0x9c, 0x0e, 0x12, 0xeb, 0xb5, 0x04, 0x44, 0x51, 0x92, 0xa3, + 0x2d, 0x0e, 0x7e, 0x4c, 0x45, 0x70, 0xb6, 0xa3, 0xdb, 0xb5, 0x7d, 0x89, 0x95, 0x9a, 0x37, 0xcd, + 0x5d, 0xa4, 0x5d, 0xfd, 0x05, 0x8a, 0xff, 0xc7, 0x51, 0x3a, 0x16, 0x5c, 0x9c, 0x44, 0x5a, 0x7f, + 0x88, 0x34, 0x4d, 0x22, 0x54, 0x13, 0xa1, 0xb8, 0x05, 0x9e, 0xef, 0xf7, 0x42, 0xf7, 0x9a, 0xe0, + 0x69, 0x19, 0x06, 0x6d, 0xa1, 0x7b, 0x0d, 0x0c, 0xbd, 0x96, 0x0c, 0xfa, 0xe2, 0xae, 0xdc, 0x00, + 0x2d, 0xcb, 0xa2, 0x1b, 0x42, 0xd0, 0x77, 0xfc, 0x00, 0x35, 0xb2, 0xed, 0x84, 0xe8, 0x7c, 0x13, + 0x9d, 0x98, 0x68, 0x6e, 0xba, 0xe8, 0x62, 0xc4, 0x13, 0x93, 0xaf, 0xa9, 0xc4, 0x2c, 0xb8, 0x88, + 0x6e, 0x07, 0x84, 0xf4, 0xdb, 0x42, 0x7a, 0x1e, 0x6a, 0xa9, 0xdb, 0xe8, 0xa9, 0x18, 0x3d, 0xc8, + 0x4b, 0x4e, 0x13, 0x22, 0xae, 0xc5, 0x69, 0xe1, 0x72, 0xd2, 0xe5, 0x1c, 0x3a, 0xe0, 0x4a, 0x0d, + 0xb5, 0x18, 0xae, 0x43, 0x37, 0x04, 0xa5, 0xad, 0x6b, 0xba, 0x93, 0x81, 0x2b, 0x1f, 0x3d, 0x05, + 0xec, 0x82, 0xae, 0x26, 0x96, 0x5b, 0xa4, 0x44, 0xf6, 0xd7, 0x2a, 0xbb, 0x4e, 0xce, 0x20, 0x27, + 0x31, 0xa8, 0x2d, 0x0d, 0xde, 0x8b, 0x46, 0x3d, 0x15, 0x5b, 0x25, 0xca, 0xa3, 0xa4, 0x3a, 0xb4, + 0x32, 0xba, 0xdc, 0xd0, 0x62, 0x26, 0xe3, 0x9f, 0xdb, 0x54, 0x1e, 0x17, 0xe9, 0x72, 0x14, 0xc6, + 0x9e, 0x09, 0x5d, 0x9f, 0x5d, 0xcf, 0x8e, 0x73, 0x5d, 0xf3, 0x2e, 0x6a, 0x9e, 0xcc, 0x23, 0x9d, + 0xce, 0xb3, 0xaa, 0xf7, 0xaf, 0x9f, 0x4f, 0x0b, 0x36, 0x3b, 0x14, 0x4d, 0x54, 0xb7, 0xa8, 0x7e, + 0x7b, 0xe0, 0xe4, 0x36, 0x09, 0xc0, 0x5e, 0x08, 0x65, 0x3f, 0x4f, 0xc6, 0x4e, 0xff, 0xee, 0x91, + 0xf9, 0x14, 0xe6, 0xd9, 0x7c, 0xe2, 0x78, 0xc6, 0x51, 0x34, 0x43, 0x30, 0x3b, 0x67, 0x46, 0x00, + 0xb3, 0x43, 0x6a, 0xf6, 0x60, 0xc4, 0xc9, 0x70, 0xc4, 0xc9, 0xc7, 0x88, 0x93, 0x87, 0x31, 0x37, + 0x86, 0x63, 0x6e, 0xbc, 0x8d, 0xb9, 0x71, 0xb5, 0xd1, 0x13, 0xba, 0x67, 0xa7, 0x1e, 0xba, 0xef, + 0x83, 0x6a, 0xac, 0x44, 0x7f, 0x78, 0xf5, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x5c, 0xd6, 0xca, 0x4a, + 0x89, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // DelegateBoundary returns the boundary for the delegate tx. + DelegateBoundary(ctx context.Context, in *QueryDelegateBoundaryRequest, opts ...grpc.CallOption) (*QueryDelegateBoundaryResponse, error) + // RedelegateBoundary returns the boundary for the redelegate tx. + RedelegateBoundary(ctx context.Context, in *QueryRedelegateBoundaryRequest, opts ...grpc.CallOption) (*QueryRedelegateBoundaryResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) DelegateBoundary(ctx context.Context, in *QueryDelegateBoundaryRequest, opts ...grpc.CallOption) (*QueryDelegateBoundaryResponse, error) { + out := new(QueryDelegateBoundaryResponse) + err := c.cc.Invoke(ctx, "/centauri.txboundary.v1beta1.Query/DelegateBoundary", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) RedelegateBoundary(ctx context.Context, in *QueryRedelegateBoundaryRequest, opts ...grpc.CallOption) (*QueryRedelegateBoundaryResponse, error) { + out := new(QueryRedelegateBoundaryResponse) + err := c.cc.Invoke(ctx, "/centauri.txboundary.v1beta1.Query/RedelegateBoundary", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // DelegateBoundary returns the boundary for the delegate tx. + DelegateBoundary(context.Context, *QueryDelegateBoundaryRequest) (*QueryDelegateBoundaryResponse, error) + // RedelegateBoundary returns the boundary for the redelegate tx. + RedelegateBoundary(context.Context, *QueryRedelegateBoundaryRequest) (*QueryRedelegateBoundaryResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) DelegateBoundary(ctx context.Context, req *QueryDelegateBoundaryRequest) (*QueryDelegateBoundaryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method DelegateBoundary not implemented") +} +func (*UnimplementedQueryServer) RedelegateBoundary(ctx context.Context, req *QueryRedelegateBoundaryRequest) (*QueryRedelegateBoundaryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RedelegateBoundary not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_DelegateBoundary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryDelegateBoundaryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).DelegateBoundary(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.txboundary.v1beta1.Query/DelegateBoundary", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).DelegateBoundary(ctx, req.(*QueryDelegateBoundaryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_RedelegateBoundary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRedelegateBoundaryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).RedelegateBoundary(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.txboundary.v1beta1.Query/RedelegateBoundary", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).RedelegateBoundary(ctx, req.(*QueryRedelegateBoundaryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "centauri.txboundary.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "DelegateBoundary", + Handler: _Query_DelegateBoundary_Handler, + }, + { + MethodName: "RedelegateBoundary", + Handler: _Query_RedelegateBoundary_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "centauri/txboundary/v1beta1/query.proto", +} + +func (m *QueryDelegateBoundaryRequest) 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 *QueryDelegateBoundaryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegateBoundaryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryDelegateBoundaryResponse) 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 *QueryDelegateBoundaryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryDelegateBoundaryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Boundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryRedelegateBoundaryRequest) 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 *QueryRedelegateBoundaryRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRedelegateBoundaryRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryRedelegateBoundaryResponse) 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 *QueryRedelegateBoundaryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRedelegateBoundaryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Boundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryDelegateBoundaryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryDelegateBoundaryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Boundary.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryRedelegateBoundaryRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryRedelegateBoundaryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Boundary.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryDelegateBoundaryRequest) 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 ErrIntOverflowQuery + } + 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: QueryDelegateBoundaryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegateBoundaryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryDelegateBoundaryResponse) 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 ErrIntOverflowQuery + } + 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: QueryDelegateBoundaryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryDelegateBoundaryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Boundary", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Boundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryRedelegateBoundaryRequest) 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 ErrIntOverflowQuery + } + 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: QueryRedelegateBoundaryRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRedelegateBoundaryRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryRedelegateBoundaryResponse) 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 ErrIntOverflowQuery + } + 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: QueryRedelegateBoundaryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryRedelegateBoundaryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Boundary", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Boundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/tx-boundary/types/query.pb.gw.go b/x/tx-boundary/types/query.pb.gw.go new file mode 100644 index 000000000..54a830aea --- /dev/null +++ b/x/tx-boundary/types/query.pb.gw.go @@ -0,0 +1,218 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: centauri/txboundary/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_DelegateBoundary_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegateBoundaryRequest + var metadata runtime.ServerMetadata + + msg, err := client.DelegateBoundary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_DelegateBoundary_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryDelegateBoundaryRequest + var metadata runtime.ServerMetadata + + msg, err := server.DelegateBoundary(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_RedelegateBoundary_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRedelegateBoundaryRequest + var metadata runtime.ServerMetadata + + msg, err := client.RedelegateBoundary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_RedelegateBoundary_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRedelegateBoundaryRequest + var metadata runtime.ServerMetadata + + msg, err := server.RedelegateBoundary(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_DelegateBoundary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_DelegateBoundary_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegateBoundary_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_RedelegateBoundary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_RedelegateBoundary_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_RedelegateBoundary_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_DelegateBoundary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_DelegateBoundary_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_DelegateBoundary_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_RedelegateBoundary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_RedelegateBoundary_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_RedelegateBoundary_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_DelegateBoundary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "txboundary", "v1beta1", "delegateboundary"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_RedelegateBoundary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "txboundary", "v1beta1", "redelegateboundary"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_DelegateBoundary_0 = runtime.ForwardResponseMessage + + forward_Query_RedelegateBoundary_0 = runtime.ForwardResponseMessage +) diff --git a/x/tx-boundary/types/tx.pb.go b/x/tx-boundary/types/tx.pb.go new file mode 100644 index 000000000..e96348dd7 --- /dev/null +++ b/x/tx-boundary/types/tx.pb.go @@ -0,0 +1,996 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/txboundary/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "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 + +// MsgUpdateDelegateBoundary is the Msg/UpdateDelegateBoundary request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateDelegateBoundary struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // boundary defines the x/tx-boundary parameters to update. + // + // NOTE: All parameters must be supplied. + Boundary Boundary `protobuf:"bytes,2,opt,name=boundary,proto3" json:"boundary"` +} + +func (m *MsgUpdateDelegateBoundary) Reset() { *m = MsgUpdateDelegateBoundary{} } +func (m *MsgUpdateDelegateBoundary) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateDelegateBoundary) ProtoMessage() {} +func (*MsgUpdateDelegateBoundary) Descriptor() ([]byte, []int) { + return fileDescriptor_148586c432693946, []int{0} +} +func (m *MsgUpdateDelegateBoundary) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateDelegateBoundary) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateDelegateBoundary.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 *MsgUpdateDelegateBoundary) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateDelegateBoundary.Merge(m, src) +} +func (m *MsgUpdateDelegateBoundary) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateDelegateBoundary) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateDelegateBoundary.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateDelegateBoundary proto.InternalMessageInfo + +func (m *MsgUpdateDelegateBoundary) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateDelegateBoundary) GetBoundary() Boundary { + if m != nil { + return m.Boundary + } + return Boundary{} +} + +// MsgUpdateDelegateBoundaryResponse defines the response structure for executing a +// MsgUpdateDelegateBoundary message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateDelegateBoundaryResponse struct { +} + +func (m *MsgUpdateDelegateBoundaryResponse) Reset() { *m = MsgUpdateDelegateBoundaryResponse{} } +func (m *MsgUpdateDelegateBoundaryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateDelegateBoundaryResponse) ProtoMessage() {} +func (*MsgUpdateDelegateBoundaryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_148586c432693946, []int{1} +} +func (m *MsgUpdateDelegateBoundaryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateDelegateBoundaryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateDelegateBoundaryResponse.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 *MsgUpdateDelegateBoundaryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateDelegateBoundaryResponse.Merge(m, src) +} +func (m *MsgUpdateDelegateBoundaryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateDelegateBoundaryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateDelegateBoundaryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateDelegateBoundaryResponse proto.InternalMessageInfo + +// MsgUpdateRedelegateBoundary is the Msg/MsgUpdateRedelegateBoundary request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateRedelegateBoundary struct { + // authority is the address that controls the module (defaults to x/gov unless + // overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // boundary defines the x/tx-boundary parameters to update. + // + // NOTE: All parameters must be supplied. + Boundary Boundary `protobuf:"bytes,2,opt,name=boundary,proto3" json:"boundary"` +} + +func (m *MsgUpdateRedelegateBoundary) Reset() { *m = MsgUpdateRedelegateBoundary{} } +func (m *MsgUpdateRedelegateBoundary) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateRedelegateBoundary) ProtoMessage() {} +func (*MsgUpdateRedelegateBoundary) Descriptor() ([]byte, []int) { + return fileDescriptor_148586c432693946, []int{2} +} +func (m *MsgUpdateRedelegateBoundary) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateRedelegateBoundary) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateRedelegateBoundary.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 *MsgUpdateRedelegateBoundary) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateRedelegateBoundary.Merge(m, src) +} +func (m *MsgUpdateRedelegateBoundary) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateRedelegateBoundary) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateRedelegateBoundary.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateRedelegateBoundary proto.InternalMessageInfo + +func (m *MsgUpdateRedelegateBoundary) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateRedelegateBoundary) GetBoundary() Boundary { + if m != nil { + return m.Boundary + } + return Boundary{} +} + +// MsgUpdateRedelegateBoundaryResponse defines the response structure for executing a +// MsgUpdateRedelegateBoundary message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateRedelegateBoundaryResponse struct { +} + +func (m *MsgUpdateRedelegateBoundaryResponse) Reset() { *m = MsgUpdateRedelegateBoundaryResponse{} } +func (m *MsgUpdateRedelegateBoundaryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateRedelegateBoundaryResponse) ProtoMessage() {} +func (*MsgUpdateRedelegateBoundaryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_148586c432693946, []int{3} +} +func (m *MsgUpdateRedelegateBoundaryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateRedelegateBoundaryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateRedelegateBoundaryResponse.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 *MsgUpdateRedelegateBoundaryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateRedelegateBoundaryResponse.Merge(m, src) +} +func (m *MsgUpdateRedelegateBoundaryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateRedelegateBoundaryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateRedelegateBoundaryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateRedelegateBoundaryResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateDelegateBoundary)(nil), "centauri.txboundary.v1beta1.MsgUpdateDelegateBoundary") + proto.RegisterType((*MsgUpdateDelegateBoundaryResponse)(nil), "centauri.txboundary.v1beta1.MsgUpdateDelegateBoundaryResponse") + proto.RegisterType((*MsgUpdateRedelegateBoundary)(nil), "centauri.txboundary.v1beta1.MsgUpdateRedelegateBoundary") + proto.RegisterType((*MsgUpdateRedelegateBoundaryResponse)(nil), "centauri.txboundary.v1beta1.MsgUpdateRedelegateBoundaryResponse") +} + +func init() { + proto.RegisterFile("centauri/txboundary/v1beta1/tx.proto", fileDescriptor_148586c432693946) +} + +var fileDescriptor_148586c432693946 = []byte{ + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0x2f, 0xa9, 0x48, 0xca, 0x2f, 0xcd, 0x4b, 0x49, 0x2c, 0xaa, 0xd4, + 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x92, 0x86, 0xa9, 0xd2, 0x43, 0xa8, 0xd2, 0x83, 0xaa, 0x92, 0x12, 0x4f, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0xcf, 0x2d, 0x4e, 0xd7, 0x2f, 0x33, 0x04, 0x51, 0x10, 0x5d, 0x52, 0x82, 0x89, + 0xb9, 0x99, 0x79, 0xf9, 0xfa, 0x60, 0x12, 0x2a, 0x24, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x66, 0xea, + 0x83, 0x58, 0x50, 0x51, 0x49, 0x88, 0x09, 0xf1, 0x10, 0x09, 0x08, 0x07, 0x2a, 0xa5, 0x85, 0xcf, + 0x7d, 0x70, 0xa7, 0x40, 0xd4, 0xca, 0x41, 0x1d, 0x92, 0x94, 0x58, 0x9c, 0x0a, 0x57, 0x93, 0x9c, + 0x9f, 0x99, 0x07, 0x91, 0x57, 0x7a, 0xca, 0xc8, 0x25, 0xe9, 0x5b, 0x9c, 0x1e, 0x5a, 0x90, 0x92, + 0x58, 0x92, 0xea, 0x92, 0x9a, 0x93, 0x9a, 0x9e, 0x58, 0x92, 0xea, 0x04, 0x35, 0x43, 0xc8, 0x8c, + 0x8b, 0x33, 0xb1, 0xb4, 0x24, 0x23, 0xbf, 0x28, 0xb3, 0xa4, 0x52, 0x82, 0x51, 0x81, 0x51, 0x83, + 0xd3, 0x49, 0xe2, 0xd2, 0x16, 0x5d, 0x11, 0xa8, 0x73, 0x1c, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, + 0x83, 0x4b, 0x8a, 0x32, 0xf3, 0xd2, 0x83, 0x10, 0x4a, 0x85, 0x7c, 0xb8, 0x38, 0x60, 0xee, 0x90, + 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd5, 0xc3, 0x13, 0x5c, 0x7a, 0x30, 0x0b, 0x9d, 0x38, + 0x4f, 0xdc, 0x93, 0x67, 0x58, 0xf1, 0x7c, 0x83, 0x16, 0x63, 0x10, 0xdc, 0x04, 0x2b, 0xa7, 0xa6, + 0xe7, 0x1b, 0xb4, 0x10, 0xa6, 0x77, 0x3d, 0xdf, 0xa0, 0xa5, 0x0f, 0x0f, 0x82, 0x0a, 0xe4, 0x40, + 0xc0, 0xe9, 0x13, 0x25, 0x65, 0x2e, 0x45, 0x9c, 0x92, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, + 0xa9, 0x4a, 0xcf, 0x19, 0xb9, 0xa4, 0xe1, 0xaa, 0x82, 0x52, 0x53, 0x86, 0x6f, 0x70, 0xa8, 0x72, + 0x29, 0xe3, 0xf1, 0x28, 0x2c, 0x40, 0x8c, 0x76, 0x30, 0x71, 0x31, 0xfb, 0x16, 0xa7, 0x0b, 0x4d, + 0x60, 0xe4, 0x12, 0xc3, 0x95, 0x44, 0xf0, 0xfa, 0x04, 0xa7, 0x0b, 0xa4, 0xec, 0xc8, 0xd3, 0x07, + 0x73, 0x9a, 0xd0, 0x34, 0x46, 0x2e, 0x09, 0x9c, 0x11, 0x65, 0x41, 0x9c, 0xe1, 0x98, 0x3a, 0xa5, + 0x1c, 0xc8, 0xd5, 0x09, 0x73, 0x98, 0x14, 0x6b, 0x03, 0x28, 0xbe, 0x9c, 0x74, 0x4f, 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, 0x4a, 0x18, 0x14, 0x47, 0xba, 0xf0, 0x48, 0x2a, 0xa9, + 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x67, 0x47, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2e, + 0x6a, 0x87, 0xa9, 0x7c, 0x04, 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 { + UpdateDelegateBoundary(ctx context.Context, in *MsgUpdateDelegateBoundary, opts ...grpc.CallOption) (*MsgUpdateDelegateBoundaryResponse, error) + UpdateRedelegateBoundary(ctx context.Context, in *MsgUpdateRedelegateBoundary, opts ...grpc.CallOption) (*MsgUpdateRedelegateBoundaryResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateDelegateBoundary(ctx context.Context, in *MsgUpdateDelegateBoundary, opts ...grpc.CallOption) (*MsgUpdateDelegateBoundaryResponse, error) { + out := new(MsgUpdateDelegateBoundaryResponse) + err := c.cc.Invoke(ctx, "/centauri.txboundary.v1beta1.Msg/UpdateDelegateBoundary", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateRedelegateBoundary(ctx context.Context, in *MsgUpdateRedelegateBoundary, opts ...grpc.CallOption) (*MsgUpdateRedelegateBoundaryResponse, error) { + out := new(MsgUpdateRedelegateBoundaryResponse) + err := c.cc.Invoke(ctx, "/centauri.txboundary.v1beta1.Msg/UpdateRedelegateBoundary", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + UpdateDelegateBoundary(context.Context, *MsgUpdateDelegateBoundary) (*MsgUpdateDelegateBoundaryResponse, error) + UpdateRedelegateBoundary(context.Context, *MsgUpdateRedelegateBoundary) (*MsgUpdateRedelegateBoundaryResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateDelegateBoundary(ctx context.Context, req *MsgUpdateDelegateBoundary) (*MsgUpdateDelegateBoundaryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateDelegateBoundary not implemented") +} +func (*UnimplementedMsgServer) UpdateRedelegateBoundary(ctx context.Context, req *MsgUpdateRedelegateBoundary) (*MsgUpdateRedelegateBoundaryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateRedelegateBoundary not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateDelegateBoundary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateDelegateBoundary) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateDelegateBoundary(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.txboundary.v1beta1.Msg/UpdateDelegateBoundary", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateDelegateBoundary(ctx, req.(*MsgUpdateDelegateBoundary)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateRedelegateBoundary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateRedelegateBoundary) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateRedelegateBoundary(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.txboundary.v1beta1.Msg/UpdateRedelegateBoundary", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateRedelegateBoundary(ctx, req.(*MsgUpdateRedelegateBoundary)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "centauri.txboundary.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateDelegateBoundary", + Handler: _Msg_UpdateDelegateBoundary_Handler, + }, + { + MethodName: "UpdateRedelegateBoundary", + Handler: _Msg_UpdateRedelegateBoundary_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "centauri/txboundary/v1beta1/tx.proto", +} + +func (m *MsgUpdateDelegateBoundary) 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 *MsgUpdateDelegateBoundary) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateDelegateBoundary) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Boundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateDelegateBoundaryResponse) 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 *MsgUpdateDelegateBoundaryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateDelegateBoundaryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateRedelegateBoundary) 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 *MsgUpdateRedelegateBoundary) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateRedelegateBoundary) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Boundary.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateRedelegateBoundaryResponse) 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 *MsgUpdateRedelegateBoundaryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateRedelegateBoundaryResponse) 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 *MsgUpdateDelegateBoundary) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Boundary.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateDelegateBoundaryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateRedelegateBoundary) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Boundary.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateRedelegateBoundaryResponse) 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 *MsgUpdateDelegateBoundary) 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: MsgUpdateDelegateBoundary: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateDelegateBoundary: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Boundary", 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.Boundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *MsgUpdateDelegateBoundaryResponse) 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: MsgUpdateDelegateBoundaryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateDelegateBoundaryResponse: 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 *MsgUpdateRedelegateBoundary) 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: MsgUpdateRedelegateBoundary: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateRedelegateBoundary: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Boundary", 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.Boundary.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *MsgUpdateRedelegateBoundaryResponse) 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: MsgUpdateRedelegateBoundaryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateRedelegateBoundaryResponse: 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") +) From e2a94940c8ad6b446bd6e145e2178d55aeb5232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 11:56:56 +0700 Subject: [PATCH 04/14] tx boundary types --- x/tx-boundary/types/codec.go | 31 +++++++++++++ x/tx-boundary/types/genesis.go | 12 +++++ x/tx-boundary/types/keys.go | 18 ++++++++ x/tx-boundary/types/msg.go | 84 ++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 x/tx-boundary/types/codec.go create mode 100644 x/tx-boundary/types/genesis.go create mode 100644 x/tx-boundary/types/keys.go create mode 100644 x/tx-boundary/types/msg.go diff --git a/x/tx-boundary/types/codec.go b/x/tx-boundary/types/codec.go new file mode 100644 index 000000000..cc858e223 --- /dev/null +++ b/x/tx-boundary/types/codec.go @@ -0,0 +1,31 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" +) + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + + RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) + amino.Seal() +} + +// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +} + +// RegisterInterfaces registers the interfaces types with the interface registry. +func RegisterInterfaces(registry types.InterfaceRegistry) { +} diff --git a/x/tx-boundary/types/genesis.go b/x/tx-boundary/types/genesis.go new file mode 100644 index 000000000..60961e6fc --- /dev/null +++ b/x/tx-boundary/types/genesis.go @@ -0,0 +1,12 @@ +package types + +// DefaultGenesisState creates a default GenesisState object +func DefaultGenesisState() *GenesisState { + return &GenesisState{} +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func ValidateGenesis(data GenesisState) error { + return nil +} diff --git a/x/tx-boundary/types/keys.go b/x/tx-boundary/types/keys.go new file mode 100644 index 000000000..d5bcc1ab4 --- /dev/null +++ b/x/tx-boundary/types/keys.go @@ -0,0 +1,18 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "txboundary" + + // StoreKey defines the primary module store key + StoreKey = ModuleName +) + +// MinterKey is the key to use for the keeper store. +var ( + // DelegateBoundaryKey is the key to use for the keeper store. + DelegateBoundaryKey = []byte{0x00} + + // RedelegateBoundaryKey is the key to use for the keeper store. + RedelegateBoundaryKey = []byte{0x01} +) diff --git a/x/tx-boundary/types/msg.go b/x/tx-boundary/types/msg.go new file mode 100644 index 000000000..fc9676ba8 --- /dev/null +++ b/x/tx-boundary/types/msg.go @@ -0,0 +1,84 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec/legacy" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpdateDelegateBoundary{} + +// Route Implements Msg. +func (m MsgUpdateDelegateBoundary) Route() string { return sdk.MsgTypeURL(&m) } + +// Type Implements Msg. +func (m MsgUpdateDelegateBoundary) Type() string { return sdk.MsgTypeURL(&m) } + +// GetSigners returns the expected signers for a MsgMintAndAllocateExp . +func (m MsgUpdateDelegateBoundary) GetSigners() []sdk.AccAddress { + authorityAddr, err := sdk.AccAddressFromBech32(m.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{authorityAddr} +} + +// GetSignBytes Implements Msg. +func (m MsgUpdateDelegateBoundary) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) +} + +// ValidateBasic does a sanity check on the provided data. +func (m MsgUpdateDelegateBoundary) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Authority) + if err != nil { + return errorsmod.Wrap(err, "invalid authority address") + } + return nil +} + +func NewMsgUpdateDelegateBoundary(boundary Boundary, authority string) *MsgUpdateDelegateBoundary { + return &MsgUpdateDelegateBoundary{ + Authority: authority, + Boundary: boundary, + } +} + +var _ sdk.Msg = &MsgUpdateRedelegateBoundary{} + +// Route Implements Msg. +func (m MsgUpdateRedelegateBoundary) Route() string { return sdk.MsgTypeURL(&m) } + +// Type Implements Msg. +func (m MsgUpdateRedelegateBoundary) Type() string { return sdk.MsgTypeURL(&m) } + +// GetSigners returns the expected signers for a MsgMintAndAllocateExp . +func (m MsgUpdateRedelegateBoundary) GetSigners() []sdk.AccAddress { + authorityAddr, err := sdk.AccAddressFromBech32(m.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{authorityAddr} +} + +// GetSignBytes Implements Msg. +func (m MsgUpdateRedelegateBoundary) GetSignBytes() []byte { + return sdk.MustSortJSON(legacy.Cdc.MustMarshalJSON(&m)) +} + +// ValidateBasic does a sanity check on the provided data. +func (m MsgUpdateRedelegateBoundary) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(m.Authority) + if err != nil { + return errorsmod.Wrap(err, "invalid authority address") + } + + return nil +} + +func NewMsgUpdateRedelegateBoundary(boundary Boundary, authority string) *MsgUpdateRedelegateBoundary { + return &MsgUpdateRedelegateBoundary{ + Authority: authority, + Boundary: boundary, + } +} From 1f766409b00fee6fac982fc0bc7b30abc5ae38a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 11:57:18 +0700 Subject: [PATCH 05/14] cli for tx boundary --- x/tx-boundary/client/cli/query.go | 85 +++++++++++++++++++++++++++ x/tx-boundary/client/cli/tx.go | 98 +++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 x/tx-boundary/client/cli/query.go create mode 100644 x/tx-boundary/client/cli/tx.go diff --git a/x/tx-boundary/client/cli/query.go b/x/tx-boundary/client/cli/query.go new file mode 100644 index 000000000..74ef00996 --- /dev/null +++ b/x/tx-boundary/client/cli/query.go @@ -0,0 +1,85 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +// GetQueryCmd returns the cli query commands for the minting module. +func GetQueryCmd() *cobra.Command { + txboundaryQueryCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the tx-boundary module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + txboundaryQueryCmd.AddCommand( + GetCmdQueryDelegateBoundary(), + GetCmdQueryRedelegateBoundary(), + ) + + return txboundaryQueryCmd +} + +// GetCmdQueryDelegateBoundary implements a command to return the current delegate boundary value +func GetCmdQueryDelegateBoundary() *cobra.Command { + cmd := &cobra.Command{ + Use: "delegate-boundary", + Short: "Query the current DelegateBoundary value", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryDelegateBoundaryRequest{} + res, err := queryClient.DelegateBoundary(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintString(fmt.Sprintf("%s\n", &res.Boundary)) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetCmdQueryDelegateBoundary implements a command to return the current delegate boundary value +func GetCmdQueryRedelegateBoundary() *cobra.Command { + cmd := &cobra.Command{ + Use: "redelegate-boundary", + Short: "Query the current RedelegateBoundary value", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryRedelegateBoundaryRequest{} + res, err := queryClient.RedelegateBoundary(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintString(fmt.Sprintf("%s\n", &res.Boundary)) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/tx-boundary/client/cli/tx.go b/x/tx-boundary/client/cli/tx.go new file mode 100644 index 000000000..f6c3d69dd --- /dev/null +++ b/x/tx-boundary/client/cli/tx.go @@ -0,0 +1,98 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" + "github.com/spf13/cobra" +) + +// GetTxCmd returns the tx commands for tx-boundary +func GetTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Exp transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + txCmd.AddCommand( + GetCmdUpdateDelegateBoundary(), + GetCmdQueryRedelegateBoundary(), + ) + return txCmd +} + +func GetCmdUpdateDelegateBoundary() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-delegate [tx_limit] [block_per_generation]", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + tx_limit, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + block_per_generation, err := strconv.ParseInt(args[1], 10, 64) + if err != nil { + return err + } + + msg := types.NewMsgUpdateDelegateBoundary( + types.Boundary{ + TxLimit: tx_limit, + BlocksPerGeneration: block_per_generation, + }, + clientCtx.GetFromAddress().String(), + ) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func GetCmdUpdateRedelegateBoundary() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-redelegate [tx_limit] [block_per_generation]", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + tx_limit, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return err + } + + block_per_generation, err := strconv.ParseInt(args[1], 10, 64) + if err != nil { + return err + } + + msg := types.NewMsgUpdateRedelegateBoundary( + types.Boundary{ + TxLimit: tx_limit, + BlocksPerGeneration: block_per_generation, + }, + clientCtx.GetFromAddress().String(), + ) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + + return cmd +} From fc1829d88c184781f54c37abd92e2bd283ee3023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 11:57:39 +0700 Subject: [PATCH 06/14] add tx-boundary keeper --- x/tx-boundary/keeper/genensis.go | 19 ++++ x/tx-boundary/keeper/grpc_query.go | 26 ++++++ x/tx-boundary/keeper/keeper.go | 139 +++++++++++++++++++++++++++++ x/tx-boundary/keeper/msg_server.go | 1 + 4 files changed, 185 insertions(+) create mode 100644 x/tx-boundary/keeper/genensis.go create mode 100644 x/tx-boundary/keeper/grpc_query.go create mode 100644 x/tx-boundary/keeper/keeper.go create mode 100644 x/tx-boundary/keeper/msg_server.go diff --git a/x/tx-boundary/keeper/genensis.go b/x/tx-boundary/keeper/genensis.go new file mode 100644 index 000000000..3b86b02fd --- /dev/null +++ b/x/tx-boundary/keeper/genensis.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + // TODO: init genensis +} + +// ExportGenesis returns the capability module's exported genesis. +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + // TODO: export genensis + return nil +} diff --git a/x/tx-boundary/keeper/grpc_query.go b/x/tx-boundary/keeper/grpc_query.go new file mode 100644 index 000000000..c97ff9c6a --- /dev/null +++ b/x/tx-boundary/keeper/grpc_query.go @@ -0,0 +1,26 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +var _ types.QueryServer = Keeper{} + +// DelegateBoundary returns params of the mint module. +func (k Keeper) DelegateBoundary(c context.Context, req *types.QueryDelegateBoundaryRequest) (*types.QueryDelegateBoundaryResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + boundary := k.GetDelegateBoundary(ctx) + + return &types.QueryDelegateBoundaryResponse{Boundary: boundary}, nil +} + +// DelegateBoundary returns params of the mint module. +func (k Keeper) RedelegateBoundary(c context.Context, _ *types.QueryRedelegateBoundaryRequest) (*types.QueryRedelegateBoundaryResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + boundary := k.GetRedelegateBoundary(ctx) + + return &types.QueryRedelegateBoundaryResponse{Boundary: boundary}, nil +} diff --git a/x/tx-boundary/keeper/keeper.go b/x/tx-boundary/keeper/keeper.go new file mode 100644 index 000000000..9bf9ccf13 --- /dev/null +++ b/x/tx-boundary/keeper/keeper.go @@ -0,0 +1,139 @@ +package keeper + +import ( + "fmt" + + "github.com/cometbft/cometbft/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +// Keeper struct +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string +} + +// NewKeeper returns keeper +func NewKeeper(cdc codec.Codec, storeKey storetypes.StoreKey, authority string) Keeper { + return Keeper{ + cdc: cdc, + storeKey: storeKey, + authority: authority, + } +} + +// GetAuthority returns the x/mint module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + +// Logger returns logger +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// TODO: Duplicate fnc here +// SetDelegateBoundary sets the delegate boundary. +func (k Keeper) SetDelegateBoundary(ctx sdk.Context, boundary types.Boundary) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&boundary) + store.Set(types.DelegateBoundaryKey, bz) +} + +// TODO: Duplicate fnc here +// GetDelegateBoundary sets the delegate boundary. +func (k Keeper) GetDelegateBoundary(ctx sdk.Context) (boundary types.Boundary) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.DelegateBoundaryKey) + if bz == nil { + panic("stored delegate boundary should not have been nil") + } + + k.cdc.MustUnmarshal(bz, &boundary) + return +} + +// SetRedelegateBoundary sets the delegate boundary. +func (k Keeper) SetRedelegateBoundary(ctx sdk.Context, boundary types.Boundary) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&boundary) + store.Set(types.RedelegateBoundaryKey, bz) +} + +// GetRedelegateBoundary sets the delegate boundary. +func (k Keeper) GetRedelegateBoundary(ctx sdk.Context) (boundary types.Boundary) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.RedelegateBoundaryKey) + if bz == nil { + panic("stored redelegate boundary should not have been nil") + } + + k.cdc.MustUnmarshal(bz, &boundary) + return +} + +// SetDelegateCount set the number of delegate tx for a given address +func (k Keeper) SetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress, limit_per_addr types.LimitPerAddr) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&limit_per_addr) + store.Set(addr, bz) +} + +// GetDelegateCount get the number of delegate tx for a given address +func (k Keeper) GetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) (limit_per_addr types.LimitPerAddr) { + store := ctx.KVStore(k.storeKey) + if store.Has(addr) == false { + return types.LimitPerAddr{ + DelegateCount: 0, + ReledegateCount: 0, + LatestUpdateBlock: 0, + } + } + bz := store.Get(addr) + k.cdc.MustUnmarshal(bz, &limit_per_addr) + return +} + +func (k Keeper) UpdateLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) { + limit_per_addr := k.GetLimitPerAddr(ctx, addr) + if limit_per_addr.LatestUpdateBlock == 0 { + return + } + boundary := k.GetDelegateBoundary(ctx) + if limit_per_addr.LatestUpdateBlock+boundary.BlocksPerGeneration >= ctx.BlockHeight() { + // Calculate the generated tx number from the duration between latest update block and curent block height + var generatedTx int64 + duration := limit_per_addr.LatestUpdateBlock + boundary.BlocksPerGeneration - ctx.BlockHeight() + if duration/boundary.BlocksPerGeneration > 5 { + generatedTx = 5 + } else { + generatedTx = duration / boundary.BlocksPerGeneration + } + + // Update the delegate tx limit + if uint64(generatedTx) > limit_per_addr.DelegateCount { + limit_per_addr.DelegateCount = 0 + } else { + limit_per_addr.DelegateCount -= uint64(generatedTx) + } + // Update the redelegate tx limit + if uint64(generatedTx) > limit_per_addr.ReledegateCount { + limit_per_addr.ReledegateCount = 0 + } else { + limit_per_addr.ReledegateCount -= uint64(generatedTx) + } + // Update LatestUpdateBlock + limit_per_addr.LatestUpdateBlock = ctx.BlockHeight() + return + } + return +} diff --git a/x/tx-boundary/keeper/msg_server.go b/x/tx-boundary/keeper/msg_server.go new file mode 100644 index 000000000..d810a5e68 --- /dev/null +++ b/x/tx-boundary/keeper/msg_server.go @@ -0,0 +1 @@ +package keeper \ No newline at end of file From f9f85461d6aa980b60f6282835945afa7a385a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 11:58:34 +0700 Subject: [PATCH 07/14] staking ante for MsgDelegate and MsgBeginRedelegate --- app/ante/ante.go | 3 + app/ante/custom_ante.go | 79 +++++++++++++++++++++ app/app.go | 10 +++ app/keepers/keepers.go | 10 +++ x/tx-boundary/module.go | 149 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 app/ante/custom_ante.go create mode 100644 x/tx-boundary/module.go diff --git a/app/ante/ante.go b/app/ante/ante.go index e0b86cafb..6e414ba99 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -10,6 +10,7 @@ import ( ante "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/signing" tfmwKeeper "github.com/notional-labs/centauri/v4/x/transfermiddleware/keeper" + txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" ) // Link to default ante handler used by cosmos sdk: @@ -21,6 +22,7 @@ func NewAnteHandler( signModeHandler signing.SignModeHandler, channelKeeper *ibckeeper.Keeper, tfmwKeeper tfmwKeeper.Keeper, + txBoundaryKeeper txBoundaryKeeper.Keeper, codec codec.BinaryCodec, ) sdk.AnteHandler { return sdk.ChainAnteDecorators( @@ -30,6 +32,7 @@ func NewAnteHandler( ante.NewValidateMemoDecorator(ak), ante.NewConsumeGasForTxSizeDecorator(ak), NewIBCPermissionDecorator(codec, tfmwKeeper), + NewStakingPermissionDecorator(codec, txBoundaryKeeper), ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(ak), ante.NewSigGasConsumeDecorator(ak, sigGasConsumer), diff --git a/app/ante/custom_ante.go b/app/ante/custom_ante.go new file mode 100644 index 000000000..1a108e917 --- /dev/null +++ b/app/ante/custom_ante.go @@ -0,0 +1,79 @@ +package ante + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" +) + +type StakingPermissionDecorator struct { + cdc codec.BinaryCodec + txBoundary txBoundaryKeeper.Keeper +} + +func NewStakingPermissionDecorator(cdc codec.BinaryCodec, keeper txBoundaryKeeper.Keeper) StakingPermissionDecorator { + return StakingPermissionDecorator{ + cdc: cdc, + txBoundary: keeper, + } +} + +func (g StakingPermissionDecorator) AnteHandle( + ctx sdk.Context, tx sdk.Tx, + simulate bool, next sdk.AnteHandler, +) (newCtx sdk.Context, err error) { + // run checks only on CheckTx or simulate + if simulate { + return next(ctx, tx, simulate) + } + + msgs := tx.GetMsgs() + if err = g.ValidateStakingMsg(ctx, msgs); err != nil { + return ctx, err + } + + return next(ctx, tx, simulate) +} + +// ValidateStakingMsg validate +func (g StakingPermissionDecorator) ValidateStakingMsg(ctx sdk.Context, msgs []sdk.Msg) error { + for _, m := range msgs { + switch msg := m.(type) { + case *stakingtypes.MsgDelegate: + if err := g.validDelegateMsg(ctx, msg); err != nil { + return err + } + case *stakingtypes.MsgBeginRedelegate: + if err := g.validRedelegateMsg(ctx, msg); err != nil { + return err + } + default: + return nil + } + } + return nil +} + +func (g StakingPermissionDecorator) validDelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgDelegate) error { + boundary := g.txBoundary.GetDelegateBoundary(ctx) + g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) + if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { + return fmt.Errorf("delegate tx denied, excess tx limit") + } + + return nil +} + +func (g StakingPermissionDecorator) validRedelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgBeginRedelegate) error { + boundary := g.txBoundary.GetRedelegateBoundary(ctx) + g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) + if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { + return fmt.Errorf("redelegate tx denied, excess tx limit") + } + + return nil +} diff --git a/app/app.go b/app/app.go index 17735a958..4ae7c01ba 100644 --- a/app/app.go +++ b/app/app.go @@ -96,6 +96,9 @@ import ( transfermiddleware "github.com/notional-labs/centauri/v4/x/transfermiddleware" transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types" + txBoundary "github.com/notional-labs/centauri/v4/x/tx-boundary" + txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types" + ratelimitmodule "github.com/notional-labs/centauri/v4/x/ratelimit" ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types" @@ -208,6 +211,7 @@ var ( ica.AppModuleBasic{}, ibc_hooks.AppModuleBasic{}, transfermiddleware.AppModuleBasic{}, + txBoundary.AppModuleBasic{}, ratelimitmodule.AppModuleBasic{}, consensus.AppModuleBasic{}, alliancemodule.AppModuleBasic{}, @@ -322,6 +326,7 @@ func NewCentauriApp( transferModule := transfer.NewAppModule(app.TransferKeeper) routerModule := router.NewAppModule(app.RouterKeeper) transfermiddlewareModule := transfermiddleware.NewAppModule(&app.TransferMiddlewareKeeper) + txBoundaryModule := txBoundary.NewAppModule(appCodec, app.TxBoundaryKeepper) ratelimitModule := ratelimitmodule.NewAppModule(&app.RatelimitKeeper) icqModule := icq.NewAppModule(app.ICQKeeper) ibcHooksModule := ibc_hooks.NewAppModule() @@ -364,6 +369,7 @@ func NewCentauriApp( wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), routerModule, transfermiddlewareModule, + txBoundaryModule, icaModule, ratelimitModule, alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), @@ -387,6 +393,7 @@ func NewCentauriApp( ibctransfertypes.ModuleName, routertypes.ModuleName, transfermiddlewaretypes.ModuleName, + txBoundaryTypes.ModuleName, ratelimitmoduletypes.ModuleName, ibchookstypes.ModuleName, icqtypes.ModuleName, @@ -426,6 +433,7 @@ func NewCentauriApp( ibchost.ModuleName, routertypes.ModuleName, transfermiddlewaretypes.ModuleName, + txBoundaryTypes.ModuleName, ratelimitmoduletypes.ModuleName, ibchookstypes.ModuleName, ibctransfertypes.ModuleName, @@ -462,6 +470,7 @@ func NewCentauriApp( icqtypes.ModuleName, routertypes.ModuleName, transfermiddlewaretypes.ModuleName, + txBoundaryTypes.ModuleName, ratelimitmoduletypes.ModuleName, ibchookstypes.ModuleName, feegrant.ModuleName, @@ -521,6 +530,7 @@ func NewCentauriApp( encodingConfig.TxConfig.SignModeHandler(), app.IBCKeeper, app.TransferMiddlewareKeeper, + app.TxBoundaryKeepper, appCodec, )) app.SetEndBlocker(app.EndBlocker) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 1cd6ba5fb..e6fb46f2d 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -80,6 +80,9 @@ import ( transfermiddlewarekeeper "github.com/notional-labs/centauri/v4/x/transfermiddleware/keeper" transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types" + txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" + txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types" + ratelimitmodule "github.com/notional-labs/centauri/v4/x/ratelimit" ratelimitmodulekeeper "github.com/notional-labs/centauri/v4/x/ratelimit/keeper" ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types" @@ -145,6 +148,7 @@ type AppKeepers struct { ConsensusParamsKeeper consensusparamkeeper.Keeper // this line is used by starport scaffolding # stargate/app/keeperDeclaration TransferMiddlewareKeeper transfermiddlewarekeeper.Keeper + TxBoundaryKeepper txBoundaryKeeper.Keeper RouterKeeper *routerkeeper.Keeper RatelimitKeeper ratelimitmodulekeeper.Keeper AllianceKeeper alliancemodulekeeper.Keeper @@ -273,6 +277,12 @@ func (appKeepers *AppKeepers) InitNormalKeepers( authorityAddress, ) + appKeepers.TxBoundaryKeepper = txBoundaryKeeper.NewKeeper( + appCodec, + appKeepers.keys[txBoundaryTypes.StoreKey], + authorityAddress, + ) + appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, appKeepers.keys[ibctransfertypes.StoreKey], appKeepers.GetSubspace(ibctransfertypes.ModuleName), diff --git a/x/tx-boundary/module.go b/x/tx-boundary/module.go new file mode 100644 index 000000000..dd980fe34 --- /dev/null +++ b/x/tx-boundary/module.go @@ -0,0 +1,149 @@ +package tx_boundary + +import ( + "context" + "encoding/json" + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/notional-labs/centauri/v4/x/tx-boundary/client/cli" + "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic defines the basic application module used by the tx-boundary module. +type AppModuleBasic struct { + cdc codec.Codec +} + +var _ module.AppModuleBasic = AppModuleBasic{} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the tx-boundary module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the tx-boundary module's types on the given LegacyAmino codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module interface +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns default genesis state as raw bytes for the tx-boundary +// module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the tx-boundary module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(data) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the tx-boundary module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns no root tx command for the tx-boundary module. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the tx-boundary module. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// AppModule implements an application module for the tx-boundary module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +// NewAppModule creates a new AppModule object. If the InflationCalculationFn +// argument is nil, then the SDK's default inflation function will be used. +func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the tx-boundary module's name. +func (AppModule) Name() string { + return types.ModuleName +} + +// RegisterInvariants registers the tx-boundary module invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// RegisterServices registers a gRPC query service to respond to the +// module-specific gRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + // types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + // types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// InitGenesis performs genesis initialization for the tx-boundary module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + + am.keeper.InitGenesis(ctx, genesisState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the tx-boundary +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock returns the begin blocker for the tx-boundary module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// WeightedOperations doesn't return any tx-boundary module operation. +func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} From 42bdef139e0bccf962a20b94a2bff755dae3953d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 13:30:12 +0700 Subject: [PATCH 08/14] genesis for tx-boundary --- x/tx-boundary/keeper/genensis.go | 11 ++++++++--- x/tx-boundary/types/genesis.go | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/x/tx-boundary/keeper/genensis.go b/x/tx-boundary/keeper/genensis.go index 3b86b02fd..a871d459c 100644 --- a/x/tx-boundary/keeper/genensis.go +++ b/x/tx-boundary/keeper/genensis.go @@ -9,11 +9,16 @@ import ( // InitGenesis initializes the capability module's state from a provided genesis // state. func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { - // TODO: init genensis + k.SetDelegateBoundary(ctx, genState.DelegateBoundary) + k.SetRedelegateBoundary(ctx, genState.RedelegateBoundary) } // ExportGenesis returns the capability module's exported genesis. func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { - // TODO: export genensis - return nil + genesis := types.DefaultGenesisState() + + genesis.DelegateBoundary = k.GetDelegateBoundary(ctx) + genesis.RedelegateBoundary = k.GetRedelegateBoundary(ctx) + + return genesis } diff --git a/x/tx-boundary/types/genesis.go b/x/tx-boundary/types/genesis.go index 60961e6fc..427737e07 100644 --- a/x/tx-boundary/types/genesis.go +++ b/x/tx-boundary/types/genesis.go @@ -1,8 +1,22 @@ package types +var ( + DefaultDelegateBoundary = Boundary{ + TxLimit: 5, + BlocksPerGeneration: 5, + } + DefaultRedelegateBoundary = Boundary{ + TxLimit: 5, + BlocksPerGeneration: 5, + } +) + // DefaultGenesisState creates a default GenesisState object func DefaultGenesisState() *GenesisState { - return &GenesisState{} + return &GenesisState{ + DelegateBoundary: DefaultDelegateBoundary, + RedelegateBoundary: DefaultRedelegateBoundary, + } } // Validate performs basic genesis state validation returning an error upon any From 124d2d849bed265229ca32a8775a9c0f43004664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 13:48:27 +0700 Subject: [PATCH 09/14] update ante logic --- app/ante/custom_ante.go | 11 ++++++++--- x/tx-boundary/keeper/keeper.go | 26 ++++++++++++++++++++++++++ x/tx-boundary/types/genesis.go | 5 +++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/ante/custom_ante.go b/app/ante/custom_ante.go index 1a108e917..8fadd07aa 100644 --- a/app/ante/custom_ante.go +++ b/app/ante/custom_ante.go @@ -61,9 +61,12 @@ func (g StakingPermissionDecorator) ValidateStakingMsg(ctx sdk.Context, msgs []s func (g StakingPermissionDecorator) validDelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgDelegate) error { boundary := g.txBoundary.GetDelegateBoundary(ctx) g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) - if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { + if boundary.TxLimit == 0 { + return nil + } else if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { return fmt.Errorf("delegate tx denied, excess tx limit") } + g.txBoundary.IncrementDelegateCount(ctx, sdk.AccAddress(msg.DelegatorAddress)) return nil } @@ -71,9 +74,11 @@ func (g StakingPermissionDecorator) validDelegateMsg(ctx sdk.Context, msg *staki func (g StakingPermissionDecorator) validRedelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgBeginRedelegate) error { boundary := g.txBoundary.GetRedelegateBoundary(ctx) g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) - if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { + if boundary.TxLimit == 0 { + return nil + } else if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).ReledegateCount > boundary.TxLimit { return fmt.Errorf("redelegate tx denied, excess tx limit") } - + g.txBoundary.IncrementRedelegateCount(ctx, sdk.AccAddress(msg.DelegatorAddress)) return nil } diff --git a/x/tx-boundary/keeper/keeper.go b/x/tx-boundary/keeper/keeper.go index 9bf9ccf13..dca036d1c 100644 --- a/x/tx-boundary/keeper/keeper.go +++ b/x/tx-boundary/keeper/keeper.go @@ -88,6 +88,32 @@ func (k Keeper) SetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress, limit_per_ store.Set(addr, bz) } +func (k Keeper) IncrementDelegateCount(ctx sdk.Context, addr sdk.AccAddress) error { + store := ctx.KVStore(k.storeKey) + if store.Has(addr) == false { + return fmt.Errorf("key is nil") + } + bz := store.Get(addr) + var limit_per_addr types.LimitPerAddr + k.cdc.MustUnmarshal(bz, &limit_per_addr) + limit_per_addr.DelegateCount += 1 + k.SetLimitPerAddr(ctx, addr, limit_per_addr) + return nil +} + +func (k Keeper) IncrementRedelegateCount(ctx sdk.Context, addr sdk.AccAddress) error { + store := ctx.KVStore(k.storeKey) + if store.Has(addr) == false { + return fmt.Errorf("key is nil") + } + bz := store.Get(addr) + var limit_per_addr types.LimitPerAddr + k.cdc.MustUnmarshal(bz, &limit_per_addr) + limit_per_addr.ReledegateCount += 1 + k.SetLimitPerAddr(ctx, addr, limit_per_addr) + return nil +} + // GetDelegateCount get the number of delegate tx for a given address func (k Keeper) GetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) (limit_per_addr types.LimitPerAddr) { store := ctx.KVStore(k.storeKey) diff --git a/x/tx-boundary/types/genesis.go b/x/tx-boundary/types/genesis.go index 427737e07..f690a7c9d 100644 --- a/x/tx-boundary/types/genesis.go +++ b/x/tx-boundary/types/genesis.go @@ -1,5 +1,7 @@ package types +import fmt "fmt" + var ( DefaultDelegateBoundary = Boundary{ TxLimit: 5, @@ -22,5 +24,8 @@ func DefaultGenesisState() *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func ValidateGenesis(data GenesisState) error { + if data.DelegateBoundary.BlocksPerGeneration <= 0 || data.RedelegateBoundary.BlocksPerGeneration <= 0 { + return fmt.Errorf("BlocksPerGeneration must greater than 0") + } return nil } From 8dbe0190a8865e300098b67a7a5f4b8dd3a3f88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Wed, 23 Aug 2023 14:06:17 +0700 Subject: [PATCH 10/14] register tx boundary store key --- app/keepers/keys.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 6126eb791..ad142811b 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -30,6 +30,7 @@ import ( ibchookstypes "github.com/notional-labs/centauri/v4/x/ibc-hooks/types" ratelimitmoduletypes "github.com/notional-labs/centauri/v4/x/ratelimit/types" transfermiddlewaretypes "github.com/notional-labs/centauri/v4/x/transfermiddleware/types" + txBoundaryTypes "github.com/notional-labs/centauri/v4/x/tx-boundary/types" consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" @@ -48,7 +49,7 @@ func (appKeepers *AppKeepers) GenerateKeys() { authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, icqtypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, wasm08types.StoreKey, - crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, alliancemoduletypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey, + crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, alliancemoduletypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey, txBoundaryTypes.StoreKey, ) // Define transient store keys From 5aa4160e9dad5033c9a23f65b6ee1b4776cbdd30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Thu, 24 Aug 2023 11:07:35 +0700 Subject: [PATCH 11/14] nit --- x/tx-boundary/client/cli/query.go | 2 +- x/tx-boundary/keeper/grpc_query.go | 4 ++-- x/tx-boundary/keeper/keeper.go | 2 +- x/tx-boundary/types/keys.go | 1 - x/tx-boundary/types/msg.go | 2 -- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/x/tx-boundary/client/cli/query.go b/x/tx-boundary/client/cli/query.go index 74ef00996..984b9fb9f 100644 --- a/x/tx-boundary/client/cli/query.go +++ b/x/tx-boundary/client/cli/query.go @@ -10,7 +10,7 @@ import ( "github.com/notional-labs/centauri/v4/x/tx-boundary/types" ) -// GetQueryCmd returns the cli query commands for the minting module. +// GetQueryCmd returns the cli query commands for the tx-boundary module. func GetQueryCmd() *cobra.Command { txboundaryQueryCmd := &cobra.Command{ Use: types.ModuleName, diff --git a/x/tx-boundary/keeper/grpc_query.go b/x/tx-boundary/keeper/grpc_query.go index c97ff9c6a..772ae2f5c 100644 --- a/x/tx-boundary/keeper/grpc_query.go +++ b/x/tx-boundary/keeper/grpc_query.go @@ -9,7 +9,7 @@ import ( var _ types.QueryServer = Keeper{} -// DelegateBoundary returns params of the mint module. +// DelegateBoundary returns delegate boundary of the tx-boundary module. func (k Keeper) DelegateBoundary(c context.Context, req *types.QueryDelegateBoundaryRequest) (*types.QueryDelegateBoundaryResponse, error) { ctx := sdk.UnwrapSDKContext(c) boundary := k.GetDelegateBoundary(ctx) @@ -17,7 +17,7 @@ func (k Keeper) DelegateBoundary(c context.Context, req *types.QueryDelegateBoun return &types.QueryDelegateBoundaryResponse{Boundary: boundary}, nil } -// DelegateBoundary returns params of the mint module. +// DelegateBoundary returns redelegate boundary of the tx-boundary module. func (k Keeper) RedelegateBoundary(c context.Context, _ *types.QueryRedelegateBoundaryRequest) (*types.QueryRedelegateBoundaryResponse, error) { ctx := sdk.UnwrapSDKContext(c) boundary := k.GetRedelegateBoundary(ctx) diff --git a/x/tx-boundary/keeper/keeper.go b/x/tx-boundary/keeper/keeper.go index dca036d1c..488b0dc04 100644 --- a/x/tx-boundary/keeper/keeper.go +++ b/x/tx-boundary/keeper/keeper.go @@ -31,7 +31,7 @@ func NewKeeper(cdc codec.Codec, storeKey storetypes.StoreKey, authority string) } } -// GetAuthority returns the x/mint module's authority. +// GetAuthority returns the x/tx-boundary module's authority. func (k Keeper) GetAuthority() string { return k.authority } diff --git a/x/tx-boundary/types/keys.go b/x/tx-boundary/types/keys.go index d5bcc1ab4..4d2cff8e8 100644 --- a/x/tx-boundary/types/keys.go +++ b/x/tx-boundary/types/keys.go @@ -8,7 +8,6 @@ const ( StoreKey = ModuleName ) -// MinterKey is the key to use for the keeper store. var ( // DelegateBoundaryKey is the key to use for the keeper store. DelegateBoundaryKey = []byte{0x00} diff --git a/x/tx-boundary/types/msg.go b/x/tx-boundary/types/msg.go index fc9676ba8..e927b957f 100644 --- a/x/tx-boundary/types/msg.go +++ b/x/tx-boundary/types/msg.go @@ -14,7 +14,6 @@ func (m MsgUpdateDelegateBoundary) Route() string { return sdk.MsgTypeURL(&m) } // Type Implements Msg. func (m MsgUpdateDelegateBoundary) Type() string { return sdk.MsgTypeURL(&m) } -// GetSigners returns the expected signers for a MsgMintAndAllocateExp . func (m MsgUpdateDelegateBoundary) GetSigners() []sdk.AccAddress { authorityAddr, err := sdk.AccAddressFromBech32(m.Authority) if err != nil { @@ -52,7 +51,6 @@ func (m MsgUpdateRedelegateBoundary) Route() string { return sdk.MsgTypeURL(&m) // Type Implements Msg. func (m MsgUpdateRedelegateBoundary) Type() string { return sdk.MsgTypeURL(&m) } -// GetSigners returns the expected signers for a MsgMintAndAllocateExp . func (m MsgUpdateRedelegateBoundary) GetSigners() []sdk.AccAddress { authorityAddr, err := sdk.AccAddressFromBech32(m.Authority) if err != nil { From 4ca8071f71db05780238694d21f523ff54b4c339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Thu, 24 Aug 2023 15:03:01 +0700 Subject: [PATCH 12/14] update proto and tests --- .../txboundary/v1beta1/boundary.proto | 2 +- x/tx-boundary/client/cli/tx.go | 4 +- x/tx-boundary/keeper/keeper.go | 20 ++- x/tx-boundary/keeper/keeper_test.go | 147 ++++++++++++++++++ x/tx-boundary/types/boundary.pb.go | 48 +++--- 5 files changed, 187 insertions(+), 34 deletions(-) create mode 100644 x/tx-boundary/keeper/keeper_test.go diff --git a/proto/centauri/txboundary/v1beta1/boundary.proto b/proto/centauri/txboundary/v1beta1/boundary.proto index c0b57b644..b1352c068 100644 --- a/proto/centauri/txboundary/v1beta1/boundary.proto +++ b/proto/centauri/txboundary/v1beta1/boundary.proto @@ -10,7 +10,7 @@ option go_package = "x/tx-boundary/types"; // Boundary defines the number of tx limit and block per tx generation time message Boundary { uint64 tx_limit = 1; - int64 blocks_per_generation = 2; + uint64 blocks_per_generation = 2; } // Boundary defines the number of delegate and redelegate per Addr diff --git a/x/tx-boundary/client/cli/tx.go b/x/tx-boundary/client/cli/tx.go index f6c3d69dd..e0899b12e 100644 --- a/x/tx-boundary/client/cli/tx.go +++ b/x/tx-boundary/client/cli/tx.go @@ -42,7 +42,7 @@ func GetCmdUpdateDelegateBoundary() *cobra.Command { return err } - block_per_generation, err := strconv.ParseInt(args[1], 10, 64) + block_per_generation, err := strconv.ParseUint(args[1], 10, 64) if err != nil { return err } @@ -77,7 +77,7 @@ func GetCmdUpdateRedelegateBoundary() *cobra.Command { return err } - block_per_generation, err := strconv.ParseInt(args[1], 10, 64) + block_per_generation, err := strconv.ParseUint(args[1], 10, 64) if err != nil { return err } diff --git a/x/tx-boundary/keeper/keeper.go b/x/tx-boundary/keeper/keeper.go index 488b0dc04..69b440ab3 100644 --- a/x/tx-boundary/keeper/keeper.go +++ b/x/tx-boundary/keeper/keeper.go @@ -41,15 +41,17 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } -// TODO: Duplicate fnc here // SetDelegateBoundary sets the delegate boundary. -func (k Keeper) SetDelegateBoundary(ctx sdk.Context, boundary types.Boundary) { +func (k Keeper) SetDelegateBoundary(ctx sdk.Context, boundary types.Boundary) error { store := ctx.KVStore(k.storeKey) + if boundary.BlocksPerGeneration == 0 { + return fmt.Errorf("BlocksPerGeneration must not be zero") + } bz := k.cdc.MustMarshal(&boundary) store.Set(types.DelegateBoundaryKey, bz) + return nil } -// TODO: Duplicate fnc here // GetDelegateBoundary sets the delegate boundary. func (k Keeper) GetDelegateBoundary(ctx sdk.Context) (boundary types.Boundary) { store := ctx.KVStore(k.storeKey) @@ -63,10 +65,14 @@ func (k Keeper) GetDelegateBoundary(ctx sdk.Context) (boundary types.Boundary) { } // SetRedelegateBoundary sets the delegate boundary. -func (k Keeper) SetRedelegateBoundary(ctx sdk.Context, boundary types.Boundary) { +func (k Keeper) SetRedelegateBoundary(ctx sdk.Context, boundary types.Boundary) error { store := ctx.KVStore(k.storeKey) + if boundary.BlocksPerGeneration == 0 { + return fmt.Errorf("BlocksPerGeneration must not be zero") + } bz := k.cdc.MustMarshal(&boundary) store.Set(types.RedelegateBoundaryKey, bz) + return nil } // GetRedelegateBoundary sets the delegate boundary. @@ -135,10 +141,10 @@ func (k Keeper) UpdateLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) { return } boundary := k.GetDelegateBoundary(ctx) - if limit_per_addr.LatestUpdateBlock+boundary.BlocksPerGeneration >= ctx.BlockHeight() { + if limit_per_addr.LatestUpdateBlock+int64(boundary.BlocksPerGeneration) >= ctx.BlockHeight() { // Calculate the generated tx number from the duration between latest update block and curent block height - var generatedTx int64 - duration := limit_per_addr.LatestUpdateBlock + boundary.BlocksPerGeneration - ctx.BlockHeight() + var generatedTx uint64 + duration := uint64(limit_per_addr.LatestUpdateBlock) + boundary.BlocksPerGeneration - uint64(ctx.BlockHeight()) if duration/boundary.BlocksPerGeneration > 5 { generatedTx = 5 } else { diff --git a/x/tx-boundary/keeper/keeper_test.go b/x/tx-boundary/keeper/keeper_test.go new file mode 100644 index 000000000..ef1ab015e --- /dev/null +++ b/x/tx-boundary/keeper/keeper_test.go @@ -0,0 +1,147 @@ +package keeper_test + +import ( + "testing" + "time" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + + "github.com/notional-labs/centauri/v4/app" + "github.com/notional-labs/centauri/v4/app/helpers" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + // querier sdk.Querier + app *app.CentauriApp +} + +func (suite *KeeperTestSuite) SetupTest() { + suite.app = helpers.SetupCentauriAppWithValSet(suite.T()) + suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "centauri-1", Time: time.Now().UTC()}) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +var ( + defaultBoundary = types.Boundary{ + TxLimit: 5, + BlocksPerGeneration: 5, + } + newBoundary = types.Boundary{ + TxLimit: 10, + BlocksPerGeneration: 5, + } + failBoundary = types.Boundary{ + TxLimit: 10, + BlocksPerGeneration: 0, + } +) + +func (suite *KeeperTestSuite) TestSetDelegateBoundary() { + for _, tc := range []struct { + desc string + expectedBoundary types.Boundary + malleate func() error + shouldErr bool + expectedErr string + }{ + { + desc: "Case success", + expectedBoundary: newBoundary, + malleate: func() error { + return suite.app.TxBoundaryKeepper.SetDelegateBoundary(suite.ctx, newBoundary) + }, + shouldErr: false, + }, + { + desc: "Case fail", + expectedBoundary: failBoundary, + malleate: func() error { + return suite.app.TxBoundaryKeepper.SetDelegateBoundary(suite.ctx, failBoundary) + }, + shouldErr: true, + expectedErr: "BlocksPerGeneration must not be zero", + }, + { + desc: "Do no thing", + expectedBoundary: defaultBoundary, + malleate: func() error { + return nil + }, + shouldErr: false, + }, + } { + tc := tc + suite.Run(tc.desc, func() { + suite.SetupTest() + err := tc.malleate() + if !tc.shouldErr { + res := suite.app.TxBoundaryKeepper.GetDelegateBoundary(suite.ctx) + suite.Equal(res, tc.expectedBoundary) + } else { + suite.Equal(err.Error(), tc.expectedErr) + } + }) + } +} + +func (suite *KeeperTestSuite) TestSetRedelegateBoundary() { + suite.app.TxBoundaryKeepper.SetRedelegateBoundary(suite.ctx, types.Boundary{ + TxLimit: 10, + BlocksPerGeneration: 5, + }) + + for _, tc := range []struct { + desc string + expectedBoundary types.Boundary + malleate func() error + shouldErr bool + expectedErr string + }{ + { + desc: "Case success", + expectedBoundary: newBoundary, + malleate: func() error { + return suite.app.TxBoundaryKeepper.SetRedelegateBoundary(suite.ctx, newBoundary) + }, + shouldErr: false, + }, + { + desc: "Success", + expectedBoundary: failBoundary, + malleate: func() error { + return suite.app.TxBoundaryKeepper.SetRedelegateBoundary(suite.ctx, failBoundary) + }, + shouldErr: true, + expectedErr: "BlocksPerGeneration must not be zero", + }, + { + desc: "Do no thing", + expectedBoundary: defaultBoundary, + malleate: func() error { + return nil + }, + shouldErr: false, + }, + } { + tc := tc + suite.Run(tc.desc, func() { + suite.SetupTest() + err := tc.malleate() + if !tc.shouldErr { + res := suite.app.TxBoundaryKeepper.GetRedelegateBoundary(suite.ctx) + suite.Equal(res, tc.expectedBoundary) + } else { + suite.Equal(err.Error(), tc.expectedErr) + } + }) + } +} diff --git a/x/tx-boundary/types/boundary.pb.go b/x/tx-boundary/types/boundary.pb.go index 675954d58..8bce1b9f3 100644 --- a/x/tx-boundary/types/boundary.pb.go +++ b/x/tx-boundary/types/boundary.pb.go @@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Boundary defines the number of tx limit and block per tx generation time type Boundary struct { TxLimit uint64 `protobuf:"varint,1,opt,name=tx_limit,json=txLimit,proto3" json:"tx_limit,omitempty"` - BlocksPerGeneration int64 `protobuf:"varint,2,opt,name=blocks_per_generation,json=blocksPerGeneration,proto3" json:"blocks_per_generation,omitempty"` + BlocksPerGeneration uint64 `protobuf:"varint,2,opt,name=blocks_per_generation,json=blocksPerGeneration,proto3" json:"blocks_per_generation,omitempty"` } func (m *Boundary) Reset() { *m = Boundary{} } @@ -71,7 +71,7 @@ func (m *Boundary) GetTxLimit() uint64 { return 0 } -func (m *Boundary) GetBlocksPerGeneration() int64 { +func (m *Boundary) GetBlocksPerGeneration() uint64 { if m != nil { return m.BlocksPerGeneration } @@ -149,27 +149,27 @@ func init() { } var fileDescriptor_668b8d6584310f2c = []byte{ - // 318 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0xcd, 0x4a, 0xf3, 0x40, - 0x14, 0x86, 0x3b, 0xed, 0xc7, 0x67, 0x19, 0xfc, 0x4d, 0x15, 0x6a, 0x85, 0xb1, 0x14, 0x84, 0x2a, - 0x34, 0x43, 0xf5, 0x0a, 0xac, 0x0b, 0x37, 0x2e, 0x4a, 0xc1, 0x85, 0x6e, 0xc2, 0xa4, 0x73, 0x0c, - 0xc1, 0x34, 0x13, 0x26, 0x67, 0x24, 0xbd, 0x8b, 0x5e, 0x96, 0xcb, 0x2e, 0x5d, 0x4a, 0x7b, 0x23, - 0x92, 0x99, 0xa6, 0x15, 0x77, 0x39, 0xef, 0xf3, 0x1c, 0xde, 0x43, 0x86, 0xde, 0x4c, 0x21, 0x45, - 0x61, 0x74, 0xcc, 0xb1, 0x08, 0x95, 0x49, 0xa5, 0xd0, 0x73, 0xfe, 0x31, 0x0c, 0x01, 0xc5, 0x90, - 0x57, 0x81, 0x9f, 0x69, 0x85, 0xca, 0xbb, 0xa8, 0x5c, 0x7f, 0xe7, 0xfa, 0x1b, 0xb7, 0x73, 0x1a, - 0xa9, 0x48, 0x59, 0x8f, 0x97, 0x5f, 0x6e, 0xa5, 0xc3, 0x22, 0xa5, 0xa2, 0x04, 0xb8, 0x9d, 0x42, - 0xf3, 0xc6, 0xa5, 0xd1, 0x02, 0x63, 0x95, 0x6e, 0xf8, 0xe5, 0x5f, 0x8e, 0xf1, 0x0c, 0x72, 0x14, - 0xb3, 0xcc, 0x09, 0xbd, 0x17, 0xda, 0x1c, 0x6d, 0xaa, 0xbc, 0x73, 0xda, 0xc4, 0x22, 0x48, 0xe2, - 0x59, 0x8c, 0x6d, 0xd2, 0x25, 0xfd, 0x7f, 0x93, 0x3d, 0x2c, 0x9e, 0xca, 0xd1, 0xbb, 0xa5, 0x67, - 0x61, 0xa2, 0xa6, 0xef, 0x79, 0x90, 0x81, 0x0e, 0x22, 0x48, 0xc1, 0xd5, 0xb4, 0xeb, 0x5d, 0xd2, - 0x6f, 0x4c, 0x5a, 0x0e, 0x8e, 0x41, 0x3f, 0x6e, 0x51, 0x6f, 0x41, 0xe8, 0xbe, 0xdd, 0x1e, 0x83, - 0xbe, 0x97, 0x52, 0x7b, 0x57, 0xf4, 0x50, 0x42, 0x02, 0x91, 0x40, 0x08, 0xa6, 0xca, 0xa4, 0x55, - 0xcb, 0x41, 0x95, 0x3e, 0x94, 0xa1, 0x77, 0x4d, 0x8f, 0x35, 0x24, 0x20, 0x7f, 0x8b, 0x75, 0x2b, - 0x1e, 0xed, 0x72, 0xa7, 0xfa, 0xb4, 0x95, 0x08, 0x84, 0x1c, 0x03, 0x93, 0xc9, 0xd2, 0xb6, 0x77, - 0xb4, 0x1b, 0xf6, 0xa8, 0x13, 0x87, 0x9e, 0x2d, 0x19, 0x95, 0x60, 0x34, 0xf8, 0x5c, 0x31, 0xb2, - 0x5c, 0x31, 0xf2, 0xbd, 0x62, 0x64, 0xb1, 0x66, 0xb5, 0xe5, 0x9a, 0xd5, 0xbe, 0xd6, 0xac, 0xf6, - 0xda, 0x2a, 0x38, 0x16, 0x83, 0xed, 0x0b, 0xe1, 0x3c, 0x83, 0x3c, 0xfc, 0x6f, 0xff, 0xd1, 0xdd, - 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x16, 0x56, 0x93, 0xc5, 0x01, 0x00, 0x00, + // 315 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0x4f, 0x4b, 0xc3, 0x30, + 0x18, 0xc6, 0x17, 0x27, 0x3a, 0x82, 0x7f, 0x3b, 0x85, 0x39, 0x21, 0x8e, 0x81, 0x30, 0x85, 0x35, + 0x4c, 0x3f, 0x81, 0xf3, 0xe0, 0xc5, 0xc3, 0x18, 0x78, 0xd0, 0x4b, 0x49, 0x97, 0xd7, 0x52, 0xec, + 0x9a, 0x92, 0xbe, 0x91, 0xee, 0x5b, 0xec, 0x63, 0x79, 0xdc, 0xd1, 0xa3, 0x6c, 0x5f, 0x44, 0x9a, + 0xac, 0x9b, 0x78, 0xcb, 0xfb, 0xfc, 0x7e, 0x2f, 0x4f, 0x48, 0xe8, 0xed, 0x04, 0x52, 0x14, 0x46, + 0xc7, 0x1c, 0x8b, 0x50, 0x99, 0x54, 0x0a, 0x3d, 0xe3, 0x9f, 0x83, 0x10, 0x50, 0x0c, 0x78, 0x15, + 0xf8, 0x99, 0x56, 0xa8, 0xbc, 0xcb, 0xca, 0xf5, 0xb7, 0xae, 0xbf, 0x76, 0xdb, 0x67, 0x91, 0x8a, + 0x94, 0xf5, 0x78, 0x79, 0x72, 0x2b, 0x6d, 0x16, 0x29, 0x15, 0x25, 0xc0, 0xed, 0x14, 0x9a, 0x77, + 0x2e, 0x8d, 0x16, 0x18, 0xab, 0x74, 0xcd, 0xaf, 0xfe, 0x73, 0x8c, 0xa7, 0x90, 0xa3, 0x98, 0x66, + 0x4e, 0xe8, 0xbe, 0xd2, 0xc6, 0x70, 0x5d, 0xe5, 0x5d, 0xd0, 0x06, 0x16, 0x41, 0x12, 0x4f, 0x63, + 0x6c, 0x91, 0x0e, 0xe9, 0xed, 0x8e, 0xf7, 0xb1, 0x78, 0x2e, 0x47, 0xef, 0x8e, 0x9e, 0x87, 0x89, + 0x9a, 0x7c, 0xe4, 0x41, 0x06, 0x3a, 0x88, 0x20, 0x05, 0x57, 0xd3, 0xda, 0xb1, 0x5e, 0xd3, 0xc1, + 0x11, 0xe8, 0xa7, 0x0d, 0xea, 0xce, 0x09, 0x3d, 0xb0, 0xdb, 0x23, 0xd0, 0x0f, 0x52, 0x6a, 0xef, + 0x9a, 0x1e, 0x49, 0x48, 0x20, 0x12, 0x08, 0xc1, 0x44, 0x99, 0xb4, 0x6a, 0x39, 0xac, 0xd2, 0xc7, + 0x32, 0xf4, 0x6e, 0xe8, 0x89, 0x86, 0x04, 0xe4, 0x5f, 0xd1, 0xd5, 0x1c, 0x6f, 0x73, 0xa7, 0xfa, + 0xb4, 0x99, 0x08, 0x84, 0x1c, 0x03, 0x93, 0xc9, 0xd2, 0xb6, 0xf7, 0x68, 0xd5, 0x3b, 0xa4, 0x57, + 0x1f, 0x9f, 0x3a, 0xf4, 0x62, 0xc9, 0xb0, 0x04, 0xc3, 0xfe, 0xd7, 0x92, 0x91, 0xc5, 0x92, 0x91, + 0x9f, 0x25, 0x23, 0xf3, 0x15, 0xab, 0x2d, 0x56, 0xac, 0xf6, 0xbd, 0x62, 0xb5, 0xb7, 0x66, 0xc1, + 0xb1, 0xe8, 0x6f, 0x7e, 0x08, 0x67, 0x19, 0xe4, 0xe1, 0x9e, 0x7d, 0xa3, 0xfb, 0xdf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x22, 0x22, 0xfc, 0xbe, 0xc5, 0x01, 0x00, 0x00, } func (m *Boundary) Marshal() (dAtA []byte, err error) { @@ -355,7 +355,7 @@ func (m *Boundary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.BlocksPerGeneration |= int64(b&0x7F) << shift + m.BlocksPerGeneration |= uint64(b&0x7F) << shift if b < 0x80 { break } From a3f631eec8e36c34600eafb9de3ac03718bd588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Thu, 24 Aug 2023 18:37:22 +0700 Subject: [PATCH 13/14] move stakingmsg ante logic to tx-boundary module and add validAuthz --- app/ante/ante.go | 3 +- .../tx-boundary/ante/decorate.go | 52 ++++++++++++++----- 2 files changed, 41 insertions(+), 14 deletions(-) rename app/ante/custom_ante.go => x/tx-boundary/ante/decorate.go (67%) diff --git a/app/ante/ante.go b/app/ante/ante.go index 6e414ba99..417f68b58 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -10,6 +10,7 @@ import ( ante "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/signing" tfmwKeeper "github.com/notional-labs/centauri/v4/x/transfermiddleware/keeper" + txBoundaryAnte "github.com/notional-labs/centauri/v4/x/tx-boundary/ante" txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" ) @@ -32,7 +33,7 @@ func NewAnteHandler( ante.NewValidateMemoDecorator(ak), ante.NewConsumeGasForTxSizeDecorator(ak), NewIBCPermissionDecorator(codec, tfmwKeeper), - NewStakingPermissionDecorator(codec, txBoundaryKeeper), + txBoundaryAnte.NewStakingPermissionDecorator(codec, txBoundaryKeeper), ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(ak), ante.NewSigGasConsumeDecorator(ak, sigGasConsumer), diff --git a/app/ante/custom_ante.go b/x/tx-boundary/ante/decorate.go similarity index 67% rename from app/ante/custom_ante.go rename to x/tx-boundary/ante/decorate.go index 8fadd07aa..d6ba1e907 100644 --- a/app/ante/custom_ante.go +++ b/x/tx-boundary/ante/decorate.go @@ -3,9 +3,11 @@ package ante import ( "fmt" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" txBoundaryKeeper "github.com/notional-labs/centauri/v4/x/tx-boundary/keeper" ) @@ -32,7 +34,7 @@ func (g StakingPermissionDecorator) AnteHandle( } msgs := tx.GetMsgs() - if err = g.ValidateStakingMsg(ctx, msgs); err != nil { + if err = g.ValidateStakingMsgs(ctx, msgs); err != nil { return ctx, err } @@ -40,20 +42,30 @@ func (g StakingPermissionDecorator) AnteHandle( } // ValidateStakingMsg validate -func (g StakingPermissionDecorator) ValidateStakingMsg(ctx sdk.Context, msgs []sdk.Msg) error { +func (g StakingPermissionDecorator) ValidateStakingMsgs(ctx sdk.Context, msgs []sdk.Msg) error { for _, m := range msgs { - switch msg := m.(type) { - case *stakingtypes.MsgDelegate: - if err := g.validDelegateMsg(ctx, msg); err != nil { - return err - } - case *stakingtypes.MsgBeginRedelegate: - if err := g.validRedelegateMsg(ctx, msg); err != nil { - return err - } - default: - return nil + g.ValidateStakingMsg(ctx, m) + } + return nil +} + +func (g StakingPermissionDecorator) ValidateStakingMsg(ctx sdk.Context, msg sdk.Msg) error { + switch msg := msg.(type) { + + case *stakingtypes.MsgDelegate: + if err := g.validDelegateMsg(ctx, msg); err != nil { + return err + } + case *stakingtypes.MsgBeginRedelegate: + if err := g.validRedelegateMsg(ctx, msg); err != nil { + return err } + case *authz.MsgExec: + if err := g.validAuthz(ctx, msg); err != nil { + return err + } + default: + return nil } return nil } @@ -82,3 +94,17 @@ func (g StakingPermissionDecorator) validRedelegateMsg(ctx sdk.Context, msg *sta g.txBoundary.IncrementRedelegateCount(ctx, sdk.AccAddress(msg.DelegatorAddress)) return nil } + +func (g StakingPermissionDecorator) validAuthz(ctx sdk.Context, execMsg *authz.MsgExec) error { + for _, v := range execMsg.Msgs { + var innerMsg sdk.Msg + if err := g.cdc.UnpackAny(v, &innerMsg); err != nil { + return errorsmod.Wrap(err, "cannot unmarshal authz exec msgs") + } + if err := g.ValidateStakingMsg(ctx, innerMsg); err != nil { + return err + } + } + + return nil +} From bd29fcab063cac0f7a1354adaad43ee669c34882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Fri, 25 Aug 2023 16:34:44 +0700 Subject: [PATCH 14/14] add ante test --- app/helpers/test_helpers.go | 51 +++++++ x/mint/simulation/decoder_test.go | 1 - x/tx-boundary/ante/antetest/ante_test.go | 121 +++++++++++++++++ .../ante/antetest/ante_test_setup.go | 127 ++++++++++++++++++ x/tx-boundary/ante/decorate.go | 29 ++-- x/tx-boundary/keeper/keeper.go | 22 ++- 6 files changed, 335 insertions(+), 16 deletions(-) create mode 100644 x/tx-boundary/ante/antetest/ante_test.go create mode 100644 x/tx-boundary/ante/antetest/ante_test_setup.go diff --git a/app/helpers/test_helpers.go b/app/helpers/test_helpers.go index 5c5db303f..aad2aca2e 100644 --- a/app/helpers/test_helpers.go +++ b/app/helpers/test_helpers.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "cosmossdk.io/math" "github.com/CosmWasm/wasmd/x/wasm" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" dbm "github.com/cometbft/cometbft-db" @@ -15,11 +16,14 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" tmtypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/baseapp" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/ibc-go/v7/testing/mock" centauri "github.com/notional-labs/centauri/v4/app" "github.com/stretchr/testify/require" @@ -171,3 +175,50 @@ func SetupCentauriAppWithValSet(t *testing.T) *centauri.CentauriApp { centauriApp := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, "notional", balance) return centauriApp } + +func SetupCentauriAppWithValSetWithGenAccout(t *testing.T) (*centauri.CentauriApp, sdk.AccAddress, []stakingtypes.Validator) { + t.Helper() + // generate validator private/public key + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(t, err) + + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + // generate genesis account + senderPrivKey := secp256k1.GenPrivKey() + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + amount, ok := sdk.NewIntFromString("10000000000000000000") + require.True(t, ok) + + balance := banktypes.Balance{ + Address: acc.GetAddress().String(), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), + } + + validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) + for _, val := range valSet.Validators { + pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey) + pkAny, _ := codectypes.NewAnyWithValue(pk) + + validator := stakingtypes.Validator{ + OperatorAddress: sdk.ValAddress(val.Address).String(), + ConsensusPubkey: pkAny, + Jailed: false, + Status: stakingtypes.Bonded, + Tokens: sdk.DefaultPowerReduction, + DelegatorShares: math.LegacyOneDec(), + Description: stakingtypes.Description{}, + UnbondingHeight: int64(0), + UnbondingTime: time.Unix(0, 0).UTC(), + Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()), + MinSelfDelegation: math.ZeroInt(), + } + validators = append(validators, validator) + } + centauriApp := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, "notional", balance) + + return centauriApp, acc.GetAddress(), validators +} diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 1a05a4862..0f733f44a 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -33,7 +33,6 @@ func TestDecodeStore(t *testing.T) { } for i, tt := range tests { i, tt := i, tt - fmt.Println("hehe") t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: diff --git a/x/tx-boundary/ante/antetest/ante_test.go b/x/tx-boundary/ante/antetest/ante_test.go new file mode 100644 index 000000000..86f22435c --- /dev/null +++ b/x/tx-boundary/ante/antetest/ante_test.go @@ -0,0 +1,121 @@ +package antetest + +import ( + "testing" + + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + txboundaryAnte "github.com/notional-labs/centauri/v4/x/tx-boundary/ante" + "github.com/notional-labs/centauri/v4/x/tx-boundary/types" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +func TestAnteTestSuite(t *testing.T) { + suite.Run(t, new(AnteTestSuite)) +} + +func (s *AnteTestSuite) TestStakingAnte() { + _, _, addr1 := testdata.KeyTestPubAddr() + delegateMsg := stakingtypes.NewMsgDelegate(s.delegator, s.validators[0].GetOperator(), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000))) + msgDelegateAny, err := cdctypes.NewAnyWithValue(delegateMsg) + addr2 := s.delegator + + require.NoError(s.T(), err) + for _, tc := range []struct { + desc string + txMsg sdk.Msg + malleate func() error + expErr bool + expErrStr string + }{ + { + desc: "Case delegate success", + txMsg: stakingtypes.NewMsgDelegate(s.delegator, s.validators[0].GetOperator(), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000))), + malleate: func() error { + return nil + }, + expErr: false, + }, + { + desc: "Case redelegate success", + txMsg: stakingtypes.NewMsgBeginRedelegate(s.delegator, s.validators[0].GetOperator(), s.newvalidators[0].GetOperator(), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000))), + malleate: func() error { + return nil + }, + expErr: false, + }, + { + desc: "Case authz success", + txMsg: &authz.MsgExec{Grantee: addr1.String(), Msgs: []*cdctypes.Any{msgDelegateAny}}, + malleate: func() error { + return nil + }, + expErr: false, + }, + { + desc: "Case delegate failed", + txMsg: stakingtypes.NewMsgDelegate(s.delegator, s.validators[0].GetOperator(), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000))), + malleate: func() error { + s.app.TxBoundaryKeepper.SetLimitPerAddr(s.ctx, addr2, types.LimitPerAddr{ + DelegateCount: 5, + ReledegateCount: 5, + LatestUpdateBlock: s.ctx.BlockHeight(), + }) + return nil + }, + expErr: true, + }, + { + desc: "Case redelegate failed", + txMsg: stakingtypes.NewMsgBeginRedelegate(s.delegator, s.validators[0].GetOperator(), s.newvalidators[0].GetOperator(), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000))), + malleate: func() error { + s.app.TxBoundaryKeepper.SetLimitPerAddr(s.ctx, addr2, types.LimitPerAddr{ + DelegateCount: 5, + ReledegateCount: 5, + LatestUpdateBlock: s.ctx.BlockHeight(), + }) + return nil + }, + expErr: true, + }, + { + desc: "Case authz failed", + txMsg: &authz.MsgExec{Grantee: addr1.String(), Msgs: []*cdctypes.Any{msgDelegateAny}}, + malleate: func() error { + s.app.TxBoundaryKeepper.SetLimitPerAddr(s.ctx, addr2, types.LimitPerAddr{ + DelegateCount: 5, + ReledegateCount: 5, + LatestUpdateBlock: s.ctx.BlockHeight(), + }) + return nil + }, + expErr: true, + }, + } { + tc := tc + s.SetupTest() + tc.malleate() + s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder() + priv1, _, _ := testdata.KeyTestPubAddr() + privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} + + mfd := txboundaryAnte.NewStakingPermissionDecorator(s.app.AppCodec(), s.app.TxBoundaryKeepper) + antehandler := sdk.ChainAnteDecorators(mfd) + s.Require().NoError(s.txBuilder.SetMsgs(tc.txMsg)) + + tx, err := s.CreateTestTx(privs, accNums, accSeqs, s.ctx.ChainID()) + s.Require().NoError(err) + _, err = antehandler(s.ctx, tx, false) + if !tc.expErr { + s.Require().NoError(err) + } else { + s.Require().Error(err) + } + } + +} diff --git a/x/tx-boundary/ante/antetest/ante_test_setup.go b/x/tx-boundary/ante/antetest/ante_test_setup.go new file mode 100644 index 000000000..33ef2fb6c --- /dev/null +++ b/x/tx-boundary/ante/antetest/ante_test_setup.go @@ -0,0 +1,127 @@ +package antetest + +import ( + "time" + + "cosmossdk.io/math" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmtypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/ibc-go/v7/testing/mock" + "github.com/notional-labs/centauri/v4/app" + "github.com/notional-labs/centauri/v4/app/helpers" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +var BaseBalance = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000000))) + +type AnteTestSuite struct { + suite.Suite + + ctx sdk.Context + // querier sdk.Querier + app *app.CentauriApp + clientCtx client.Context + txBuilder client.TxBuilder + delegator sdk.AccAddress + validators []stakingtypes.Validator + newvalidators []stakingtypes.Validator +} + +func (suite *AnteTestSuite) SetupTest() { + suite.app, suite.delegator, suite.validators = helpers.SetupCentauriAppWithValSetWithGenAccout(suite.T()) + suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "centauri-1", Time: time.Now().UTC()}) + app.FundAccount(suite.app.BankKeeper, suite.ctx, sdk.AccAddress(suite.delegator), BaseBalance) + + encodingConfig := app.MakeEncodingConfig() + encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) + testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry) + + privVal := mock.NewPV() + pubKey, err := privVal.GetPubKey() + require.NoError(suite.T(), err) + // create validator set with single validator + validator := tmtypes.NewValidator(pubKey, 1) + valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) + + validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) + for _, val := range valSet.Validators { + pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey) + pkAny, _ := codectypes.NewAnyWithValue(pk) + validator := stakingtypes.Validator{ + OperatorAddress: sdk.ValAddress(val.Address).String(), + ConsensusPubkey: pkAny, + Jailed: false, + Status: stakingtypes.Bonded, + Tokens: sdk.DefaultPowerReduction, + DelegatorShares: math.LegacyOneDec(), + Description: stakingtypes.Description{}, + UnbondingHeight: int64(0), + UnbondingTime: time.Unix(0, 0).UTC(), + Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()), + MinSelfDelegation: math.ZeroInt(), + } + validators = append(validators, validator) + } + suite.newvalidators = validators + + suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) +} + +func (s *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) { + var sigsV2 []signing.SignatureV2 + for i, priv := range privs { + sigV2 := signing.SignatureV2{ + PubKey: priv.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), + Signature: nil, + }, + Sequence: accSeqs[i], + } + + sigsV2 = append(sigsV2, sigV2) + } + + if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { + return nil, err + } + + sigsV2 = []signing.SignatureV2{} + for i, priv := range privs { + signerData := xauthsigning.SignerData{ + ChainID: chainID, + AccountNumber: accNums[i], + Sequence: accSeqs[i], + } + sigV2, err := tx.SignWithPrivKey( + s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), + signerData, + s.txBuilder, + priv, + s.clientCtx.TxConfig, + accSeqs[i], + ) + if err != nil { + return nil, err + } + + sigsV2 = append(sigsV2, sigV2) + } + + if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { + return nil, err + } + + return s.txBuilder.GetTx(), nil +} diff --git a/x/tx-boundary/ante/decorate.go b/x/tx-boundary/ante/decorate.go index d6ba1e907..8bfec5a8f 100644 --- a/x/tx-boundary/ante/decorate.go +++ b/x/tx-boundary/ante/decorate.go @@ -44,7 +44,10 @@ func (g StakingPermissionDecorator) AnteHandle( // ValidateStakingMsg validate func (g StakingPermissionDecorator) ValidateStakingMsgs(ctx sdk.Context, msgs []sdk.Msg) error { for _, m := range msgs { - g.ValidateStakingMsg(ctx, m) + err := g.ValidateStakingMsg(ctx, m) + if err != nil { + return err + } } return nil } @@ -72,26 +75,35 @@ func (g StakingPermissionDecorator) ValidateStakingMsg(ctx sdk.Context, msg sdk. func (g StakingPermissionDecorator) validDelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgDelegate) error { boundary := g.txBoundary.GetDelegateBoundary(ctx) - g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) + delegator, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) + if err != nil { + return err + } + g.txBoundary.UpdateLimitPerAddr(ctx, delegator) + if boundary.TxLimit == 0 { return nil - } else if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).DelegateCount > boundary.TxLimit { + } else if g.txBoundary.GetLimitPerAddr(ctx, delegator).DelegateCount >= boundary.TxLimit { return fmt.Errorf("delegate tx denied, excess tx limit") } - g.txBoundary.IncrementDelegateCount(ctx, sdk.AccAddress(msg.DelegatorAddress)) - + g.txBoundary.IncrementDelegateCount(ctx, delegator) return nil } func (g StakingPermissionDecorator) validRedelegateMsg(ctx sdk.Context, msg *stakingtypes.MsgBeginRedelegate) error { boundary := g.txBoundary.GetRedelegateBoundary(ctx) - g.txBoundary.UpdateLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)) + delegator, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) + if err != nil { + return err + } + + g.txBoundary.UpdateLimitPerAddr(ctx, delegator) if boundary.TxLimit == 0 { return nil - } else if g.txBoundary.GetLimitPerAddr(ctx, sdk.AccAddress(msg.DelegatorAddress)).ReledegateCount > boundary.TxLimit { + } else if g.txBoundary.GetLimitPerAddr(ctx, delegator).ReledegateCount >= boundary.TxLimit { return fmt.Errorf("redelegate tx denied, excess tx limit") } - g.txBoundary.IncrementRedelegateCount(ctx, sdk.AccAddress(msg.DelegatorAddress)) + g.txBoundary.IncrementRedelegateCount(ctx, delegator) return nil } @@ -105,6 +117,5 @@ func (g StakingPermissionDecorator) validAuthz(ctx sdk.Context, execMsg *authz.M return err } } - return nil } diff --git a/x/tx-boundary/keeper/keeper.go b/x/tx-boundary/keeper/keeper.go index 69b440ab3..135ef46a9 100644 --- a/x/tx-boundary/keeper/keeper.go +++ b/x/tx-boundary/keeper/keeper.go @@ -94,30 +94,40 @@ func (k Keeper) SetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress, limit_per_ store.Set(addr, bz) } -func (k Keeper) IncrementDelegateCount(ctx sdk.Context, addr sdk.AccAddress) error { +func (k Keeper) IncrementDelegateCount(ctx sdk.Context, addr sdk.AccAddress) { store := ctx.KVStore(k.storeKey) if store.Has(addr) == false { - return fmt.Errorf("key is nil") + k.SetLimitPerAddr(ctx, addr, types.LimitPerAddr{ + DelegateCount: 1, + ReledegateCount: 0, + LatestUpdateBlock: ctx.BlockHeight(), + }) + return } bz := store.Get(addr) var limit_per_addr types.LimitPerAddr k.cdc.MustUnmarshal(bz, &limit_per_addr) limit_per_addr.DelegateCount += 1 k.SetLimitPerAddr(ctx, addr, limit_per_addr) - return nil + return } -func (k Keeper) IncrementRedelegateCount(ctx sdk.Context, addr sdk.AccAddress) error { +func (k Keeper) IncrementRedelegateCount(ctx sdk.Context, addr sdk.AccAddress) { store := ctx.KVStore(k.storeKey) if store.Has(addr) == false { - return fmt.Errorf("key is nil") + k.SetLimitPerAddr(ctx, addr, types.LimitPerAddr{ + DelegateCount: 0, + ReledegateCount: 1, + LatestUpdateBlock: ctx.BlockHeight(), + }) + return } bz := store.Get(addr) var limit_per_addr types.LimitPerAddr k.cdc.MustUnmarshal(bz, &limit_per_addr) limit_per_addr.ReledegateCount += 1 k.SetLimitPerAddr(ctx, addr, limit_per_addr) - return nil + return } // GetDelegateCount get the number of delegate tx for a given address