diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8ef93a3..0d0b803 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 + submodules: true - name: Prepare Release Variables id: vars @@ -30,6 +31,8 @@ jobs: - name: Issue Release Assets uses: ignite/cli/actions/cli@main if: ${{ steps.vars.outputs.should_release == 'true' }} + env: + GOFLAGS: "-buildvcs=false" with: args: chain build --release --release.prefix ${{ steps.vars.outputs.tarball_prefix }} -t linux:amd64 -t darwin:amd64 -t darwin:arm64 diff --git a/api/sourcehub/tier/v1beta1/lockup.pulsar.go b/api/sourcehub/tier/v1beta1/lockup.pulsar.go index 31c86c6..faa6994 100644 --- a/api/sourcehub/tier/v1beta1/lockup.pulsar.go +++ b/api/sourcehub/tier/v1beta1/lockup.pulsar.go @@ -17,6 +17,7 @@ import ( var ( md_Lockup protoreflect.MessageDescriptor + fd_Lockup_delegator_address protoreflect.FieldDescriptor fd_Lockup_validator_address protoreflect.FieldDescriptor fd_Lockup_amount protoreflect.FieldDescriptor fd_Lockup_creation_height protoreflect.FieldDescriptor @@ -27,6 +28,7 @@ var ( func init() { file_sourcehub_tier_v1beta1_lockup_proto_init() md_Lockup = File_sourcehub_tier_v1beta1_lockup_proto.Messages().ByName("Lockup") + fd_Lockup_delegator_address = md_Lockup.Fields().ByName("delegator_address") fd_Lockup_validator_address = md_Lockup.Fields().ByName("validator_address") fd_Lockup_amount = md_Lockup.Fields().ByName("amount") fd_Lockup_creation_height = md_Lockup.Fields().ByName("creation_height") @@ -99,6 +101,12 @@ func (x *fastReflection_Lockup) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_Lockup) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.DelegatorAddress != "" { + value := protoreflect.ValueOfString(x.DelegatorAddress) + if !f(fd_Lockup_delegator_address, value) { + return + } + } if x.ValidatorAddress != "" { value := protoreflect.ValueOfString(x.ValidatorAddress) if !f(fd_Lockup_validator_address, value) { @@ -144,6 +152,8 @@ func (x *fastReflection_Lockup) Range(f func(protoreflect.FieldDescriptor, proto // a repeated field is populated if it is non-empty. func (x *fastReflection_Lockup) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + return x.DelegatorAddress != "" case "sourcehub.tier.v1beta1.Lockup.validator_address": return x.ValidatorAddress != "" case "sourcehub.tier.v1beta1.Lockup.amount": @@ -170,6 +180,8 @@ func (x *fastReflection_Lockup) Has(fd protoreflect.FieldDescriptor) bool { // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Lockup) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + x.DelegatorAddress = "" case "sourcehub.tier.v1beta1.Lockup.validator_address": x.ValidatorAddress = "" case "sourcehub.tier.v1beta1.Lockup.amount": @@ -196,6 +208,9 @@ func (x *fastReflection_Lockup) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_Lockup) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + value := x.DelegatorAddress + return protoreflect.ValueOfString(value) case "sourcehub.tier.v1beta1.Lockup.validator_address": value := x.ValidatorAddress return protoreflect.ValueOfString(value) @@ -231,6 +246,8 @@ func (x *fastReflection_Lockup) Get(descriptor protoreflect.FieldDescriptor) pro // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_Lockup) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + x.DelegatorAddress = value.Interface().(string) case "sourcehub.tier.v1beta1.Lockup.validator_address": x.ValidatorAddress = value.Interface().(string) case "sourcehub.tier.v1beta1.Lockup.amount": @@ -271,6 +288,8 @@ func (x *fastReflection_Lockup) Mutable(fd protoreflect.FieldDescriptor) protore x.UnlockTime = new(timestamppb.Timestamp) } return protoreflect.ValueOfMessage(x.UnlockTime.ProtoReflect()) + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + panic(fmt.Errorf("field delegator_address of message sourcehub.tier.v1beta1.Lockup is not mutable")) case "sourcehub.tier.v1beta1.Lockup.validator_address": panic(fmt.Errorf("field validator_address of message sourcehub.tier.v1beta1.Lockup is not mutable")) case "sourcehub.tier.v1beta1.Lockup.amount": @@ -290,6 +309,8 @@ func (x *fastReflection_Lockup) Mutable(fd protoreflect.FieldDescriptor) protore // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_Lockup) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { + case "sourcehub.tier.v1beta1.Lockup.delegator_address": + return protoreflect.ValueOfString("") case "sourcehub.tier.v1beta1.Lockup.validator_address": return protoreflect.ValueOfString("") case "sourcehub.tier.v1beta1.Lockup.amount": @@ -371,6 +392,10 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { var n int var l int _ = l + l = len(x.DelegatorAddress) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } l = len(x.ValidatorAddress) if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) @@ -431,7 +456,7 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], encoded) i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } if x.UnbondTime != nil { encoded, err := options.Marshal(x.UnbondTime) @@ -445,25 +470,32 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], encoded) i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } if x.CreationHeight != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.CreationHeight)) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x20 } if len(x.Amount) > 0 { i -= len(x.Amount) copy(dAtA[i:], x.Amount) i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Amount))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(x.ValidatorAddress) > 0 { i -= len(x.ValidatorAddress) copy(dAtA[i:], x.ValidatorAddress) i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ValidatorAddress))) i-- + dAtA[i] = 0x12 + } + if len(x.DelegatorAddress) > 0 { + i -= len(x.DelegatorAddress) + copy(dAtA[i:], x.DelegatorAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DelegatorAddress))) + i-- dAtA[i] = 0xa } if input.Buf != nil { @@ -516,6 +548,38 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { } switch fieldNum { case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) } @@ -547,7 +611,7 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { } x.ValidatorAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } @@ -579,7 +643,7 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { } x.Amount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field CreationHeight", wireType) } @@ -598,7 +662,7 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { break } } - case 4: + case 5: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field UnbondTime", wireType) } @@ -634,7 +698,7 @@ func (x *fastReflection_Lockup) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field UnlockTime", wireType) } @@ -724,16 +788,17 @@ type Lockup struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` - Amount string `protobuf:"bytes,2,opt,name=amount,proto3" json:"amount,omitempty"` + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` // The following fields are only used for unlocking lockups. // // The height at which the lockup was created. - CreationHeight int64 `protobuf:"varint,3,opt,name=creation_height,json=creationHeight,proto3" json:"creation_height,omitempty"` + CreationHeight int64 `protobuf:"varint,4,opt,name=creation_height,json=creationHeight,proto3" json:"creation_height,omitempty"` // The time at which the stake undelegation will be completed. - UnbondTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=unbond_time,json=unbondTime,proto3" json:"unbond_time,omitempty"` + UnbondTime *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=unbond_time,json=unbondTime,proto3" json:"unbond_time,omitempty"` // The time at which the stake unlocking will be completed. - UnlockTime *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=unlock_time,json=unlockTime,proto3" json:"unlock_time,omitempty"` + UnlockTime *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=unlock_time,json=unlockTime,proto3" json:"unlock_time,omitempty"` } func (x *Lockup) Reset() { @@ -756,6 +821,13 @@ func (*Lockup) Descriptor() ([]byte, []int) { return file_sourcehub_tier_v1beta1_lockup_proto_rawDescGZIP(), []int{0} } +func (x *Lockup) GetDelegatorAddress() string { + if x != nil { + return x.DelegatorAddress + } + return "" +} + func (x *Lockup) GetValidatorAddress() string { if x != nil { return x.ValidatorAddress @@ -803,42 +875,46 @@ var file_sourcehub_tier_v1beta1_lockup_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0xcc, 0x02, 0x0a, 0x06, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x12, 0x4e, 0x0a, 0x11, 0x76, 0x61, - 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x10, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x43, 0x0a, 0x06, 0x61, 0x6d, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x2b, 0xc8, 0xde, 0x1f, 0x00, - 0xda, 0xde, 0x1f, 0x15, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, - 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x49, 0x6e, 0x74, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, - 0x27, 0x0a, 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x68, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x41, 0x0a, 0x0b, 0x75, 0x6e, 0x62, 0x6f, - 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x04, 0x90, 0xdf, 0x1f, 0x01, 0x52, - 0x0a, 0x75, 0x6e, 0x62, 0x6f, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x41, 0x0a, 0x0b, 0x75, - 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x04, 0x90, 0xdf, - 0x1f, 0x01, 0x52, 0x0a, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x69, 0x6d, 0x65, 0x42, 0xd8, - 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, - 0x2e, 0x74, 0x69, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0b, 0x4c, - 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x63, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x2f, 0x74, 0x69, 0x65, 0x72, 0x2f, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x74, 0x69, 0x65, 0x72, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0xa2, 0x02, 0x03, 0x53, 0x54, 0x58, 0xaa, 0x02, 0x16, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x68, 0x75, 0x62, 0x2e, 0x54, 0x69, 0x65, 0x72, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, - 0xca, 0x02, 0x16, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x5c, 0x54, 0x69, 0x65, - 0x72, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, 0x53, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x68, 0x75, 0x62, 0x5c, 0x54, 0x69, 0x65, 0x72, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, - 0x18, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x3a, 0x3a, 0x54, 0x69, 0x65, 0x72, - 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x93, 0x03, 0x0a, 0x06, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x12, 0x45, 0x0a, 0x11, 0x64, 0x65, + 0x6c, 0x65, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, + 0x10, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x12, 0x4e, 0x0a, 0x11, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, + 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, + 0x10, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x12, 0x43, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x2b, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x15, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x49, 0x6e, 0x74, + 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0x52, 0x06, + 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x0e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, + 0x41, 0x0a, 0x0b, 0x75, 0x6e, 0x62, 0x6f, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x42, 0x04, 0x90, 0xdf, 0x1f, 0x01, 0x52, 0x0a, 0x75, 0x6e, 0x62, 0x6f, 0x6e, 0x64, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x41, 0x0a, 0x0b, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, + 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x42, 0x04, 0x90, 0xdf, 0x1f, 0x01, 0x52, 0x0a, 0x75, 0x6e, 0x6c, 0x6f, 0x63, + 0x6b, 0x54, 0x69, 0x6d, 0x65, 0x42, 0xd8, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x6f, + 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x2e, 0x74, 0x69, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0x42, 0x0b, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, + 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x2f, + 0x74, 0x69, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x74, 0x69, 0x65, + 0x72, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x53, 0x54, 0x58, 0xaa, 0x02, + 0x16, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x2e, 0x54, 0x69, 0x65, 0x72, 0x2e, + 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x68, 0x75, 0x62, 0x5c, 0x54, 0x69, 0x65, 0x72, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0xe2, 0x02, 0x22, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x5c, 0x54, 0x69, 0x65, + 0x72, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, + 0x62, 0x3a, 0x3a, 0x54, 0x69, 0x65, 0x72, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/sourcehub/tier/v1beta1/params.pulsar.go b/api/sourcehub/tier/v1beta1/params.pulsar.go index 1f742ad..ef3f353 100644 --- a/api/sourcehub/tier/v1beta1/params.pulsar.go +++ b/api/sourcehub/tier/v1beta1/params.pulsar.go @@ -3,7 +3,6 @@ package tierv1beta1 import ( _ "cosmossdk.io/api/amino" - binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" @@ -13,7 +12,6 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" durationpb "google.golang.org/protobuf/types/known/durationpb" io "io" - math "math" reflect "reflect" sync "sync" ) @@ -723,8 +721,8 @@ func (x *fastReflection_Rate) Range(f func(protoreflect.FieldDescriptor, protore return } } - if x.Rate != float64(0) || math.Signbit(x.Rate) { - value := protoreflect.ValueOfFloat64(x.Rate) + if x.Rate != int64(0) { + value := protoreflect.ValueOfInt64(x.Rate) if !f(fd_Rate_rate, value) { return } @@ -747,7 +745,7 @@ func (x *fastReflection_Rate) Has(fd protoreflect.FieldDescriptor) bool { case "sourcehub.tier.v1beta1.Rate.amount": return x.Amount != "" case "sourcehub.tier.v1beta1.Rate.rate": - return x.Rate != float64(0) || math.Signbit(x.Rate) + return x.Rate != int64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: sourcehub.tier.v1beta1.Rate")) @@ -767,7 +765,7 @@ func (x *fastReflection_Rate) Clear(fd protoreflect.FieldDescriptor) { case "sourcehub.tier.v1beta1.Rate.amount": x.Amount = "" case "sourcehub.tier.v1beta1.Rate.rate": - x.Rate = float64(0) + x.Rate = int64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: sourcehub.tier.v1beta1.Rate")) @@ -789,7 +787,7 @@ func (x *fastReflection_Rate) Get(descriptor protoreflect.FieldDescriptor) proto return protoreflect.ValueOfString(value) case "sourcehub.tier.v1beta1.Rate.rate": value := x.Rate - return protoreflect.ValueOfFloat64(value) + return protoreflect.ValueOfInt64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: sourcehub.tier.v1beta1.Rate")) @@ -813,7 +811,7 @@ func (x *fastReflection_Rate) Set(fd protoreflect.FieldDescriptor, value protore case "sourcehub.tier.v1beta1.Rate.amount": x.Amount = value.Interface().(string) case "sourcehub.tier.v1beta1.Rate.rate": - x.Rate = value.Float() + x.Rate = value.Int() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: sourcehub.tier.v1beta1.Rate")) @@ -854,7 +852,7 @@ func (x *fastReflection_Rate) NewField(fd protoreflect.FieldDescriptor) protoref case "sourcehub.tier.v1beta1.Rate.amount": return protoreflect.ValueOfString("") case "sourcehub.tier.v1beta1.Rate.rate": - return protoreflect.ValueOfFloat64(float64(0)) + return protoreflect.ValueOfInt64(int64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: sourcehub.tier.v1beta1.Rate")) @@ -928,8 +926,8 @@ func (x *fastReflection_Rate) ProtoMethods() *protoiface.Methods { if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } - if x.Rate != 0 || math.Signbit(x.Rate) { - n += 9 + if x.Rate != 0 { + n += 1 + runtime.Sov(uint64(x.Rate)) } if x.unknownFields != nil { n += len(x.unknownFields) @@ -960,11 +958,10 @@ func (x *fastReflection_Rate) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if x.Rate != 0 || math.Signbit(x.Rate) { - i -= 8 - binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(x.Rate)))) + if x.Rate != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Rate)) i-- - dAtA[i] = 0x11 + dAtA[i] = 0x10 } if len(x.Amount) > 0 { i -= len(x.Amount) @@ -1055,16 +1052,24 @@ func (x *fastReflection_Rate) ProtoMethods() *protoiface.Methods { x.Amount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: - if wireType != 1 { + if wireType != 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Rate", wireType) } - var v uint64 - if (iNdEx + 8) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + x.Rate = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Rate |= int64(b&0x7F) << shift + if b < 0x80 { + break + } } - v = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - x.Rate = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -1172,8 +1177,8 @@ type Rate struct { unknownFields protoimpl.UnknownFields // amount of locked stake required for earning rewards at this rate. - Amount string `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` - Rate float64 `protobuf:"fixed64,2,opt,name=rate,proto3" json:"rate,omitempty"` + Amount string `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` + Rate int64 `protobuf:"varint,2,opt,name=rate,proto3" json:"rate,omitempty"` } func (x *Rate) Reset() { @@ -1203,7 +1208,7 @@ func (x *Rate) GetAmount() string { return "" } -func (x *Rate) GetRate() float64 { +func (x *Rate) GetRate() int64 { if x != nil { return x.Rate } @@ -1241,7 +1246,7 @@ var file_sourcehub_tier_v1beta1_params_proto_rawDesc = []byte{ 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x49, 0x6e, 0x74, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x04, 0x72, 0x61, 0x74, 0x65, 0x42, 0xd8, 0x01, 0x0a, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x72, 0x61, 0x74, 0x65, 0x42, 0xd8, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x68, 0x75, 0x62, 0x2e, 0x74, 0x69, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x63, 0x6f, 0x73, 0x6d, diff --git a/proto/sourcehub/tier/v1beta1/lockup.proto b/proto/sourcehub/tier/v1beta1/lockup.proto index 7287f7e..9e0c188 100644 --- a/proto/sourcehub/tier/v1beta1/lockup.proto +++ b/proto/sourcehub/tier/v1beta1/lockup.proto @@ -9,8 +9,9 @@ option go_package = "github.com/sourcenetwork/sourcehub/x/tier/types"; // Lockup tracks the locked and unlocking stake of a delegator. message Lockup { - string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; - string amount = 2 [ + string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + string amount = 3 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false @@ -19,11 +20,11 @@ message Lockup { // The following fields are only used for unlocking lockups. // // The height at which the lockup was created. - int64 creation_height = 3; + int64 creation_height = 4; // The time at which the stake undelegation will be completed. - google.protobuf.Timestamp unbond_time = 4 [(gogoproto.stdtime) = true]; + google.protobuf.Timestamp unbond_time = 5 [(gogoproto.stdtime) = true]; // The time at which the stake unlocking will be completed. - google.protobuf.Timestamp unlock_time = 5 [(gogoproto.stdtime) = true]; + google.protobuf.Timestamp unlock_time = 6 [(gogoproto.stdtime) = true]; } diff --git a/proto/sourcehub/tier/v1beta1/params.proto b/proto/sourcehub/tier/v1beta1/params.proto index 839b6f2..58a888f 100644 --- a/proto/sourcehub/tier/v1beta1/params.proto +++ b/proto/sourcehub/tier/v1beta1/params.proto @@ -26,5 +26,5 @@ message Rate { (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; - double rate = 2; + int64 rate = 2; } diff --git a/scripts/ignite/config-tier.yml b/scripts/ignite/config-tier.yml index fd3758b..bdb6d94 100644 --- a/scripts/ignite/config-tier.yml +++ b/scripts/ignite/config-tier.yml @@ -58,10 +58,10 @@ genesis: unlocking_epochs: 2 reward_rates: - amount: '300' - rate: 1.50 + rate: 150 - amount: '200' - rate: 1.20 + rate: 120 - amount: '100' - rate: 1.10 + rate: 110 - amount: '0' - rate: 1.00 + rate: 100 diff --git a/x/tier/keeper/credit.go b/x/tier/keeper/credit.go index 1721a76..b93f5c0 100644 --- a/x/tier/keeper/credit.go +++ b/x/tier/keeper/credit.go @@ -12,9 +12,8 @@ import ( "github.com/sourcenetwork/sourcehub/x/tier/types" ) -// Mintcredit mints a coin and sends it to the specified address. +// mintCredit mints a coin and sends it to the specified address. func (k Keeper) mintCredit(ctx context.Context, addr sdk.AccAddress, amt math.Int) error { - coins := sdk.NewCoins(sdk.NewCoin(appparams.CreditDenom, amt)) err := k.bankKeeper.MintCoins(ctx, types.ModuleName, coins) if err != nil { @@ -31,7 +30,6 @@ func (k Keeper) mintCredit(ctx context.Context, addr sdk.AccAddress, amt math.In // proratedCredit calculates the credits earned on the lockingAmt. func (k Keeper) proratedCredit(ctx context.Context, delAddr sdk.AccAddress, lockingAmt math.Int) math.Int { - // Calculate the reward credits earned on the new lock. rates := k.GetParams(ctx).RewardRates lockedAmt := k.TotalAmountByAddr(ctx, delAddr) @@ -43,7 +41,7 @@ func (k Keeper) proratedCredit(ctx context.Context, delAddr sdk.AccAddress, lock epochDuration := epochInfo.Duration.Milliseconds() // TODO: is this check necessary? - // Uner what condition can sinceCurrentEpoch be greater than epochDuration? + // Under what condition can sinceCurrentEpoch be greater than epochDuration? // What happens if the chain is paused for a long time? if sinceCurrentEpoch < epochDuration { credit = credit.MulRaw(sinceCurrentEpoch).QuoRaw(epochDuration) @@ -55,11 +53,9 @@ func (k Keeper) proratedCredit(ctx context.Context, delAddr sdk.AccAddress, lock // burnAllCredits burns all the reward credits in the system. // It is called at the end of each epoch. func (k Keeper) burnAllCredits(ctx context.Context) error { - // Note that we can't simply iterate through the lockup records because credits // are transferrable and can be stored in accounts that are not tracked by lockups. // Instead, we iterate through all the balances to find and burn the credits. - var err error cb := func(addr sdk.AccAddress, coin sdk.Coin) (stop bool) { @@ -91,12 +87,10 @@ func (k Keeper) burnAllCredits(ctx context.Context) error { // resetAllCredits resets all the credits in the system. func (k Keeper) resetAllCredits(ctx context.Context) error { - // Reward to a delegator is calculated based on the total locked amount // to all validators. Since each lockup entry only records locked amount // for a single validator, we need to iterate through all the lockups to // calculate the total locked amount for each delegator. - lockedAmts := make(map[string]math.Int) cb := func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup) { @@ -107,12 +101,11 @@ func (k Keeper) resetAllCredits(ctx context.Context) error { lockedAmts[delAddr.String()] = amt.Add(lockup.Amount) } - k.mustIterateLockups(ctx, false, cb) + k.MustIterateLockups(ctx, false, cb) rates := k.GetParams(ctx).RewardRates for delStrAddr, amt := range lockedAmts { - delAddr := sdk.MustAccAddressFromBech32(delStrAddr) credit := calculateCredit(rates, math.ZeroInt(), amt) err := k.mintCredit(ctx, delAddr, credit) @@ -128,13 +121,11 @@ func (k Keeper) resetAllCredits(ctx context.Context) error { // lockingAmt is stacked up on top of the lockedAmt to earn at the // highest eligible reward. func calculateCredit(rateList []types.Rate, lockedAmt, lockingAmt math.Int) math.Int { - credit := math.ZeroInt() stakedAmt := lockedAmt.Add(lockingAmt) // Iterate from the highest reward rate to the lowest. for _, r := range rateList { - // Continue if the total lock does not reach the current rate requirement. if stakedAmt.LT(r.Amount) { continue @@ -143,8 +134,11 @@ func calculateCredit(rateList []types.Rate, lockedAmt, lockingAmt math.Int) math lower := math.MaxInt(r.Amount, lockedAmt) diff := stakedAmt.Sub(lower) - amt := float64(diff.Int64()) * r.Rate - credit = credit.AddRaw(int64(amt)) + diffDec := math.LegacyNewDecFromInt(diff) + rateDec := math.LegacyNewDec(r.Rate) + + amt := diffDec.Mul(rateDec).Quo(math.LegacyNewDec(100)) + credit = credit.Add(amt.TruncateInt()) // Subtract the lock that has been rewarded. stakedAmt = stakedAmt.Sub(diff) diff --git a/x/tier/keeper/credit_test.go b/x/tier/keeper/credit_test.go index 0da1db8..8c0bc66 100644 --- a/x/tier/keeper/credit_test.go +++ b/x/tier/keeper/credit_test.go @@ -11,12 +11,11 @@ import ( ) func Test_calReward(t *testing.T) { - rateList := []types.Rate{ - {Amount: math.NewInt(300), Rate: 1.50}, - {Amount: math.NewInt(200), Rate: 1.20}, - {Amount: math.NewInt(100), Rate: 1.10}, - {Amount: math.NewInt(0), Rate: 1.00}, + {Amount: math.NewInt(300), Rate: 150}, + {Amount: math.NewInt(200), Rate: 120}, + {Amount: math.NewInt(100), Rate: 110}, + {Amount: math.NewInt(0), Rate: 100}, } tests := []struct { @@ -86,7 +85,6 @@ func Test_calReward(t *testing.T) { }, } for _, tt := range tests { - name := fmt.Sprintf("%d adds %d", tt.lockedAmt, tt.lockingAmt) oldLock := math.NewInt(tt.lockedAmt) newLock := math.NewInt(tt.lockingAmt) diff --git a/x/tier/keeper/grpc_query.go b/x/tier/keeper/grpc_query.go index 8eaa9e8..72668fc 100644 --- a/x/tier/keeper/grpc_query.go +++ b/x/tier/keeper/grpc_query.go @@ -50,9 +50,10 @@ func (q Querier) Lockup(ctx context.Context, req *types.LockupRequest) ( return nil, status.Error(codes.InvalidArgument, "invalid validator address") } - amt := q.getLockup(ctx, delAddr, valAddr) + amt := q.GetLockup(ctx, delAddr, valAddr) lockup := &types.Lockup{ + DelegatorAddress: req.DelegatorAddress, ValidatorAddress: req.ValidatorAddress, Amount: amt, } @@ -99,10 +100,11 @@ func (q Querier) UnlockingLockup(ctx context.Context, req *types.UnlockingLockup found, amt, unbondTime, unlockTime := q.getUnlockingLockup(ctx, delAddr, valAddr) if !found { - return nil, status.Error(codes.NotFound, "not found") + return &types.UnlockingLockupResponse{Lockup: types.Lockup{ValidatorAddress: req.ValidatorAddress, Amount: amt}}, nil } lockup := &types.Lockup{ + DelegatorAddress: req.DelegatorAddress, ValidatorAddress: req.ValidatorAddress, Amount: amt, UnbondTime: &unbondTime, @@ -136,10 +138,8 @@ func (q Querier) getLockupsPaginated(ctx context.Context, unlocking bool, delAdd []types.Lockup, *query.PageResponse, error) { var lockups []types.Lockup - store := q.lockupStore(ctx, unlocking) onResult := func(key []byte, value []byte) error { - if !bytes.HasPrefix(key, delAddr.Bytes()) { return nil } diff --git a/x/tier/keeper/grpc_query_test.go b/x/tier/keeper/grpc_query_test.go index c8a3213..8c787e0 100644 --- a/x/tier/keeper/grpc_query_test.go +++ b/x/tier/keeper/grpc_query_test.go @@ -2,7 +2,10 @@ package keeper_test import ( "testing" + "time" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" keepertest "github.com/sourcenetwork/sourcehub/testutil/keeper" @@ -17,6 +20,108 @@ func TestParamsQuery(t *testing.T) { querier := tierkeeper.NewQuerier(keeper) response, err := querier.Params(ctx, &types.QueryParamsRequest{}) + require.NoError(t, err) require.Equal(t, &types.QueryParamsResponse{Params: params}, response) } + +func TestLockupQuery(t *testing.T) { + keeper, ctx := keepertest.TierKeeper(t) + delAddr := sdk.AccAddress("source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et") + valAddr := sdk.ValAddress("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + amount := math.NewInt(1000) + + keeper.AddLockup(ctx, delAddr, valAddr, amount) + + querier := tierkeeper.NewQuerier(keeper) + response, err := querier.Lockup(ctx, &types.LockupRequest{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + }) + + require.NoError(t, err) + require.Equal(t, &types.LockupResponse{ + Lockup: types.Lockup{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + Amount: amount, + }, + }, response) +} + +func TestLockupsQuery(t *testing.T) { + keeper, ctx := keepertest.TierKeeper(t) + delAddr := sdk.AccAddress("source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et") + valAddr := sdk.ValAddress("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + amount1 := math.NewInt(1000) + amount2 := math.NewInt(500) + + keeper.AddLockup(ctx, delAddr, valAddr, amount1) + keeper.AddLockup(ctx, delAddr, valAddr, amount2) + + querier := tierkeeper.NewQuerier(keeper) + response, err := querier.Lockups(ctx, &types.LockupsRequest{ + DelegatorAddress: delAddr.String(), + }) + + require.NoError(t, err) + require.Len(t, response.Lockup, 1) + require.Equal(t, amount1.Add(amount2), response.Lockup[0].Amount) +} + +func TestUnlockingLockupQuery(t *testing.T) { + keeper, ctx := keepertest.TierKeeper(t) + delAddr := sdk.AccAddress("source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et") + valAddr := sdk.ValAddress("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + amount := math.NewInt(1000) + + unbondTime := time.Now().Add(24 * time.Hour).UTC() + unlockTime := time.Now().Add(48 * time.Hour).UTC() + + keeper.SetLockup(ctx, true, delAddr, valAddr, amount, 1, &unbondTime, &unlockTime) + + querier := tierkeeper.NewQuerier(keeper) + response, err := querier.UnlockingLockup(ctx, &types.UnlockingLockupRequest{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + }) + + require.NoError(t, err) + require.Equal(t, &types.UnlockingLockupResponse{ + Lockup: types.Lockup{ + DelegatorAddress: delAddr.String(), + ValidatorAddress: valAddr.String(), + Amount: amount, + UnbondTime: &unbondTime, + UnlockTime: &unlockTime, + }, + }, response) +} + +func TestUnlockingLockupsQuery(t *testing.T) { + keeper, ctx := keepertest.TierKeeper(t) + delAddr := sdk.AccAddress("source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et") + valAddr := sdk.ValAddress("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + amount1 := math.NewInt(1000) + amount2 := math.NewInt(500) + + unbondTime1 := time.Now().Add(24 * time.Hour).UTC() + unlockTime1 := time.Now().Add(48 * time.Hour).UTC() + unbondTime2 := time.Now().Add(36 * time.Hour).UTC() + unlockTime2 := time.Now().Add(72 * time.Hour).UTC() + + keeper.SetLockup(ctx, true, delAddr, valAddr, amount1, 1, &unbondTime1, &unlockTime1) + keeper.SetLockup(ctx, true, delAddr, valAddr, amount2, 2, &unbondTime2, &unlockTime2) + + querier := tierkeeper.NewQuerier(keeper) + response, err := querier.UnlockingLockups(ctx, &types.UnlockingLockupsRequest{ + DelegatorAddress: delAddr.String(), + }) + + require.NoError(t, err) + require.Len(t, response.Lockup, 1) + // TODO: at the moment, SetLockup() overrides existing lockup. + // This needs to be changed in favor of storing unlocking lockups separately. + // After the change, this test should be updated to use new SetLockup logic + // and the response.Lockup length check above should return 2 as expected. +} diff --git a/x/tier/keeper/keeper.go b/x/tier/keeper/keeper.go index b65bd14..85fd151 100644 --- a/x/tier/keeper/keeper.go +++ b/x/tier/keeper/keeper.go @@ -76,7 +76,6 @@ func (k Keeper) Logger() log.Logger { // CompleteUnlocking completes the unlocking process for all lockups that have reached their unlock time. // It is called at the end of each Epoch. func (k Keeper) CompleteUnlocking(ctx context.Context) error { - cb := func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup) error { if time.Now().Before(*lockup.UnlockTime) { return nil @@ -99,12 +98,12 @@ func (k Keeper) CompleteUnlocking(ctx context.Context) error { if err != nil { return errorsmod.Wrap(err, "iterate lockups") } + return nil } // Lock locks the stake of a delegator to a validator. func (k Keeper) Lock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) error { - validator, err := k.stakingKeeper.GetValidator(ctx, valAddr) if err != nil { return types.ErrInvalidAddress.Wrapf("validator address %s: %s", valAddr, err) @@ -126,7 +125,7 @@ func (k Keeper) Lock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.Va } // Record the lockup - k.addLockup(ctx, delAddr, valAddr, stake.Amount) + k.AddLockup(ctx, delAddr, valAddr, stake.Amount) // Mint credits creditAmt := k.proratedCredit(ctx, delAddr, amt) @@ -143,7 +142,7 @@ func (k Keeper) Lock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.Va func (k Keeper) Unlock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) ( unbondTime time.Time, unlockTime time.Time, err error) { - err = k.subtractLockup(ctx, delAddr, valAddr, amt) + err = k.SubtractLockup(ctx, delAddr, valAddr, amt) if err != nil { return time.Time{}, time.Time{}, errorsmod.Wrap(err, "subtract lockup") } @@ -167,7 +166,7 @@ func (k Keeper) Unlock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk. sdkCtx := sdk.UnwrapSDKContext(ctx) height := sdkCtx.BlockHeight() - k.setLockup(ctx, true, delAddr, valAddr, amt, height, &unbondTime, &unlockTime) + k.SetLockup(ctx, true, delAddr, valAddr, amt, height, &unbondTime, &unlockTime) return unbondTime, unlockTime, nil } @@ -177,12 +176,12 @@ func (k Keeper) Unlock(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk. func (k Keeper) Redelegate(ctx context.Context, delAddr sdk.AccAddress, srcValAddr, dstValAddr sdk.ValAddress, amt math.Int) ( completionTime time.Time, err error) { - err = k.subtractLockup(ctx, delAddr, srcValAddr, amt) + err = k.SubtractLockup(ctx, delAddr, srcValAddr, amt) if err != nil { return time.Time{}, errorsmod.Wrap(err, "subtract locked stake from source validator") } - k.addLockup(ctx, delAddr, dstValAddr, amt) + k.AddLockup(ctx, delAddr, dstValAddr, amt) shares, err := k.stakingKeeper.ValidateUnbondAmount(ctx, delAddr, srcValAddr, amt) if err != nil { diff --git a/x/tier/keeper/lockup.go b/x/tier/keeper/lockup.go index aeded72..b534d47 100644 --- a/x/tier/keeper/lockup.go +++ b/x/tier/keeper/lockup.go @@ -17,23 +17,23 @@ import ( // GetAllockups returns all lockups in the store. // It is only used for exporting all lockups as part of the app state. func (k Keeper) GetAllLockups(ctx context.Context) []types.Lockup { - var lockups []types.Lockup cb := func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup) { lockups = append(lockups, lockup) } - k.mustIterateLockups(ctx, true, cb) - k.mustIterateLockups(ctx, false, cb) + k.MustIterateLockups(ctx, true, cb) + k.MustIterateLockups(ctx, false, cb) return lockups } -func (k Keeper) setLockup(ctx context.Context, unlocking bool, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int, creationHeight int64, unbondTime *time.Time, unlockTime *time.Time) { +func (k Keeper) SetLockup(ctx context.Context, unlocking bool, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int, creationHeight int64, unbondTime *time.Time, unlockTime *time.Time) { key := types.LockupKey(delAddr, valAddr) lockup := &types.Lockup{ + DelegatorAddress: delAddr.String(), ValidatorAddress: valAddr.String(), Amount: amt, CreationHeight: creationHeight, @@ -45,8 +45,7 @@ func (k Keeper) setLockup(ctx context.Context, unlocking bool, delAddr sdk.AccAd store.Set(key, b) } -func (k Keeper) getLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) math.Int { - +func (k Keeper) GetLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) math.Int { key := types.LockupKey(delAddr, valAddr) store := k.lockupStore(ctx, false) b := store.Get(key) @@ -60,6 +59,14 @@ func (k Keeper) getLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr s return lockup.Amount } +func (k Keeper) HasLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) bool { + key := types.LockupKey(delAddr, valAddr) + store := k.lockupStore(ctx, false) + b := store.Get(key) + + return b != nil +} + func (k Keeper) getUnlockingLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( found bool, amt math.Int, unbondTime time.Time, unlockTime time.Time) { @@ -77,36 +84,33 @@ func (k Keeper) getUnlockingLockup(ctx context.Context, delAddr sdk.AccAddress, } func (k Keeper) removeUnlockingLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { - key := types.LockupKey(delAddr, valAddr) store := k.lockupStore(ctx, true) + store.Delete(key) } -func (k Keeper) addLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) { - - lockedAmt := k.getLockup(ctx, delAddr, valAddr) +func (k Keeper) AddLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) { + lockedAmt := k.GetLockup(ctx, delAddr, valAddr) amt = amt.Add(lockedAmt) - k.setLockup(ctx, false, delAddr, valAddr, amt, 0, nil, nil) + k.SetLockup(ctx, false, delAddr, valAddr, amt, 0, nil, nil) } -func (k Keeper) subtractLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) error { - - lockedAmt := k.getLockup(ctx, delAddr, valAddr) +func (k Keeper) SubtractLockup(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) error { + lockedAmt := k.GetLockup(ctx, delAddr, valAddr) lockedAmt, err := lockedAmt.SafeSub(amt) if err != nil { return errorsmod.Wrapf(err, "subtract %s from locked amount %s", amt, lockedAmt) } - k.setLockup(ctx, false, delAddr, valAddr, lockedAmt, 0, nil, nil) + k.SetLockup(ctx, false, delAddr, valAddr, lockedAmt, 0, nil, nil) return nil } func (k Keeper) TotalAmountByAddr(ctx context.Context, delAddr sdk.AccAddress) math.Int { - amt := math.ZeroInt() cb := func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup) { @@ -115,7 +119,7 @@ func (k Keeper) TotalAmountByAddr(ctx context.Context, delAddr sdk.AccAddress) m } } - k.mustIterateLockups(ctx, false, cb) + k.MustIterateLockups(ctx, false, cb) return amt } @@ -128,13 +132,12 @@ func (k Keeper) iterateLockups(ctx context.Context, unlocking bool, store := k.lockupStore(ctx, unlocking) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - var lockup types.Lockup k.cdc.MustUnmarshal(iterator.Value(), &lockup) - delAddr, valAddr := types.LockupKeyToAddresses(iterator.Key()) err := cb(delAddr, valAddr, lockup) if err != nil { @@ -145,19 +148,18 @@ func (k Keeper) iterateLockups(ctx context.Context, unlocking bool, return nil } -// mustIterateLockups iterates over all lockups in the store and performs the provided callback function. -func (k Keeper) mustIterateLockups(ctx context.Context, unlocking bool, +// MustIterateLockups iterates over all lockups in the store and performs the provided callback function. +func (k Keeper) MustIterateLockups(ctx context.Context, unlocking bool, cb func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup)) { store := k.lockupStore(ctx, unlocking) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - var lockup types.Lockup k.cdc.MustUnmarshal(iterator.Value(), &lockup) - delAddr, valAddr := types.LockupKeyToAddresses(iterator.Key()) cb(delAddr, valAddr, lockup) } @@ -166,5 +168,6 @@ func (k Keeper) mustIterateLockups(ctx context.Context, unlocking bool, func (k Keeper) lockupStore(ctx context.Context, unlocking bool) prefix.Store { storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) storePrefix := types.KeyPrefix(unlocking) + return prefix.NewStore(storeAdapter, storePrefix) } diff --git a/x/tier/keeper/lockup_test.go b/x/tier/keeper/lockup_test.go new file mode 100644 index 0000000..78596b2 --- /dev/null +++ b/x/tier/keeper/lockup_test.go @@ -0,0 +1,136 @@ +package keeper_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sourcenetwork/sourcehub/app" + keepertest "github.com/sourcenetwork/sourcehub/testutil/keeper" + "github.com/sourcenetwork/sourcehub/x/tier/keeper" + "github.com/sourcenetwork/sourcehub/x/tier/types" + "github.com/stretchr/testify/require" +) + +func init() { + app.SetConfig(true) +} + +func setupKeeper(t *testing.T) (*keeper.Keeper, sdk.Context) { + k, ctx := keepertest.TierKeeper(t) + return &k, ctx +} + +func TestSetAndGetLockup(t *testing.T) { + k, ctx := setupKeeper(t) + + amount := math.NewInt(1000) + creationHeight := int64(10) + unbondTime := time.Now().Add(1 * time.Hour) + unlockTime := time.Now().Add(2 * time.Hour) + + delAddr, err := sdk.AccAddressFromBech32("source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9") + require.Nil(t, err) + valAddr, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + k.SetLockup(ctx, false, delAddr, valAddr, amount, creationHeight, &unbondTime, &unlockTime) + + store := k.GetAllLockups(ctx) + require.Len(t, store, 1) + + lockup := store[0] + require.Equal(t, delAddr.String(), lockup.DelegatorAddress) + require.Equal(t, valAddr.String(), lockup.ValidatorAddress) + require.Equal(t, amount, lockup.Amount) + require.Equal(t, creationHeight, lockup.CreationHeight) + require.Equal(t, unbondTime.UTC(), lockup.UnbondTime.UTC()) + require.Equal(t, unlockTime.UTC(), lockup.UnlockTime.UTC()) +} + +func TestAddLockup(t *testing.T) { + k, ctx := setupKeeper(t) + + amount := math.NewInt(500) + + delAddr, err := sdk.AccAddressFromBech32("source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9") + require.Nil(t, err) + valAddr, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + k.AddLockup(ctx, delAddr, valAddr, amount) + + lockup := k.GetLockup(ctx, delAddr, valAddr) + require.Equal(t, amount, lockup) +} + +func TestSubtractLockup(t *testing.T) { + k, ctx := setupKeeper(t) + + amount := math.NewInt(1000) + + delAddr, err := sdk.AccAddressFromBech32("source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9") + require.Nil(t, err) + valAddr, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + k.AddLockup(ctx, delAddr, valAddr, amount) + + err = k.SubtractLockup(ctx, delAddr, valAddr, math.NewInt(500)) + require.NoError(t, err) + + lockup := k.GetLockup(ctx, delAddr, valAddr) + require.Equal(t, math.NewInt(500), lockup) +} + +func TestGetAllLockups(t *testing.T) { + k, ctx := setupKeeper(t) + + amount1 := math.NewInt(1000) + amount2 := math.NewInt(500) + + delAddr1, err := sdk.AccAddressFromBech32("source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et") + require.Nil(t, err) + valAddr1, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + delAddr2, err := sdk.AccAddressFromBech32("source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9") + require.Nil(t, err) + valAddr2, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + k.SetLockup(ctx, false, delAddr1, valAddr1, amount1, 1, nil, nil) + k.SetLockup(ctx, false, delAddr2, valAddr2, amount2, 2, nil, nil) + + lockups := k.GetAllLockups(ctx) + require.Len(t, lockups, 2) + + require.Equal(t, delAddr1.String(), lockups[0].DelegatorAddress) + require.Equal(t, valAddr1.String(), lockups[0].ValidatorAddress) + require.Equal(t, delAddr2.String(), lockups[1].DelegatorAddress) + require.Equal(t, valAddr2.String(), lockups[1].ValidatorAddress) +} + +func TestIterateLockups(t *testing.T) { + k, ctx := setupKeeper(t) + + amount := math.NewInt(1000) + + delAddr, err := sdk.AccAddressFromBech32("source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9") + require.Nil(t, err) + valAddr, err := sdk.ValAddressFromBech32("sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm") + require.Nil(t, err) + + k.AddLockup(ctx, delAddr, valAddr, amount) + + count := 0 + k.MustIterateLockups(ctx, false, func(delAddr sdk.AccAddress, valAddr sdk.ValAddress, lockup types.Lockup) { + require.Equal(t, "source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9", delAddr.String()) + require.Equal(t, "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", valAddr.String()) + require.Equal(t, amount, lockup.Amount) + count++ + }) + + require.Equal(t, 1, count) +} diff --git a/x/tier/module/genesis.go b/x/tier/module/genesis.go index ab72b6a..a0dc7df 100644 --- a/x/tier/module/genesis.go +++ b/x/tier/module/genesis.go @@ -3,6 +3,7 @@ package tier import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sourcenetwork/sourcehub/x/tier/keeper" "github.com/sourcenetwork/sourcehub/x/tier/types" ) @@ -13,6 +14,16 @@ func InitGenesis(ctx context.Context, k keeper.Keeper, genState types.GenesisSta if err := k.SetParams(ctx, genState.Params); err != nil { panic(err) } + + for _, lockup := range genState.Lockups { + delAddr := sdk.MustAccAddressFromBech32(lockup.DelegatorAddress) + valAddr := types.MustValAddressFromBech32(lockup.ValidatorAddress) + if k.HasLockup(ctx, delAddr, valAddr) { + k.AddLockup(ctx, delAddr, valAddr, lockup.Amount) + } else { + k.SetLockup(ctx, lockup.UnlockTime != nil, delAddr, valAddr, lockup.Amount, lockup.CreationHeight, lockup.UnbondTime, lockup.UnlockTime) + } + } } // ExportGenesis returns the module's exported genesis. diff --git a/x/tier/module/genesis_test.go b/x/tier/module/genesis_test.go new file mode 100644 index 0000000..6aac0b7 --- /dev/null +++ b/x/tier/module/genesis_test.go @@ -0,0 +1,131 @@ +package tier_test + +import ( + "testing" + "time" + + "cosmossdk.io/math" + "github.com/sourcenetwork/sourcehub/app" + keepertest "github.com/sourcenetwork/sourcehub/testutil/keeper" + "github.com/sourcenetwork/sourcehub/testutil/nullify" + tier "github.com/sourcenetwork/sourcehub/x/tier/module" + "github.com/sourcenetwork/sourcehub/x/tier/types" + "github.com/stretchr/testify/require" +) + +func init() { + app.SetConfig(true) +} + +func TestGenesis(t *testing.T) { + timestamp1 := time.Date(2006, time.January, 2, 15, 4, 5, 1, time.UTC) + timestamp2 := time.Date(2006, time.January, 2, 15, 4, 5, 2, time.UTC) + timestamp3 := time.Date(2006, time.January, 2, 15, 4, 5, 3, time.UTC) + + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + Lockups: []types.Lockup{ + { + DelegatorAddress: "source1wjj5v5rlf57kayyeskncpu4hwev25ty645p2et", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(1000), + CreationHeight: 1, + UnbondTime: ×tamp1, + UnlockTime: ×tamp1, + }, + { + DelegatorAddress: "source1n34fvpteuanu2nx2a4hql4jvcrcnal3gsrjppy", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(500), + CreationHeight: 2, + UnbondTime: ×tamp2, + UnlockTime: ×tamp2, + }, + { + DelegatorAddress: "source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(2000), + CreationHeight: 3, + UnbondTime: ×tamp3, + UnlockTime: ×tamp3, + }, + }, + } + + k, ctx := keepertest.TierKeeper(t) + tier.InitGenesis(ctx, k, genesisState) + got := tier.ExportGenesis(ctx, k) + require.NotNil(t, got) + require.Equal(t, genesisState.Params, got.Params) + require.Equal(t, len(genesisState.Lockups), len(got.Lockups)) + + for i, lockup := range genesisState.Lockups { + require.Equal(t, lockup.ValidatorAddress, got.Lockups[i].ValidatorAddress) + require.Equal(t, lockup.Amount, got.Lockups[i].Amount) + require.Equal(t, lockup.CreationHeight, got.Lockups[i].CreationHeight) + if lockup.UnbondTime != nil { + require.NotNil(t, got.Lockups[i].UnbondTime) + require.Equal(t, lockup.UnbondTime.UTC(), got.Lockups[i].UnbondTime.UTC()) + } else { + require.Nil(t, got.Lockups[i].UnbondTime) + } + if lockup.UnlockTime != nil { + require.NotNil(t, got.Lockups[i].UnlockTime) + require.Equal(t, lockup.UnlockTime.UTC(), got.Lockups[i].UnlockTime.UTC()) + } else { + require.Nil(t, got.Lockups[i].UnlockTime) + } + } + + nullify.Fill(&genesisState) + nullify.Fill(got) +} + +func TestInitWithMultipleIdenticalLockups(t *testing.T) { + timestamp1 := time.Date(2006, time.January, 2, 15, 4, 5, 1, time.UTC) + timestamp2 := time.Date(2006, time.January, 2, 15, 4, 5, 2, time.UTC) + timestamp3 := time.Date(2006, time.January, 2, 15, 4, 5, 3, time.UTC) + + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + Lockups: []types.Lockup{ + { + DelegatorAddress: "source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(1000), + CreationHeight: 1, + UnbondTime: ×tamp1, + UnlockTime: nil, + }, + { + DelegatorAddress: "source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(2000), + CreationHeight: 2, + UnbondTime: ×tamp2, + UnlockTime: nil, + }, + { + DelegatorAddress: "source1m4f5a896t7fzd9vc7pfgmc3fxkj8n24s68fcw9", + ValidatorAddress: "sourcevaloper1cy0p47z24ejzvq55pu3lesxwf73xnrnd0pzkqm", + Amount: math.NewInt(3000), + CreationHeight: 3, + UnbondTime: ×tamp3, + UnlockTime: nil, + }, + }, + } + + k, ctx := keepertest.TierKeeper(t) + tier.InitGenesis(ctx, k, genesisState) + got := tier.ExportGenesis(ctx, k) + require.NotNil(t, got) + require.Equal(t, genesisState.Params, got.Params) + + // Lockups of identical del/val records are added and exported as a single record. + require.Equal(t, 1, len(got.Lockups)) + require.Equal(t, int64(6000), got.Lockups[0].Amount.Int64()) + + nullify.Fill(&genesisState) + nullify.Fill(got) +} diff --git a/x/tier/types/expected_keepers.go b/x/tier/types/expected_keepers.go index a147164..ab0f208 100644 --- a/x/tier/types/expected_keepers.go +++ b/x/tier/types/expected_keepers.go @@ -17,18 +17,22 @@ type EpochsKeeper interface { // StakingKeeper defines the expected interface for the Staking module. type StakingKeeper interface { Delegate(ctx context.Context, delAddr sdk.AccAddress, bondAmt math.Int, tokenSrc stakingtypes.BondStatus, - validator stakingtypes.Validator, subtractAccount bool) ( - newShares math.LegacyDec, err error) - + validator stakingtypes.Validator, subtractAccount bool) (newShares math.LegacyDec, err error) Undelegate(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount math.LegacyDec) ( time.Time, math.Int, error) - BeginRedelegation(ctx context.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, sharesAmount math.LegacyDec) (completionTime time.Time, err error) BondDenom(ctx context.Context) (string, error) GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error) ValidateUnbondAmount(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int) ( shares math.LegacyDec, err error) + GetUnbondingDelegation(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) ( + ubd stakingtypes.UnbondingDelegation, err error) + SetUnbondingDelegation(ctx context.Context, ubd stakingtypes.UnbondingDelegation) error + RemoveUnbondingDelegation(ctx context.Context, ubd stakingtypes.UnbondingDelegation) error + SetValidatorByConsAddr(ctx context.Context, addr stakingtypes.Validator) error + SetValidator(ctx context.Context, addr stakingtypes.Validator) error + CompleteUnbonding(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) } // BankKeeper defines the expected interface for the Bank module. @@ -43,6 +47,7 @@ type BankKeeper interface { // ViewKeeper interface IterateAllBalances(ctx context.Context, cb func(addr sdk.AccAddress, coin sdk.Coin) bool) + GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin } // ParamSubspace defines the expected Subspace interface for parameters. diff --git a/x/tier/types/lockup.pb.go b/x/tier/types/lockup.pb.go index 55fbd39..5bce5bf 100644 --- a/x/tier/types/lockup.pb.go +++ b/x/tier/types/lockup.pb.go @@ -31,16 +31,17 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Lockup tracks the locked and unlocking stake of a delegator. type Lockup struct { - ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` - Amount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` + DelegatorAddress string `protobuf:"bytes,1,opt,name=delegator_address,json=delegatorAddress,proto3" json:"delegator_address,omitempty"` + ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` // The following fields are only used for unlocking lockups. // // The height at which the lockup was created. - CreationHeight int64 `protobuf:"varint,3,opt,name=creation_height,json=creationHeight,proto3" json:"creation_height,omitempty"` + CreationHeight int64 `protobuf:"varint,4,opt,name=creation_height,json=creationHeight,proto3" json:"creation_height,omitempty"` // The time at which the stake undelegation will be completed. - UnbondTime *time.Time `protobuf:"bytes,4,opt,name=unbond_time,json=unbondTime,proto3,stdtime" json:"unbond_time,omitempty"` + UnbondTime *time.Time `protobuf:"bytes,5,opt,name=unbond_time,json=unbondTime,proto3,stdtime" json:"unbond_time,omitempty"` // The time at which the stake unlocking will be completed. - UnlockTime *time.Time `protobuf:"bytes,5,opt,name=unlock_time,json=unlockTime,proto3,stdtime" json:"unlock_time,omitempty"` + UnlockTime *time.Time `protobuf:"bytes,6,opt,name=unlock_time,json=unlockTime,proto3,stdtime" json:"unlock_time,omitempty"` } func (m *Lockup) Reset() { *m = Lockup{} } @@ -76,6 +77,13 @@ func (m *Lockup) XXX_DiscardUnknown() { var xxx_messageInfo_Lockup proto.InternalMessageInfo +func (m *Lockup) GetDelegatorAddress() string { + if m != nil { + return m.DelegatorAddress + } + return "" +} + func (m *Lockup) GetValidatorAddress() string { if m != nil { return m.ValidatorAddress @@ -113,31 +121,33 @@ func init() { } var fileDescriptor_2e0e6f58f533fc52 = []byte{ - // 382 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x8e, 0xd3, 0x30, - 0x14, 0x85, 0xe3, 0x99, 0xa1, 0x12, 0x1e, 0x89, 0x9f, 0x08, 0x50, 0xa8, 0x44, 0x52, 0x60, 0x41, - 0x25, 0x34, 0xb6, 0x06, 0x9e, 0x60, 0xca, 0x86, 0x4a, 0x88, 0x45, 0x40, 0x2c, 0xd8, 0x44, 0x4e, - 0x62, 0x12, 0xab, 0x8d, 0x6f, 0x65, 0xdf, 0x14, 0x78, 0x8b, 0x79, 0x98, 0x79, 0x88, 0x59, 0xb0, - 0xa8, 0xba, 0x42, 0x2c, 0x0a, 0x6a, 0x5f, 0x04, 0x39, 0x4e, 0x40, 0x62, 0xc5, 0xce, 0xfe, 0x74, - 0xee, 0x39, 0x3a, 0xba, 0x97, 0x3e, 0xb5, 0xd0, 0x9a, 0x42, 0xd6, 0x6d, 0xce, 0x51, 0x49, 0xc3, - 0xd7, 0xe7, 0xb9, 0x44, 0x71, 0xce, 0x97, 0x50, 0x2c, 0xda, 0x15, 0x5b, 0x19, 0x40, 0x08, 0x1f, - 0xfc, 0x11, 0x31, 0x27, 0x62, 0xbd, 0x68, 0xfc, 0xb0, 0x00, 0xdb, 0x80, 0xcd, 0x3a, 0x15, 0xf7, - 0x1f, 0x3f, 0x32, 0xbe, 0x57, 0x41, 0x05, 0x9e, 0xbb, 0x57, 0x4f, 0x93, 0x0a, 0xa0, 0x5a, 0x4a, - 0xde, 0xfd, 0xf2, 0xf6, 0x13, 0x47, 0xd5, 0x48, 0x8b, 0xa2, 0xe9, 0x93, 0x9e, 0x7c, 0x3b, 0xa2, - 0xa3, 0x37, 0x5d, 0x74, 0xf8, 0x96, 0xde, 0x5d, 0x8b, 0xa5, 0x2a, 0x05, 0x82, 0xc9, 0x44, 0x59, - 0x1a, 0x69, 0x6d, 0x44, 0x26, 0x64, 0x7a, 0x73, 0xf6, 0x78, 0x7b, 0x75, 0xf6, 0xa8, 0x8f, 0xfb, - 0x30, 0x68, 0x2e, 0xbc, 0xe4, 0x1d, 0x1a, 0xa5, 0xab, 0xf4, 0xce, 0xfa, 0x1f, 0x1e, 0xbe, 0xa2, - 0x23, 0xd1, 0x40, 0xab, 0x31, 0x3a, 0xea, 0x4c, 0x9e, 0x5f, 0xef, 0x92, 0xe0, 0xc7, 0x2e, 0xb9, - 0xef, 0x8d, 0x6c, 0xb9, 0x60, 0x0a, 0x78, 0x23, 0xb0, 0x66, 0x73, 0x8d, 0xdb, 0xab, 0x33, 0xda, - 0x27, 0xcc, 0x35, 0xa6, 0xfd, 0x68, 0xf8, 0x8c, 0xde, 0x2e, 0x8c, 0x14, 0xa8, 0x40, 0x67, 0xb5, - 0x54, 0x55, 0x8d, 0xd1, 0xf1, 0x84, 0x4c, 0x8f, 0xd3, 0x5b, 0x03, 0x7e, 0xdd, 0xd1, 0xf0, 0x82, - 0x9e, 0xb6, 0x3a, 0x07, 0x5d, 0x66, 0xae, 0x62, 0x74, 0x32, 0x21, 0xd3, 0xd3, 0x17, 0x63, 0xe6, - 0xfb, 0xb3, 0xa1, 0x3f, 0x7b, 0x3f, 0xf4, 0x9f, 0x9d, 0x5c, 0xfe, 0x4c, 0x48, 0x4a, 0xfd, 0x90, - 0xc3, 0xde, 0xc2, 0xed, 0xc1, 0x5b, 0xdc, 0xf8, 0x7f, 0x0b, 0x37, 0xe4, 0xf0, 0x6c, 0x7e, 0xbd, - 0x8f, 0xc9, 0x66, 0x1f, 0x93, 0x5f, 0xfb, 0x98, 0x5c, 0x1e, 0xe2, 0x60, 0x73, 0x88, 0x83, 0xef, - 0x87, 0x38, 0xf8, 0xc8, 0x2b, 0x85, 0x6e, 0x9f, 0x05, 0x34, 0xdc, 0x6f, 0x57, 0x4b, 0xfc, 0x0c, - 0x66, 0xc1, 0xff, 0x1e, 0xc4, 0x17, 0x7f, 0x12, 0xf8, 0x75, 0x25, 0x6d, 0x3e, 0xea, 0x02, 0x5f, - 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x7d, 0x78, 0xae, 0x59, 0x31, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xd1, 0x8a, 0x13, 0x31, + 0x14, 0x86, 0x1b, 0xbb, 0x16, 0xcc, 0x82, 0xba, 0xc3, 0x2a, 0x63, 0xc1, 0x69, 0xd5, 0x0b, 0x0b, + 0xd2, 0x84, 0xd5, 0x27, 0xd8, 0x8a, 0x60, 0x41, 0xbc, 0xa8, 0xe2, 0x85, 0x37, 0x25, 0x33, 0x13, + 0xd3, 0xd0, 0x4e, 0x4e, 0x49, 0xce, 0x54, 0x7d, 0x8b, 0x05, 0x5f, 0xa5, 0x0f, 0xb1, 0x97, 0x4b, + 0xaf, 0xc4, 0x8b, 0x55, 0xda, 0x17, 0x91, 0x4c, 0xd2, 0x15, 0xf7, 0x6a, 0xef, 0xe6, 0xfc, 0xf3, + 0xff, 0xdf, 0x0f, 0x27, 0x87, 0x3e, 0x73, 0x50, 0xdb, 0x42, 0xce, 0xea, 0x9c, 0xa3, 0x96, 0x96, + 0xaf, 0x4e, 0x72, 0x89, 0xe2, 0x84, 0x2f, 0xa0, 0x98, 0xd7, 0x4b, 0xb6, 0xb4, 0x80, 0x90, 0x3c, + 0xbc, 0x32, 0x31, 0x6f, 0x62, 0xd1, 0xd4, 0x7d, 0x54, 0x80, 0xab, 0xc0, 0x4d, 0x1b, 0x17, 0x0f, + 0x43, 0x88, 0x74, 0x8f, 0x15, 0x28, 0x08, 0xba, 0xff, 0x8a, 0x6a, 0x4f, 0x01, 0xa8, 0x85, 0xe4, + 0xcd, 0x94, 0xd7, 0x5f, 0x38, 0xea, 0x4a, 0x3a, 0x14, 0x55, 0x6c, 0x7a, 0xfa, 0xa3, 0x4d, 0x3b, + 0xef, 0x9a, 0xea, 0xe4, 0x0d, 0x3d, 0x2a, 0xe5, 0x42, 0x2a, 0x81, 0x60, 0xa7, 0xa2, 0x2c, 0xad, + 0x74, 0x2e, 0x25, 0x7d, 0x32, 0xb8, 0x33, 0x4a, 0x37, 0xeb, 0xe1, 0x71, 0xac, 0x3b, 0x0d, 0x7f, + 0x3e, 0xa0, 0xd5, 0x46, 0x4d, 0xee, 0x5f, 0x45, 0xa2, 0x9e, 0xbc, 0xa7, 0x47, 0x2b, 0xb1, 0xd0, + 0xe5, 0x7f, 0x98, 0x5b, 0x0d, 0xe6, 0xc9, 0x66, 0x3d, 0x7c, 0x1c, 0x31, 0x9f, 0xf6, 0x9e, 0x6b, + 0xbc, 0xd5, 0x35, 0x3d, 0x79, 0x4d, 0x3b, 0xa2, 0x82, 0xda, 0x60, 0xda, 0x6e, 0x20, 0x2f, 0xce, + 0x2f, 0x7b, 0xad, 0x5f, 0x97, 0xbd, 0x07, 0x01, 0xe4, 0xca, 0x39, 0xd3, 0xc0, 0x2b, 0x81, 0x33, + 0x36, 0x36, 0xb8, 0x59, 0x0f, 0x69, 0x6c, 0x18, 0x1b, 0x9c, 0xc4, 0x68, 0xf2, 0x9c, 0xde, 0x2b, + 0xac, 0x14, 0xa8, 0xc1, 0x4c, 0x67, 0x52, 0xab, 0x19, 0xa6, 0x07, 0x7d, 0x32, 0x68, 0x4f, 0xee, + 0xee, 0xe5, 0xb7, 0x8d, 0x9a, 0x9c, 0xd2, 0xc3, 0xda, 0xe4, 0x60, 0xca, 0xa9, 0xdf, 0x54, 0x7a, + 0xbb, 0x4f, 0x06, 0x87, 0x2f, 0xbb, 0x2c, 0xac, 0x91, 0xed, 0xd7, 0xc8, 0x3e, 0xee, 0xd7, 0x38, + 0x3a, 0x38, 0xfb, 0xdd, 0x23, 0x13, 0x1a, 0x42, 0x5e, 0x0e, 0x08, 0xff, 0x9c, 0x01, 0xd1, 0xb9, + 0x39, 0xc2, 0x87, 0xbc, 0x3c, 0x1a, 0x9f, 0x6f, 0x33, 0x72, 0xb1, 0xcd, 0xc8, 0x9f, 0x6d, 0x46, + 0xce, 0x76, 0x59, 0xeb, 0x62, 0x97, 0xb5, 0x7e, 0xee, 0xb2, 0xd6, 0x67, 0xae, 0x34, 0xfa, 0xb3, + 0x28, 0xa0, 0xe2, 0xe1, 0x48, 0x8c, 0xc4, 0xaf, 0x60, 0xe7, 0xfc, 0xdf, 0x5d, 0x7d, 0x0b, 0x97, + 0x85, 0xdf, 0x97, 0xd2, 0xe5, 0x9d, 0xa6, 0xf0, 0xd5, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, + 0x59, 0x99, 0xc1, 0x78, 0x02, 0x00, 0x00, } func (m *Lockup) Marshal() (dAtA []byte, err error) { @@ -168,7 +178,7 @@ func (m *Lockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n1 i = encodeVarintLockup(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } if m.UnbondTime != nil { n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(*m.UnbondTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(*m.UnbondTime):]) @@ -178,12 +188,12 @@ func (m *Lockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n2 i = encodeVarintLockup(dAtA, i, uint64(n2)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } if m.CreationHeight != 0 { i = encodeVarintLockup(dAtA, i, uint64(m.CreationHeight)) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x20 } { size := m.Amount.Size() @@ -194,12 +204,19 @@ func (m *Lockup) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintLockup(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a if len(m.ValidatorAddress) > 0 { i -= len(m.ValidatorAddress) copy(dAtA[i:], m.ValidatorAddress) i = encodeVarintLockup(dAtA, i, uint64(len(m.ValidatorAddress))) i-- + dAtA[i] = 0x12 + } + if len(m.DelegatorAddress) > 0 { + i -= len(m.DelegatorAddress) + copy(dAtA[i:], m.DelegatorAddress) + i = encodeVarintLockup(dAtA, i, uint64(len(m.DelegatorAddress))) + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -222,6 +239,10 @@ func (m *Lockup) Size() (n int) { } var l int _ = l + l = len(m.DelegatorAddress) + if l > 0 { + n += 1 + l + sovLockup(uint64(l)) + } l = len(m.ValidatorAddress) if l > 0 { n += 1 + l + sovLockup(uint64(l)) @@ -278,6 +299,38 @@ func (m *Lockup) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DelegatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLockup + } + 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 ErrInvalidLengthLockup + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthLockup + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DelegatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) } @@ -309,7 +362,7 @@ func (m *Lockup) Unmarshal(dAtA []byte) error { } m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } @@ -343,7 +396,7 @@ func (m *Lockup) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field CreationHeight", wireType) } @@ -362,7 +415,7 @@ func (m *Lockup) Unmarshal(dAtA []byte) error { break } } - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field UnbondTime", wireType) } @@ -398,7 +451,7 @@ func (m *Lockup) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field UnlockTime", wireType) } diff --git a/x/tier/types/params.go b/x/tier/types/params.go index d2123c3..b849bb1 100644 --- a/x/tier/types/params.go +++ b/x/tier/types/params.go @@ -36,10 +36,10 @@ func DefaultParams() Params { EpochDuration: &du, UnlockingEpochs: 2, RewardRates: []Rate{ - {Amount: math.NewInt(300), Rate: 1.50}, - {Amount: math.NewInt(200), Rate: 1.20}, - {Amount: math.NewInt(100), Rate: 1.10}, - {Amount: math.NewInt(0), Rate: 1.00}, + {Amount: math.NewInt(300), Rate: 150}, + {Amount: math.NewInt(200), Rate: 120}, + {Amount: math.NewInt(100), Rate: 110}, + {Amount: math.NewInt(0), Rate: 100}, }, } } @@ -90,7 +90,7 @@ func validateCreditRewardRate(i interface{}) error { return fmt.Errorf("invalid locked stake: %s", rate.Amount) } if rate.Rate <= 0 { - return fmt.Errorf("invalid rate: %f", rate.Rate) + return fmt.Errorf("invalid rate: %d", rate.Rate) } } return nil diff --git a/x/tier/types/params.pb.go b/x/tier/types/params.pb.go index c4299dd..9eb2980 100644 --- a/x/tier/types/params.pb.go +++ b/x/tier/types/params.pb.go @@ -5,7 +5,6 @@ package types import ( cosmossdk_io_math "cosmossdk.io/math" - encoding_binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" @@ -96,7 +95,7 @@ func (m *Params) GetRewardRates() []Rate { type Rate struct { // amount of locked stake required for earning rewards at this rate. Amount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` - Rate float64 `protobuf:"fixed64,2,opt,name=rate,proto3" json:"rate,omitempty"` + Rate int64 `protobuf:"varint,2,opt,name=rate,proto3" json:"rate,omitempty"` } func (m *Rate) Reset() { *m = Rate{} } @@ -132,7 +131,7 @@ func (m *Rate) XXX_DiscardUnknown() { var xxx_messageInfo_Rate proto.InternalMessageInfo -func (m *Rate) GetRate() float64 { +func (m *Rate) GetRate() int64 { if m != nil { return m.Rate } @@ -149,7 +148,7 @@ func init() { } var fileDescriptor_a6ec74918331e1a2 = []byte{ - // 390 bytes of a gzipped FileDescriptorProto + // 388 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xcf, 0x6e, 0xda, 0x40, 0x10, 0xc6, 0xbd, 0x05, 0x21, 0xb1, 0xf4, 0xaf, 0xd5, 0x56, 0x80, 0x2a, 0x83, 0xe8, 0x85, 0xb6, 0xea, 0xae, 0xa0, 0x6f, 0xe0, 0xfe, 0x91, 0xe8, 0xa9, 0xf2, 0xb1, 0x17, 0x6b, 0x6d, 0xb6, 0xc6, @@ -170,11 +169,11 @@ var fileDescriptor_a6ec74918331e1a2 = []byte{ 0x21, 0xae, 0x97, 0x85, 0xfb, 0x1d, 0x37, 0x58, 0x06, 0x85, 0xd0, 0xc6, 0x7e, 0xd3, 0xff, 0x52, 0xf2, 0x37, 0x9b, 0xde, 0x3b, 0x9b, 0x96, 0x9a, 0xce, 0x49, 0x0a, 0x34, 0x63, 0x7a, 0x46, 0x26, 0x42, 0x5f, 0x5d, 0x7c, 0xc5, 0x55, 0x8c, 0x13, 0xa1, 0x83, 0x6a, 0xd5, 0x75, 0x71, 0xbd, 0x74, - 0x64, 0x7c, 0xa3, 0xc0, 0xd4, 0xfe, 0x64, 0xb5, 0xf5, 0xd0, 0x7a, 0xeb, 0xa1, 0xbb, 0xad, 0x87, - 0x4e, 0x76, 0x9e, 0xb3, 0xde, 0x79, 0xce, 0xf5, 0xce, 0x73, 0xfe, 0xd2, 0x24, 0xd5, 0xa5, 0xd9, - 0x18, 0x32, 0x6a, 0xad, 0x0b, 0xae, 0x97, 0x20, 0xe7, 0xf4, 0xf1, 0xf7, 0x1f, 0xd9, 0x07, 0xa0, - 0x8f, 0x73, 0xae, 0xa2, 0x86, 0x89, 0xf2, 0xdb, 0x43, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xbe, - 0x8e, 0x0a, 0x1f, 0x02, 0x00, 0x00, + 0x54, 0xf9, 0x36, 0xb5, 0x3f, 0x59, 0x6d, 0x3d, 0xb4, 0xde, 0x7a, 0xe8, 0x6e, 0xeb, 0xa1, 0x93, + 0x9d, 0xe7, 0xac, 0x77, 0x9e, 0x73, 0xbd, 0xf3, 0x9c, 0xbf, 0x34, 0x49, 0x75, 0x69, 0x36, 0x86, + 0x8c, 0x5a, 0xeb, 0x82, 0xeb, 0x25, 0xc8, 0x39, 0x7d, 0xfc, 0xfd, 0x47, 0xf6, 0x01, 0xe8, 0xe3, + 0x9c, 0xab, 0xa8, 0x61, 0xa2, 0xfc, 0xf6, 0x10, 0x00, 0x00, 0xff, 0xff, 0x83, 0xd6, 0xf1, 0x17, + 0x1f, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -250,10 +249,9 @@ func (m *Rate) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if m.Rate != 0 { - i -= 8 - encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.Rate)))) + i = encodeVarintParams(dAtA, i, uint64(m.Rate)) i-- - dAtA[i] = 0x11 + dAtA[i] = 0x10 } { size := m.Amount.Size() @@ -310,7 +308,7 @@ func (m *Rate) Size() (n int) { l = m.Amount.Size() n += 1 + l + sovParams(uint64(l)) if m.Rate != 0 { - n += 9 + n += 1 + sovParams(uint64(m.Rate)) } return n } @@ -524,16 +522,24 @@ func (m *Rate) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: - if wireType != 1 { + if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Rate", wireType) } - var v uint64 - if (iNdEx + 8) > l { - return io.ErrUnexpectedEOF + m.Rate = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Rate |= int64(b&0x7F) << shift + if b < 0x80 { + break + } } - v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - m.Rate = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])