diff --git a/proto/elys/parameter/params.proto b/proto/elys/parameter/params.proto index ad4717ceb..5c277db1e 100644 --- a/proto/elys/parameter/params.proto +++ b/proto/elys/parameter/params.proto @@ -24,3 +24,21 @@ message Params { string broker_address = 4; int64 total_blocks_per_year = 5; } + +message LegacyParams { + option (gogoproto.goproto_stringer) = false; + + string min_commission_rate = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string max_voting_power = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string min_self_delegation = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + string broker_address = 4; +} \ No newline at end of file diff --git a/x/parameter/keeper/params.go b/x/parameter/keeper/params.go index 7c81ec2de..6c618ca77 100644 --- a/x/parameter/keeper/params.go +++ b/x/parameter/keeper/params.go @@ -24,3 +24,16 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { b := k.cdc.MustMarshal(¶ms) store.Set([]byte(types.ParamsKey), b) } + +// GetParams get all parameters as types.Params +func (k Keeper) GetLegacyParams(ctx sdk.Context) (params types.LegacyParams) { + store := ctx.KVStore(k.storeKey) + + b := store.Get([]byte(types.ParamsKey)) + if b == nil { + return + } + + k.cdc.MustUnmarshal(b, ¶ms) + return +} diff --git a/x/parameter/migrations/v3_migration.go b/x/parameter/migrations/v3_migration.go index ddcfbc225..2f71ba68d 100644 --- a/x/parameter/migrations/v3_migration.go +++ b/x/parameter/migrations/v3_migration.go @@ -7,12 +7,13 @@ import ( func (m Migrator) V3Migration(ctx sdk.Context) error { // reset params + legacy := m.keeper.GetLegacyParams(ctx) params := types.NewParams( - sdk.NewDecWithPrec(5, 2), // min commission 0.05 - sdk.NewDecWithPrec(66, 2), // max voting power 0.66 - sdk.NewInt(1), // min self delegation - "elys1m3hduhk4uzxn8mxuvpz02ysndxfwgy5mq60h4c34qqn67xud584qeee3m4", // broker address - 6307200, // total blocks per year + legacy.MinCommissionRate, // min commission 0.05 + legacy.MaxVotingPower, // max voting power 0.66 + legacy.MinSelfDelegation, // min self delegation + legacy.BrokerAddress, // broker address + 6307200, // total blocks per year ) m.keeper.SetParams(ctx, params) diff --git a/x/parameter/types/params.go b/x/parameter/types/params.go index 88ea6fbf0..d5cb57b75 100644 --- a/x/parameter/types/params.go +++ b/x/parameter/types/params.go @@ -100,3 +100,9 @@ func validateBrokerAddress(i interface{}) error { } return nil } + +// String implements the Stringer interface. +func (p LegacyParams) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/parameter/types/params.pb.go b/x/parameter/types/params.pb.go index b8763e201..6d8e684a9 100644 --- a/x/parameter/types/params.pb.go +++ b/x/parameter/types/params.pb.go @@ -79,36 +79,85 @@ func (m *Params) GetTotalBlocksPerYear() int64 { return 0 } +type LegacyParams struct { + MinCommissionRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=min_commission_rate,json=minCommissionRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"min_commission_rate"` + MaxVotingPower github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=max_voting_power,json=maxVotingPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"max_voting_power"` + MinSelfDelegation github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=min_self_delegation,json=minSelfDelegation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_self_delegation"` + BrokerAddress string `protobuf:"bytes,4,opt,name=broker_address,json=brokerAddress,proto3" json:"broker_address,omitempty"` +} + +func (m *LegacyParams) Reset() { *m = LegacyParams{} } +func (*LegacyParams) ProtoMessage() {} +func (*LegacyParams) Descriptor() ([]byte, []int) { + return fileDescriptor_b61780a5be327c2b, []int{1} +} +func (m *LegacyParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LegacyParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LegacyParams.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 *LegacyParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_LegacyParams.Merge(m, src) +} +func (m *LegacyParams) XXX_Size() int { + return m.Size() +} +func (m *LegacyParams) XXX_DiscardUnknown() { + xxx_messageInfo_LegacyParams.DiscardUnknown(m) +} + +var xxx_messageInfo_LegacyParams proto.InternalMessageInfo + +func (m *LegacyParams) GetBrokerAddress() string { + if m != nil { + return m.BrokerAddress + } + return "" +} + func init() { proto.RegisterType((*Params)(nil), "elys.parameter.Params") + proto.RegisterType((*LegacyParams)(nil), "elys.parameter.LegacyParams") } func init() { proto.RegisterFile("elys/parameter/params.proto", fileDescriptor_b61780a5be327c2b) } var fileDescriptor_b61780a5be327c2b = []byte{ - // 352 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xc1, 0x4a, 0xeb, 0x40, - 0x14, 0x86, 0x93, 0xdb, 0xde, 0xc2, 0x0d, 0xdc, 0xa2, 0x51, 0x21, 0x28, 0xa4, 0x45, 0x50, 0xba, - 0x69, 0x82, 0xb8, 0x73, 0x67, 0xed, 0x42, 0x77, 0x25, 0x82, 0xa8, 0x0b, 0x87, 0x49, 0x72, 0x1a, - 0x43, 0x32, 0x73, 0xc2, 0xcc, 0x68, 0xdb, 0xad, 0x4f, 0xe0, 0xd2, 0xa5, 0x8f, 0xd3, 0x65, 0x97, - 0xe2, 0xa2, 0x48, 0xfb, 0x22, 0x92, 0x89, 0x96, 0x6e, 0x75, 0x95, 0x93, 0xf3, 0xcd, 0x7c, 0xfc, - 0xc3, 0x6f, 0xed, 0x41, 0x3e, 0x91, 0x7e, 0x41, 0x05, 0x65, 0xa0, 0x40, 0x54, 0x93, 0xf4, 0x0a, - 0x81, 0x0a, 0xed, 0x66, 0x09, 0xbd, 0x15, 0xdc, 0xdd, 0x4e, 0x30, 0x41, 0x8d, 0xfc, 0x72, 0xaa, - 0x4e, 0xed, 0x3f, 0xd5, 0xac, 0xc6, 0x40, 0x5f, 0xb3, 0xef, 0xac, 0x2d, 0x96, 0x72, 0x12, 0x21, - 0x63, 0xa9, 0x94, 0x29, 0x72, 0x22, 0xa8, 0x02, 0xc7, 0x6c, 0x9b, 0x9d, 0x7f, 0x3d, 0x6f, 0x3a, - 0x6f, 0x19, 0xef, 0xf3, 0xd6, 0x61, 0x92, 0xaa, 0xfb, 0x87, 0xd0, 0x8b, 0x90, 0xf9, 0x11, 0x4a, - 0x86, 0xf2, 0xeb, 0xd3, 0x95, 0x71, 0xe6, 0xab, 0x49, 0x01, 0xd2, 0xeb, 0x43, 0x14, 0x6c, 0xb2, - 0x94, 0x9f, 0xad, 0x4c, 0x01, 0x55, 0x60, 0x5f, 0x5b, 0x1b, 0x8c, 0x8e, 0xc9, 0x23, 0xaa, 0x94, - 0x27, 0xa4, 0xc0, 0x11, 0x08, 0xe7, 0xcf, 0xaf, 0xe4, 0x4d, 0x46, 0xc7, 0x57, 0x5a, 0x33, 0x28, - 0x2d, 0xdf, 0xc9, 0x25, 0xe4, 0x43, 0x12, 0x43, 0x0e, 0x09, 0x55, 0x29, 0x72, 0xa7, 0xf6, 0x63, - 0xf9, 0x05, 0x57, 0x3a, 0xf9, 0x25, 0xe4, 0xc3, 0xfe, 0x4a, 0x64, 0x1f, 0x58, 0xcd, 0x50, 0x60, - 0x06, 0x82, 0xd0, 0x38, 0x16, 0x20, 0xa5, 0x53, 0x2f, 0xd5, 0xc1, 0xff, 0x6a, 0x7b, 0x5a, 0x2d, - 0xed, 0x23, 0x6b, 0x47, 0xa1, 0xa2, 0x39, 0x09, 0x73, 0x8c, 0x32, 0x49, 0x0a, 0x10, 0x64, 0x02, - 0x54, 0x38, 0x7f, 0xdb, 0x66, 0xa7, 0x16, 0xd8, 0x1a, 0xf6, 0x34, 0x1b, 0x80, 0xb8, 0x01, 0x2a, - 0x4e, 0xea, 0x2f, 0xaf, 0x2d, 0xa3, 0x77, 0x3e, 0x5d, 0xb8, 0xe6, 0x6c, 0xe1, 0x9a, 0x1f, 0x0b, - 0xd7, 0x7c, 0x5e, 0xba, 0xc6, 0x6c, 0xe9, 0x1a, 0x6f, 0x4b, 0xd7, 0xb8, 0xf5, 0xd6, 0x42, 0x97, - 0x7d, 0x76, 0x39, 0xa8, 0x11, 0x8a, 0x4c, 0xff, 0xf8, 0xe3, 0xb5, 0xee, 0xf5, 0x03, 0xc2, 0x86, - 0x6e, 0xf5, 0xf8, 0x33, 0x00, 0x00, 0xff, 0xff, 0xf3, 0xe7, 0xd9, 0x9d, 0x1a, 0x02, 0x00, 0x00, + // 378 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x93, 0x41, 0x4b, 0xe3, 0x40, + 0x14, 0xc7, 0x93, 0xb6, 0x5b, 0xd8, 0xb0, 0x5b, 0x76, 0xb3, 0xbb, 0x10, 0x76, 0x21, 0x2d, 0x85, + 0x5d, 0x7a, 0x69, 0xc2, 0xe2, 0xcd, 0x9b, 0xb5, 0x07, 0x05, 0x0f, 0x25, 0x82, 0xa8, 0x07, 0x87, + 0x49, 0xf2, 0x1a, 0x43, 0x32, 0x79, 0x61, 0x66, 0xb4, 0xcd, 0xd5, 0x4f, 0xe0, 0xd1, 0xa3, 0x1f, + 0xa7, 0xc7, 0x5e, 0x04, 0xf1, 0x50, 0xa4, 0xfd, 0x22, 0x92, 0x89, 0x96, 0x5e, 0x15, 0x8f, 0x9e, + 0xe6, 0xcd, 0xfb, 0xcf, 0xfc, 0xf8, 0xf3, 0x1e, 0x7f, 0xe3, 0x0f, 0xa4, 0x85, 0x70, 0x73, 0xca, + 0x29, 0x03, 0x09,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ad, 0x4f, 0x1d, 0xbd, 0x57, 0xf7, + 0x4c, 0x25, 0x0e, 0x94, 0x36, 0x02, 0x7e, 0x02, 0x94, 0x6f, 0x37, 0x6e, 0x6e, 0xdb, 0x5a, 0xf7, + 0xae, 0x66, 0x7c, 0x39, 0x80, 0x88, 0x06, 0xc5, 0xc7, 0x2a, 0xde, 0x65, 0x15, 0xd5, 0x5c, 0x07, + 0x7b, 0xb3, 0xa5, 0xad, 0xcf, 0x97, 0xb6, 0xfe, 0xb8, 0xb4, 0xf5, 0xeb, 0x95, 0xad, 0xcd, 0x57, + 0xb6, 0x76, 0xbf, 0xb2, 0xb5, 0x53, 0x67, 0xc3, 0x41, 0x99, 0x93, 0x7e, 0x06, 0x72, 0x82, 0x3c, + 0x51, 0x17, 0x77, 0xba, 0x91, 0x29, 0xe5, 0xc6, 0x6f, 0xaa, 0xb4, 0x6c, 0x3d, 0x05, 0x00, 0x00, + 0xff, 0xff, 0x48, 0x4f, 0x3f, 0x9c, 0x72, 0x03, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -176,6 +225,66 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *LegacyParams) 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 *LegacyParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LegacyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BrokerAddress) > 0 { + i -= len(m.BrokerAddress) + copy(dAtA[i:], m.BrokerAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.BrokerAddress))) + i-- + dAtA[i] = 0x22 + } + { + size := m.MinSelfDelegation.Size() + i -= size + if _, err := m.MinSelfDelegation.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.MaxVotingPower.Size() + i -= size + if _, err := m.MaxVotingPower.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.MinCommissionRate.Size() + i -= size + if _, err := m.MinCommissionRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintParams(dAtA []byte, offset int, v uint64) int { offset -= sovParams(v) base := offset @@ -209,6 +318,25 @@ func (m *Params) Size() (n int) { return n } +func (m *LegacyParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MinCommissionRate.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MaxVotingPower.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MinSelfDelegation.Size() + n += 1 + l + sovParams(uint64(l)) + l = len(m.BrokerAddress) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } + return n +} + func sovParams(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -418,6 +546,190 @@ func (m *Params) Unmarshal(dAtA []byte) error { } return nil } +func (m *LegacyParams) 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 ErrIntOverflowParams + } + 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: LegacyParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LegacyParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinCommissionRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinCommissionRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxVotingPower", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MaxVotingPower.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinSelfDelegation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinSelfDelegation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BrokerAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BrokerAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipParams(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0