From 42e4fff2b890f584e1ea99b995f37042b31f8463 Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 7 Jul 2022 19:13:38 +0530 Subject: [PATCH 01/13] WIP: params --- api/cosmos/app/v1alpha1/config.pulsar.go | 2 +- api/cosmos/crisis/v1beta1/tx.pulsar.go | 1049 ++++++++++++++++- api/cosmos/crisis/v1beta1/tx_grpc.pb.go | 44 + proto/cosmos/crisis/v1beta1/tx.proto | 28 + x/crisis/keeper/keeper.go | 13 +- x/crisis/keeper/msg_server.go | 13 + x/crisis/keeper/msg_server_test.go | 144 +++ x/crisis/keeper/params.go | 13 +- x/crisis/module.go | 7 + x/crisis/types/codec.go | 2 + x/crisis/types/keys.go | 6 + .../types/{params.go => legacy_params.go} | 0 x/crisis/types/msgs.go | 39 +- x/crisis/types/tx.pb.go | 452 ++++++- 14 files changed, 1751 insertions(+), 61 deletions(-) create mode 100644 x/crisis/keeper/msg_server_test.go rename x/crisis/types/{params.go => legacy_params.go} (100%) diff --git a/api/cosmos/app/v1alpha1/config.pulsar.go b/api/cosmos/app/v1alpha1/config.pulsar.go index 7359179ac6ac..34dfc0d7459c 100644 --- a/api/cosmos/app/v1alpha1/config.pulsar.go +++ b/api/cosmos/app/v1alpha1/config.pulsar.go @@ -1850,7 +1850,7 @@ type ModuleConfig struct { // that the v1 module had. Note: modules should provide info on which versions // they can migrate from in the ModuleDescriptor.can_migration_from field. Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // config is the config object for the module. Module config messages shouldA + // config is the config object for the module. Module config messages should // define a ModuleDescriptor using the cosmos.app.v1alpha1.is_module extension. Config *anypb.Any `protobuf:"bytes,2,opt,name=config,proto3" json:"config,omitempty"` // golang_bindings specifies explicit interface to implementation type bindings which diff --git a/api/cosmos/crisis/v1beta1/tx.pulsar.go b/api/cosmos/crisis/v1beta1/tx.pulsar.go index 13a5f6f51adb..b778998bd52b 100644 --- a/api/cosmos/crisis/v1beta1/tx.pulsar.go +++ b/api/cosmos/crisis/v1beta1/tx.pulsar.go @@ -2,6 +2,7 @@ package crisisv1beta1 import ( + v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" _ "github.com/cosmos/cosmos-proto" @@ -919,6 +920,861 @@ func (x *fastReflection_MsgVerifyInvariantResponse) ProtoMethods() *protoiface.M } } +var ( + md_MsgUpdateParams protoreflect.MessageDescriptor + fd_MsgUpdateParams_authority protoreflect.FieldDescriptor + fd_MsgUpdateParams_constant_fee protoreflect.FieldDescriptor +) + +func init() { + file_cosmos_crisis_v1beta1_tx_proto_init() + md_MsgUpdateParams = File_cosmos_crisis_v1beta1_tx_proto.Messages().ByName("MsgUpdateParams") + fd_MsgUpdateParams_authority = md_MsgUpdateParams.Fields().ByName("authority") + fd_MsgUpdateParams_constant_fee = md_MsgUpdateParams.Fields().ByName("constant_fee") +} + +var _ protoreflect.Message = (*fastReflection_MsgUpdateParams)(nil) + +type fastReflection_MsgUpdateParams MsgUpdateParams + +func (x *MsgUpdateParams) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgUpdateParams)(x) +} + +func (x *MsgUpdateParams) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_crisis_v1beta1_tx_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgUpdateParams_messageType fastReflection_MsgUpdateParams_messageType +var _ protoreflect.MessageType = fastReflection_MsgUpdateParams_messageType{} + +type fastReflection_MsgUpdateParams_messageType struct{} + +func (x fastReflection_MsgUpdateParams_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgUpdateParams)(nil) +} +func (x fastReflection_MsgUpdateParams_messageType) New() protoreflect.Message { + return new(fastReflection_MsgUpdateParams) +} +func (x fastReflection_MsgUpdateParams_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpdateParams +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgUpdateParams) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpdateParams +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgUpdateParams) Type() protoreflect.MessageType { + return _fastReflection_MsgUpdateParams_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgUpdateParams) New() protoreflect.Message { + return new(fastReflection_MsgUpdateParams) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgUpdateParams) Interface() protoreflect.ProtoMessage { + return (*MsgUpdateParams)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgUpdateParams) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Authority != "" { + value := protoreflect.ValueOfString(x.Authority) + if !f(fd_MsgUpdateParams_authority, value) { + return + } + } + if x.ConstantFee != nil { + value := protoreflect.ValueOfMessage(x.ConstantFee.ProtoReflect()) + if !f(fd_MsgUpdateParams_constant_fee, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgUpdateParams) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + return x.Authority != "" + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + return x.ConstantFee != nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParams) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + x.Authority = "" + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + x.ConstantFee = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgUpdateParams) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + value := x.Authority + return protoreflect.ValueOfString(value) + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + value := x.ConstantFee + return protoreflect.ValueOfMessage(value.ProtoReflect()) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParams) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + x.Authority = value.Interface().(string) + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + x.ConstantFee = value.Message().Interface().(*v1beta1.Coin) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParams) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + if x.ConstantFee == nil { + x.ConstantFee = new(v1beta1.Coin) + } + return protoreflect.ValueOfMessage(x.ConstantFee.ProtoReflect()) + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + panic(fmt.Errorf("field authority of message cosmos.crisis.v1beta1.MsgUpdateParams is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgUpdateParams) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "cosmos.crisis.v1beta1.MsgUpdateParams.authority": + return protoreflect.ValueOfString("") + case "cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee": + m := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParams")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParams does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgUpdateParams) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos.crisis.v1beta1.MsgUpdateParams", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgUpdateParams) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParams) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgUpdateParams) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgUpdateParams) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgUpdateParams) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Authority) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.ConstantFee != nil { + l = options.Size(x.ConstantFee) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgUpdateParams) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if x.ConstantFee != nil { + encoded, err := options.Marshal(x.ConstantFee) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x12 + } + if len(x.Authority) > 0 { + i -= len(x.Authority) + copy(dAtA[i:], x.Authority) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Authority))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgUpdateParams) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire 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++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Authority", 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.Authority = 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 ConstantFee", wireType) + } + var msglen int + 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++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + 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 + } + if x.ConstantFee == nil { + x.ConstantFee = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ConstantFee); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_MsgUpdateParamsResponse protoreflect.MessageDescriptor +) + +func init() { + file_cosmos_crisis_v1beta1_tx_proto_init() + md_MsgUpdateParamsResponse = File_cosmos_crisis_v1beta1_tx_proto.Messages().ByName("MsgUpdateParamsResponse") +} + +var _ protoreflect.Message = (*fastReflection_MsgUpdateParamsResponse)(nil) + +type fastReflection_MsgUpdateParamsResponse MsgUpdateParamsResponse + +func (x *MsgUpdateParamsResponse) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgUpdateParamsResponse)(x) +} + +func (x *MsgUpdateParamsResponse) slowProtoReflect() protoreflect.Message { + mi := &file_cosmos_crisis_v1beta1_tx_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgUpdateParamsResponse_messageType fastReflection_MsgUpdateParamsResponse_messageType +var _ protoreflect.MessageType = fastReflection_MsgUpdateParamsResponse_messageType{} + +type fastReflection_MsgUpdateParamsResponse_messageType struct{} + +func (x fastReflection_MsgUpdateParamsResponse_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgUpdateParamsResponse)(nil) +} +func (x fastReflection_MsgUpdateParamsResponse_messageType) New() protoreflect.Message { + return new(fastReflection_MsgUpdateParamsResponse) +} +func (x fastReflection_MsgUpdateParamsResponse_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpdateParamsResponse +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgUpdateParamsResponse) Descriptor() protoreflect.MessageDescriptor { + return md_MsgUpdateParamsResponse +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgUpdateParamsResponse) Type() protoreflect.MessageType { + return _fastReflection_MsgUpdateParamsResponse_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgUpdateParamsResponse) New() protoreflect.Message { + return new(fastReflection_MsgUpdateParamsResponse) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgUpdateParamsResponse) Interface() protoreflect.ProtoMessage { + return (*MsgUpdateParamsResponse)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgUpdateParamsResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgUpdateParamsResponse) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParamsResponse) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgUpdateParamsResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParamsResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParamsResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgUpdateParamsResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crisis.v1beta1.MsgUpdateParamsResponse")) + } + panic(fmt.Errorf("message cosmos.crisis.v1beta1.MsgUpdateParamsResponse does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgUpdateParamsResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in cosmos.crisis.v1beta1.MsgUpdateParamsResponse", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgUpdateParamsResponse) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgUpdateParamsResponse) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgUpdateParamsResponse) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgUpdateParamsResponse) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgUpdateParamsResponse) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgUpdateParamsResponse) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgUpdateParamsResponse) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire 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++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.0 @@ -1011,6 +1867,86 @@ func (*MsgVerifyInvariantResponse) Descriptor() ([]byte, []int) { return file_cosmos_crisis_v1beta1_tx_proto_rawDescGZIP(), []int{1} } +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParams struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // constant_fee defines the x/crisis parameter. + // + // NOTE: All parameters must be supplied. + ConstantFee *v1beta1.Coin `protobuf:"bytes,2,opt,name=constant_fee,json=constantFee,proto3" json:"constant_fee,omitempty"` +} + +func (x *MsgUpdateParams) Reset() { + *x = MsgUpdateParams{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_crisis_v1beta1_tx_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgUpdateParams) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgUpdateParams) ProtoMessage() {} + +// Deprecated: Use MsgUpdateParams.ProtoReflect.Descriptor instead. +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return file_cosmos_crisis_v1beta1_tx_proto_rawDescGZIP(), []int{2} +} + +func (x *MsgUpdateParams) GetAuthority() string { + if x != nil { + return x.Authority + } + return "" +} + +func (x *MsgUpdateParams) GetConstantFee() *v1beta1.Coin { + if x != nil { + return x.ConstantFee + } + return nil +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParamsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *MsgUpdateParamsResponse) Reset() { + *x = MsgUpdateParamsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_cosmos_crisis_v1beta1_tx_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgUpdateParamsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgUpdateParamsResponse) ProtoMessage() {} + +// Deprecated: Use MsgUpdateParamsResponse.ProtoReflect.Descriptor instead. +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return file_cosmos_crisis_v1beta1_tx_proto_rawDescGZIP(), []int{3} +} + var File_cosmos_crisis_v1beta1_tx_proto protoreflect.FileDescriptor var file_cosmos_crisis_v1beta1_tx_proto_rawDesc = []byte{ @@ -1022,6 +1958,8 @@ var file_cosmos_crisis_v1beta1_tx_proto_rawDesc = []byte{ 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb8, 0x01, 0x0a, 0x12, 0x4d, 0x73, 0x67, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 0x12, 0x30, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, @@ -1035,28 +1973,47 @@ var file_cosmos_crisis_v1beta1_tx_proto_rawDesc = []byte{ 0x6e, 0x74, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x3a, 0x13, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x1c, 0x0a, 0x1a, 0x4d, 0x73, 0x67, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, - 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x76, 0x0a, 0x03, 0x4d, 0x73, - 0x67, 0x12, 0x6f, 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, - 0x69, 0x61, 0x6e, 0x74, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, - 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, - 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 0x1a, - 0x31, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, - 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x56, 0x65, 0x72, 0x69, 0x66, - 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x42, 0xd0, 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, - 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x34, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2f, 0x76, 0x31, 0x62, 0x65, - 0x74, 0x61, 0x31, 0x3b, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, - 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x5c, - 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x21, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5c, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x43, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x3a, 0x3a, 0x56, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x9d, 0x01, 0x0a, 0x0f, 0x4d, + 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x36, + 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 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, 0x09, 0x61, 0x75, 0x74, + 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x42, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, + 0x6e, 0x74, 0x5f, 0x66, 0x65, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x0b, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x46, 0x65, 0x65, 0x3a, 0x0e, 0x82, 0xe7, 0xb0, 0x2a, + 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x22, 0x19, 0x0a, 0x17, 0x4d, 0x73, + 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xde, 0x01, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x6f, 0x0a, + 0x0f, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, + 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, + 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x56, 0x65, 0x72, 0x69, + 0x66, 0x79, 0x49, 0x6e, 0x76, 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 0x1a, 0x31, 0x2e, 0x63, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, 0x31, 0x62, 0x65, + 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x49, 0x6e, 0x76, + 0x61, 0x72, 0x69, 0x61, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x66, + 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x26, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, + 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x1a, 0x2e, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, + 0x73, 0x67, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0xd0, 0x01, 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x76, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0x42, 0x07, 0x54, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x34, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2f, + 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x63, 0x72, 0x69, 0x73, 0x69, 0x73, 0x76, 0x31, + 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x58, 0xaa, 0x02, 0x15, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x2e, 0x56, 0x31, 0x62, 0x65, + 0x74, 0x61, 0x31, 0xca, 0x02, 0x15, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x69, + 0x73, 0x69, 0x73, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x21, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, 0x5c, 0x56, 0x31, 0x62, 0x65, + 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x17, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x72, 0x69, 0x73, 0x69, 0x73, + 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -1071,19 +2028,25 @@ func file_cosmos_crisis_v1beta1_tx_proto_rawDescGZIP() []byte { return file_cosmos_crisis_v1beta1_tx_proto_rawDescData } -var file_cosmos_crisis_v1beta1_tx_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_cosmos_crisis_v1beta1_tx_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_cosmos_crisis_v1beta1_tx_proto_goTypes = []interface{}{ (*MsgVerifyInvariant)(nil), // 0: cosmos.crisis.v1beta1.MsgVerifyInvariant (*MsgVerifyInvariantResponse)(nil), // 1: cosmos.crisis.v1beta1.MsgVerifyInvariantResponse + (*MsgUpdateParams)(nil), // 2: cosmos.crisis.v1beta1.MsgUpdateParams + (*MsgUpdateParamsResponse)(nil), // 3: cosmos.crisis.v1beta1.MsgUpdateParamsResponse + (*v1beta1.Coin)(nil), // 4: cosmos.base.v1beta1.Coin } var file_cosmos_crisis_v1beta1_tx_proto_depIdxs = []int32{ - 0, // 0: cosmos.crisis.v1beta1.Msg.VerifyInvariant:input_type -> cosmos.crisis.v1beta1.MsgVerifyInvariant - 1, // 1: cosmos.crisis.v1beta1.Msg.VerifyInvariant:output_type -> cosmos.crisis.v1beta1.MsgVerifyInvariantResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 4, // 0: cosmos.crisis.v1beta1.MsgUpdateParams.constant_fee:type_name -> cosmos.base.v1beta1.Coin + 0, // 1: cosmos.crisis.v1beta1.Msg.VerifyInvariant:input_type -> cosmos.crisis.v1beta1.MsgVerifyInvariant + 2, // 2: cosmos.crisis.v1beta1.Msg.UpdateParams:input_type -> cosmos.crisis.v1beta1.MsgUpdateParams + 1, // 3: cosmos.crisis.v1beta1.Msg.VerifyInvariant:output_type -> cosmos.crisis.v1beta1.MsgVerifyInvariantResponse + 3, // 4: cosmos.crisis.v1beta1.Msg.UpdateParams:output_type -> cosmos.crisis.v1beta1.MsgUpdateParamsResponse + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_cosmos_crisis_v1beta1_tx_proto_init() } @@ -1116,6 +2079,30 @@ func file_cosmos_crisis_v1beta1_tx_proto_init() { return nil } } + file_cosmos_crisis_v1beta1_tx_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgUpdateParams); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cosmos_crisis_v1beta1_tx_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgUpdateParamsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1123,7 +2110,7 @@ func file_cosmos_crisis_v1beta1_tx_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_cosmos_crisis_v1beta1_tx_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/api/cosmos/crisis/v1beta1/tx_grpc.pb.go b/api/cosmos/crisis/v1beta1/tx_grpc.pb.go index bd137cf2bb2f..bf5162aa0590 100644 --- a/api/cosmos/crisis/v1beta1/tx_grpc.pb.go +++ b/api/cosmos/crisis/v1beta1/tx_grpc.pb.go @@ -24,6 +24,11 @@ const _ = grpc.SupportPackageIsVersion7 type MsgClient interface { // VerifyInvariant defines a method to verify a particular invariance. VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, opts ...grpc.CallOption) (*MsgVerifyInvariantResponse, error) + // UpdateParams defines a governance operation for updating the x/crisis module + // parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -43,12 +48,26 @@ func (c *msgClient) VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/cosmos.crisis.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. // All implementations must embed UnimplementedMsgServer // for forward compatibility type MsgServer interface { // VerifyInvariant defines a method to verify a particular invariance. VerifyInvariant(context.Context, *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) + // UpdateParams defines a governance operation for updating the x/crisis module + // parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) mustEmbedUnimplementedMsgServer() } @@ -59,6 +78,9 @@ type UnimplementedMsgServer struct { func (UnimplementedMsgServer) VerifyInvariant(context.Context, *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VerifyInvariant not implemented") } +func (UnimplementedMsgServer) UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {} // UnsafeMsgServer may be embedded to opt out of forward compatibility for this service. @@ -90,6 +112,24 @@ func _Msg_VerifyInvariant_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.crisis.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + // Msg_ServiceDesc is the grpc.ServiceDesc for Msg service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -101,6 +141,10 @@ var Msg_ServiceDesc = grpc.ServiceDesc{ MethodName: "VerifyInvariant", Handler: _Msg_VerifyInvariant_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/crisis/v1beta1/tx.proto", diff --git a/proto/cosmos/crisis/v1beta1/tx.proto b/proto/cosmos/crisis/v1beta1/tx.proto index fea9059f6f03..02c09f9da9f2 100644 --- a/proto/cosmos/crisis/v1beta1/tx.proto +++ b/proto/cosmos/crisis/v1beta1/tx.proto @@ -6,11 +6,18 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/crisis/types"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; import "cosmos/msg/v1/msg.proto"; +import "cosmos/base/v1beta1/coin.proto"; // Msg defines the bank Msg service. service Msg { // VerifyInvariant defines a method to verify a particular invariance. rpc VerifyInvariant(MsgVerifyInvariant) returns (MsgVerifyInvariantResponse); + + // UpdateParams defines a governance operation for updating the x/crisis module + // parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } // MsgVerifyInvariant represents a message to verify a particular invariance. @@ -27,3 +34,24 @@ message MsgVerifyInvariant { // MsgVerifyInvariantResponse defines the Msg/VerifyInvariant response type. message MsgVerifyInvariantResponse {} + +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // constant_fee defines the x/crisis parameter. + // + // NOTE: All parameters must be supplied. + cosmos.base.v1beta1.Coin constant_fee = 2 [(gogoproto.nullable) = false]; +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +message MsgUpdateParamsResponse {} diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index b1442ff5d465..5c0e89dda171 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -6,6 +6,8 @@ import ( "github.com/tendermint/tendermint/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/cosmos/cosmos-sdk/x/crisis/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -16,6 +18,9 @@ type Keeper struct { routes []types.InvarRoute paramSpace paramtypes.Subspace invCheckPeriod uint + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + authority string supplyKeeper types.SupplyKeeper @@ -24,8 +29,9 @@ type Keeper struct { // NewKeeper creates a new Keeper object func NewKeeper( - paramSpace paramtypes.Subspace, invCheckPeriod uint, supplyKeeper types.SupplyKeeper, - feeCollectorName string, + cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, + invCheckPeriod uint, supplyKeeper types.SupplyKeeper, feeCollectorName string, + authority string, ) *Keeper { // set KeyTable if it has not already been set if !paramSpace.HasKeyTable() { @@ -33,11 +39,14 @@ func NewKeeper( } return &Keeper{ + storeKey: storeKey, + cdc: cdc, routes: make([]types.InvarRoute, 0), paramSpace: paramSpace, invCheckPeriod: invCheckPeriod, supplyKeeper: supplyKeeper, feeCollectorName: feeCollectorName, + authority: authority, } } diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 7e02a370e907..04155d0c8536 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -4,7 +4,9 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/crisis/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) var _ types.MsgServer = &Keeper{} @@ -64,3 +66,14 @@ func (k *Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInva return &types.MsgVerifyInvariantResponse{}, nil } + +func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.authority != req.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.SetConstantFee(ctx, req.ConstantFee) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go new file mode 100644 index 000000000000..077311d13f2e --- /dev/null +++ b/x/crisis/keeper/msg_server_test.go @@ -0,0 +1,144 @@ +package keeper_test + +import "github.com/cosmos/cosmos-sdk/x/mint/types" + +func (s *KeeperTestSuite) TestMsgUpdateParams() { + // default params + communityTax := sdk.NewDecWithPrec(2, 2) // 2% + baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1% + bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4% + withdrawAddrEnabled := true + + testCases := []struct { + name string + input *types.MsgUpdateParams + expErr bool + expErrMsg string + }{ + { + name: "invalid authority", + input: &types.MsgUpdateParams{ + Authority: "invalid", + Params: types.Params{ + CommunityTax: sdk.NewDecWithPrec(2, 0), + BaseProposerReward: baseProposerReward, + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "invalid authority", + }, + { + name: "community tax > 1", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: sdk.NewDecWithPrec(2, 0), + BaseProposerReward: baseProposerReward, + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "community tax should be non-negative and less than one", + }, + { + name: "negative community tax", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: sdk.NewDecWithPrec(-2, 1), + BaseProposerReward: baseProposerReward, + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "community tax should be non-negative and less than one", + }, + { + name: "base proposer reward > 1", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: communityTax, + BaseProposerReward: sdk.NewDecWithPrec(2, 0), + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one", + }, + { + name: "negative base proposer reward", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: communityTax, + BaseProposerReward: sdk.NewDecWithPrec(-2, 0), + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "base proposer reward should be positive", + }, + { + name: "bonus proposer reward > 1", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: communityTax, + BaseProposerReward: baseProposerReward, + BonusProposerReward: sdk.NewDecWithPrec(2, 0), + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one", + }, + { + name: "negative bonus proposer reward", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: communityTax, + BaseProposerReward: baseProposerReward, + BonusProposerReward: sdk.NewDecWithPrec(-2, 0), + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: true, + expErrMsg: "bonus proposer reward should be positive", + }, + { + name: "all good", + input: &types.MsgUpdateParams{ + Authority: s.distrKeeper.GetAuthority(), + Params: types.Params{ + CommunityTax: communityTax, + BaseProposerReward: baseProposerReward, + BonusProposerReward: bonusProposerReward, + WithdrawAddrEnabled: withdrawAddrEnabled, + }, + }, + expErr: false, + }, + } + + for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { + _, err := s.msgServer.UpdateParams(s.ctx, tc.input) + + if tc.expErr { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expErrMsg) + } else { + s.Require().NoError(err) + } + }) + } +} diff --git a/x/crisis/keeper/params.go b/x/crisis/keeper/params.go index 82a42a30896e..8620e9c0fd46 100644 --- a/x/crisis/keeper/params.go +++ b/x/crisis/keeper/params.go @@ -7,11 +7,20 @@ import ( // GetConstantFee get's the constant fee from the paramSpace func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { - k.paramSpace.Get(ctx, types.ParamStoreKeyConstantFee, &constantFee) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConstantFee) + if bz == nil { + return constantFee + } + k.cdc.MustUnmarshal(bz, &constantFee) + // k.paramSpace.Get(ctx, types.ParamStoreKeyConstantFee, &constantFee) return } // GetConstantFee set's the constant fee in the paramSpace func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) { - k.paramSpace.Set(ctx, types.ParamStoreKeyConstantFee, constantFee) + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&constantFee) + store.Set(types.ConstantFee, bz) + // k.paramSpace.Set(ctx, types.ParamStoreKeyConstantFee, constantFee) } diff --git a/x/crisis/module.go b/x/crisis/module.go index 8afbf8d89c0d..e54e418d850b 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" + store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -26,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" "github.com/cosmos/cosmos-sdk/x/crisis/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -187,6 +189,8 @@ type crisisInputs struct { depinject.In Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec AppOpts servertypes.AppOptions `optional:"true"` Subspace paramstypes.Subspace BankKeeper types.SupplyKeeper @@ -212,10 +216,13 @@ func provideModule(in crisisInputs) crisisOutputs { } k := keeper.NewKeeper( + in.Cdc, + in.Key, in.Subspace, invalidCheckPeriod, in.BankKeeper, feeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) skipGenesisInvariants := cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants)) diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 324ef56891ea..8df1ab46762e 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -14,11 +14,13 @@ import ( // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant") + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/crisis/MsgUpdateParams") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgVerifyInvariant{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/crisis/types/keys.go b/x/crisis/types/keys.go index 8f009eda4148..449f4f5ba8fa 100644 --- a/x/crisis/types/keys.go +++ b/x/crisis/types/keys.go @@ -3,4 +3,10 @@ package types const ( // module name ModuleName = "crisis" + + StoreKey = ModuleName +) + +var ( + ConstantFee = []byte("ConstantFee") ) diff --git a/x/crisis/types/params.go b/x/crisis/types/legacy_params.go similarity index 100% rename from x/crisis/types/params.go rename to x/crisis/types/legacy_params.go diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index a5450b010e7f..8b933586d559 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -5,8 +5,13 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +const ( + TypeMsgVerifyInvariant = "verify_invariant" + TypeMsgUpdateParams = "update_params" +) + // ensure Msg interface compliance at compile time -var _ sdk.Msg = &MsgVerifyInvariant{} +var _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object //nolint:interfacer @@ -19,7 +24,7 @@ func NewMsgVerifyInvariant(sender sdk.AccAddress, invModeName, invRoute string) } func (msg MsgVerifyInvariant) Route() string { return ModuleName } -func (msg MsgVerifyInvariant) Type() string { return "verify_invariant" } +func (msg MsgVerifyInvariant) Type() string { return TypeMsgVerifyInvariant } // get the bytes for the message signer to sign on func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress { @@ -45,3 +50,33 @@ func (msg MsgVerifyInvariant) ValidateBasic() error { func (msg MsgVerifyInvariant) FullInvariantRoute() string { return msg.InvariantModuleName + "/" + msg.InvariantRoute } + +func (msg MsgUpdateParams) Route() string { return ModuleName } +func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } + +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes. +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{authority} +} + +// GetSignBytes returns the raw bytes for a MsgUpdateParams message that +// the expected signer needs to sign. +func (msg MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic MsgUpdateParams message validation. +func (msg MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.Wrap(err, "invalid authority address") + } + + if !msg.ConstantFee.IsValid() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "invalid costant fee") + } + + return nil +} diff --git a/x/crisis/types/tx.pb.go b/x/crisis/types/tx.pb.go index 412311aace83..de1d9e434022 100644 --- a/x/crisis/types/tx.pb.go +++ b/x/crisis/types/tx.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" @@ -107,37 +108,146 @@ func (m *MsgVerifyInvariantResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVerifyInvariantResponse proto.InternalMessageInfo +// MsgUpdateParams is the Msg/UpdateParams request type. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParams struct { + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // constant_fee defines the x/crisis parameter. + // + // NOTE: All parameters must be supplied. + ConstantFee types.Coin `protobuf:"bytes,2,opt,name=constant_fee,json=constantFee,proto3" json:"constant_fee"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_61276163172fe867, []int{2} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.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 *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetConstantFee() types.Coin { + if m != nil { + return m.ConstantFee + } + return types.Coin{} +} + +// MsgUpdateParamsResponse defines the response structure for executing a +// MsgUpdateParams message. +// +// Since: cosmos-sdk 0.47 +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_61276163172fe867, []int{3} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.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 *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgVerifyInvariant)(nil), "cosmos.crisis.v1beta1.MsgVerifyInvariant") proto.RegisterType((*MsgVerifyInvariantResponse)(nil), "cosmos.crisis.v1beta1.MsgVerifyInvariantResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "cosmos.crisis.v1beta1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "cosmos.crisis.v1beta1.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("cosmos/crisis/v1beta1/tx.proto", fileDescriptor_61276163172fe867) } var fileDescriptor_61276163172fe867 = []byte{ - // 342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x4f, 0x2e, 0xca, 0x2c, 0xce, 0x2c, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, - 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0xc8, 0xeb, 0x41, - 0xe4, 0xf5, 0xa0, 0xf2, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x15, 0xfa, 0x20, 0x16, 0x44, - 0xb1, 0x94, 0x24, 0x44, 0x71, 0x3c, 0x44, 0x02, 0xaa, 0x13, 0x22, 0x25, 0x0e, 0xb5, 0x27, 0xb7, - 0x38, 0x5d, 0xbf, 0xcc, 0x10, 0x44, 0x41, 0x24, 0x94, 0x76, 0x30, 0x72, 0x09, 0xf9, 0x16, 0xa7, - 0x87, 0xa5, 0x16, 0x65, 0xa6, 0x55, 0x7a, 0xe6, 0x95, 0x25, 0x16, 0x65, 0x26, 0xe6, 0x95, 0x08, - 0x19, 0x70, 0xb1, 0x15, 0xa7, 0xe6, 0xa5, 0xa4, 0x16, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x3a, - 0x49, 0x5c, 0xda, 0xa2, 0x2b, 0x02, 0x35, 0xd1, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x38, 0xb8, - 0xa4, 0x28, 0x33, 0x2f, 0x3d, 0x08, 0xaa, 0x4e, 0xc8, 0x88, 0x4b, 0x34, 0x13, 0xa6, 0x3d, 0x3e, - 0x37, 0x3f, 0xa5, 0x34, 0x27, 0x35, 0x3e, 0x2f, 0x31, 0x37, 0x55, 0x82, 0x09, 0x64, 0x40, 0x90, - 0x30, 0x5c, 0xd2, 0x17, 0x2c, 0xe7, 0x97, 0x98, 0x9b, 0x2a, 0xa4, 0xce, 0xc5, 0x8f, 0xd0, 0x53, - 0x94, 0x5f, 0x5a, 0x92, 0x2a, 0xc1, 0x0c, 0x56, 0xcd, 0x07, 0x17, 0x0e, 0x02, 0x89, 0x5a, 0x09, - 0x77, 0x2c, 0x90, 0x67, 0x78, 0xb1, 0x40, 0x9e, 0xa1, 0xe9, 0xf9, 0x06, 0x2d, 0xa8, 0x8d, 0x4a, - 0x32, 0x5c, 0x52, 0x98, 0x2e, 0x0f, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x35, 0x2a, 0xe3, - 0x62, 0xf6, 0x2d, 0x4e, 0x17, 0xca, 0xe7, 0xe2, 0x47, 0xf7, 0x9b, 0xa6, 0x1e, 0xd6, 0x40, 0xd5, - 0xc3, 0x34, 0x4c, 0xca, 0x90, 0x68, 0xa5, 0x30, 0x7b, 0x9d, 0x5c, 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, 0x3b, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, - 0x57, 0x1f, 0x16, 0xed, 0x60, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0x96, 0x06, 0x4a, 0x2a, - 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xd1, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x69, 0x76, - 0x6c, 0x9d, 0x21, 0x02, 0x00, 0x00, + // 467 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xbf, 0x6f, 0x13, 0x31, + 0x14, 0xbe, 0xa3, 0xa8, 0x52, 0xdd, 0xaa, 0x91, 0xdc, 0x56, 0x4d, 0x4e, 0xe8, 0x82, 0x32, 0xf0, + 0x53, 0xf5, 0x91, 0x20, 0x31, 0x74, 0x23, 0x08, 0x24, 0x86, 0x20, 0x74, 0x08, 0x06, 0x96, 0xc8, + 0xb9, 0x7b, 0xb9, 0x5a, 0x70, 0x76, 0xe4, 0xe7, 0x44, 0xcd, 0xca, 0xc4, 0xc8, 0x3f, 0x80, 0xd4, + 0x3f, 0x81, 0x81, 0x81, 0x3f, 0xa1, 0x63, 0xc5, 0xc4, 0x54, 0xa1, 0x64, 0x80, 0x3f, 0x03, 0xdd, + 0x9d, 0x9d, 0x40, 0x0b, 0x22, 0x93, 0x2d, 0x7f, 0xdf, 0xf7, 0xbe, 0xcf, 0xcf, 0x7e, 0x24, 0x4c, + 0x14, 0xe6, 0x0a, 0xa3, 0x44, 0x0b, 0x14, 0x18, 0x4d, 0xda, 0x03, 0x30, 0xbc, 0x1d, 0x99, 0x63, + 0x36, 0xd2, 0xca, 0x28, 0xba, 0x57, 0xe1, 0xac, 0xc2, 0x99, 0xc5, 0x83, 0xdd, 0x4c, 0x65, 0xaa, + 0x64, 0x44, 0xc5, 0xae, 0x22, 0x07, 0x8d, 0x8a, 0xdc, 0xaf, 0x00, 0xab, 0xac, 0xa0, 0x7d, 0xeb, + 0x93, 0x63, 0x16, 0x4d, 0xda, 0xc5, 0x62, 0x01, 0x17, 0x60, 0xc0, 0x11, 0x16, 0xf6, 0x89, 0x12, + 0xb2, 0xc2, 0x5b, 0x5f, 0x7c, 0x42, 0x7b, 0x98, 0xbd, 0x02, 0x2d, 0x86, 0xd3, 0xa7, 0x72, 0xc2, + 0xb5, 0xe0, 0xd2, 0xd0, 0x7b, 0x64, 0x1d, 0x41, 0xa6, 0xa0, 0xeb, 0xfe, 0x75, 0xff, 0xd6, 0x46, + 0xb7, 0xfe, 0xf5, 0xf3, 0xc1, 0xae, 0x75, 0x7c, 0x98, 0xa6, 0x1a, 0x10, 0x5f, 0x18, 0x2d, 0x64, + 0x16, 0x5b, 0x1e, 0xed, 0x90, 0x3d, 0xe1, 0xe4, 0xfd, 0x5c, 0xa5, 0xe3, 0xb7, 0xd0, 0x97, 0x3c, + 0x87, 0xfa, 0x95, 0xa2, 0x40, 0xbc, 0xb3, 0x00, 0x7b, 0x25, 0xf6, 0x8c, 0xe7, 0x40, 0x6f, 0x92, + 0xda, 0x52, 0xa3, 0xd5, 0xd8, 0x40, 0x7d, 0xad, 0x64, 0x6f, 0x2f, 0x8e, 0xe3, 0xe2, 0xf4, 0x70, + 0xe7, 0xfd, 0x49, 0xd3, 0xfb, 0x79, 0xd2, 0xf4, 0xde, 0xfd, 0xf8, 0x74, 0xc7, 0x3a, 0xb6, 0xae, + 0x91, 0xe0, 0x72, 0xf2, 0x18, 0x70, 0xa4, 0x24, 0x42, 0xeb, 0xa3, 0x4f, 0x6a, 0x3d, 0xcc, 0x5e, + 0x8e, 0x52, 0x6e, 0xe0, 0x39, 0xd7, 0x3c, 0x47, 0xfa, 0x80, 0x6c, 0xf0, 0xb1, 0x39, 0x52, 0x5a, + 0x98, 0xe9, 0x7f, 0x2f, 0xb6, 0xa4, 0xd2, 0x2e, 0xd9, 0x4a, 0x94, 0x44, 0x53, 0xc4, 0x1c, 0x42, + 0x75, 0xa5, 0xcd, 0x4e, 0x83, 0x59, 0x5d, 0xd1, 0x5b, 0xf7, 0x74, 0xec, 0x91, 0x12, 0xb2, 0x7b, + 0xf5, 0xf4, 0xbc, 0xe9, 0xc5, 0x9b, 0x4e, 0xf4, 0x04, 0xe0, 0x70, 0xbb, 0x88, 0xbe, 0xac, 0xd9, + 0x6a, 0x90, 0xfd, 0x0b, 0xf1, 0x5c, 0xf4, 0xce, 0xb9, 0x4f, 0xd6, 0x7a, 0x98, 0x51, 0x45, 0x6a, + 0x17, 0xdf, 0xe5, 0x36, 0xfb, 0xeb, 0x87, 0x61, 0x97, 0x1b, 0x11, 0xb4, 0x57, 0xa6, 0x3a, 0x63, + 0x3a, 0x24, 0x5b, 0x7f, 0xf4, 0xeb, 0xc6, 0xbf, 0x4b, 0xfc, 0xce, 0x0b, 0xd8, 0x6a, 0x3c, 0xe7, + 0xd3, 0x7d, 0x7c, 0x3a, 0x0b, 0xfd, 0xb3, 0x59, 0xe8, 0x7f, 0x9f, 0x85, 0xfe, 0x87, 0x79, 0xe8, + 0x9d, 0xcd, 0x43, 0xef, 0xdb, 0x3c, 0xf4, 0x5e, 0xdf, 0xcd, 0x84, 0x39, 0x1a, 0x0f, 0x58, 0xa2, + 0xf2, 0xc8, 0x8d, 0x4e, 0xb9, 0x1c, 0x60, 0xfa, 0x26, 0x3a, 0x76, 0x73, 0x64, 0xa6, 0x23, 0xc0, + 0xc1, 0x7a, 0xf9, 0x85, 0xef, 0xff, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x34, 0x0c, 0xab, 0x77, 0x65, + 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -154,6 +264,11 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // VerifyInvariant defines a method to verify a particular invariance. VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, opts ...grpc.CallOption) (*MsgVerifyInvariantResponse, error) + // UpdateParams defines a governance operation for updating the x/crisis module + // parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -173,10 +288,24 @@ func (c *msgClient) VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/cosmos.crisis.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // VerifyInvariant defines a method to verify a particular invariance. VerifyInvariant(context.Context, *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) + // UpdateParams defines a governance operation for updating the x/crisis module + // parameters. The authority is defined in the keeper. + // + // Since: cosmos-sdk 0.47 + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -186,6 +315,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) VerifyInvariant(ctx context.Context, req *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VerifyInvariant not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -209,6 +341,24 @@ func _Msg_VerifyInvariant_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.crisis.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.crisis.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -217,6 +367,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "VerifyInvariant", Handler: _Msg_VerifyInvariant_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/crisis/v1beta1/tx.proto", @@ -289,6 +443,69 @@ func (m *MsgVerifyInvariantResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *MsgUpdateParams) 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 *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.ConstantFee.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 *MsgUpdateParamsResponse) 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 *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) 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 @@ -330,6 +547,30 @@ func (m *MsgVerifyInvariantResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) 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.ConstantFee.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) 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 } @@ -532,6 +773,171 @@ func (m *MsgVerifyInvariantResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) 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: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: 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 ConstantFee", 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.ConstantFee.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 *MsgUpdateParamsResponse) 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: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: 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 From 4612c9f5cbcb6250627a364c957d71cc9f8676be Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 8 Jul 2022 11:34:10 +0530 Subject: [PATCH 02/13] add msg server tests --- x/crisis/keeper/keeper.go | 4 + x/crisis/keeper/msg_server.go | 5 + x/crisis/keeper/msg_server_test.go | 141 +++++++++-------------------- 3 files changed, 50 insertions(+), 100 deletions(-) diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index 5c0e89dda171..9997469b8c30 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -27,6 +27,10 @@ type Keeper struct { feeCollectorName string // name of the FeeCollector ModuleAccount } +func (k *Keeper) GetAuthority() string { + return k.authority +} + // NewKeeper creates a new Keeper object func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 04155d0c8536..0f597d779585 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/crisis/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -72,6 +73,10 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) } + if !req.ConstantFee.IsValid() { + return nil, errors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid costant fee") + } + ctx := sdk.UnwrapSDKContext(goCtx) k.SetConstantFee(ctx, req.ConstantFee) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 077311d13f2e..40b0d733bb01 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -1,13 +1,36 @@ package keeper_test -import "github.com/cosmos/cosmos-sdk/x/mint/types" +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +type KeeperTestSuite struct { + suite.Suite + + app *simapp.SimApp + ctx sdk.Context + keeper keeper.Keeper +} + +func (s *KeeperTestSuite) SetupSuite(t *testing.T) { + app := simapp.Setup(t, false) + ctx := app.NewContext(true, tmproto.Header{}) + + s.app = app + s.ctx = ctx + s.keeper = *app.CrisisKeeper +} func (s *KeeperTestSuite) TestMsgUpdateParams() { // default params - communityTax := sdk.NewDecWithPrec(2, 2) // 2% - baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1% - bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4% - withdrawAddrEnabled := true + constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% testCases := []struct { name string @@ -18,111 +41,25 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { { name: "invalid authority", input: &types.MsgUpdateParams{ - Authority: "invalid", - Params: types.Params{ - CommunityTax: sdk.NewDecWithPrec(2, 0), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, + Authority: "invalid", + ConstantFee: constantFee, }, expErr: true, expErrMsg: "invalid authority", }, { - name: "community tax > 1", - input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: sdk.NewDecWithPrec(2, 0), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - }, - expErr: true, - expErrMsg: "community tax should be non-negative and less than one", - }, - { - name: "negative community tax", + name: "invalid constant fee", input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: sdk.NewDecWithPrec(-2, 1), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, + Authority: s.keeper.GetAuthority(), + ConstantFee: sdk.Coin{}, }, - expErr: true, - expErrMsg: "community tax should be non-negative and less than one", - }, - { - name: "base proposer reward > 1", - input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: sdk.NewDecWithPrec(2, 0), - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - }, - expErr: true, - expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one", - }, - { - name: "negative base proposer reward", - input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: sdk.NewDecWithPrec(-2, 0), - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - }, - expErr: true, - expErrMsg: "base proposer reward should be positive", - }, - { - name: "bonus proposer reward > 1", - input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: sdk.NewDecWithPrec(2, 0), - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - }, - expErr: true, - expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one", - }, - { - name: "negative bonus proposer reward", - input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: sdk.NewDecWithPrec(-2, 0), - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - }, - expErr: true, - expErrMsg: "bonus proposer reward should be positive", + expErr: true, }, { name: "all good", input: &types.MsgUpdateParams{ - Authority: s.distrKeeper.GetAuthority(), - Params: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, + Authority: s.keeper.GetAuthority(), + ConstantFee: constantFee, }, expErr: false, }, @@ -131,7 +68,7 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - _, err := s.msgServer.UpdateParams(s.ctx, tc.input) + _, err := s.keeper.UpdateParams(s.ctx, tc.input) if tc.expErr { s.Require().Error(err) @@ -142,3 +79,7 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { }) } } + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} From 244083893e1af9ef6f6165124a2a87a390b351cb Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 8 Jul 2022 11:35:31 +0530 Subject: [PATCH 03/13] review changes --- x/crisis/keeper/msg_server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 0f597d779585..3247df4460b4 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/crisis/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -74,7 +73,7 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) } if !req.ConstantFee.IsValid() { - return nil, errors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid costant fee") + return nil, errors.ErrInvalidCoins.Wrap("invalid costant fee") } ctx := sdk.UnwrapSDKContext(goCtx) From 068a10a1f6e6e9dc0178168a22f1bc0782f7e89e Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 8 Jul 2022 14:56:12 +0530 Subject: [PATCH 04/13] add tests --- x/crisis/keeper/genesis.go | 5 +++- x/crisis/keeper/msg_server.go | 6 +++- x/crisis/keeper/msg_server_test.go | 18 ++++++++---- x/crisis/keeper/params.go | 22 +++++++++++--- x/crisis/keeper/params_test.go | 47 ++++++++++++++++++++++++++++++ x/crisis/module.go | 1 + x/crisis/testutil/app.yaml | 47 ++++++++++++++++++++++++++++++ x/crisis/testutil/app_config.go | 19 ++++++++++++ 8 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 x/crisis/keeper/params_test.go create mode 100644 x/crisis/testutil/app.yaml create mode 100644 x/crisis/testutil/app_config.go diff --git a/x/crisis/keeper/genesis.go b/x/crisis/keeper/genesis.go index f8553bbbd55b..4885221ace7e 100644 --- a/x/crisis/keeper/genesis.go +++ b/x/crisis/keeper/genesis.go @@ -7,7 +7,10 @@ import ( // new crisis genesis func (k *Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { - k.SetConstantFee(ctx, data.ConstantFee) + if err := k.SetConstantFee(ctx, data.ConstantFee); err != nil { + panic(err) + } + } // ExportGenesis returns a GenesisState for a given context and keeper. diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 3247df4460b4..2a02ad72a76f 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" @@ -77,7 +78,10 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) } ctx := sdk.UnwrapSDKContext(goCtx) - k.SetConstantFee(ctx, req.ConstantFee) + if err := k.SetConstantFee(ctx, req.ConstantFee); err != nil { + fmt.Printf("err::::::::::::::::::::::::::::::::::: %v\n", err) + return nil, err + } return &types.MsgUpdateParamsResponse{}, nil } diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 40b0d733bb01..cfad954cb1f5 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -3,29 +3,37 @@ package keeper_test import ( "testing" - "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + "github.com/cosmos/cosmos-sdk/x/crisis/testutil" "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) type KeeperTestSuite struct { suite.Suite - app *simapp.SimApp + // app *simapp.SimApp ctx sdk.Context keeper keeper.Keeper } func (s *KeeperTestSuite) SetupSuite(t *testing.T) { - app := simapp.Setup(t, false) + app, err := simtestutil.Setup(testutil.AppConfig, + &s.keeper, + ) + s.Require().NoError(err) + + // app := simapp.Setup(t, false) + app.Commit() + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) ctx := app.NewContext(true, tmproto.Header{}) - s.app = app + // s.app = app s.ctx = ctx - s.keeper = *app.CrisisKeeper } func (s *KeeperTestSuite) TestMsgUpdateParams() { diff --git a/x/crisis/keeper/params.go b/x/crisis/keeper/params.go index 8620e9c0fd46..badeae940311 100644 --- a/x/crisis/keeper/params.go +++ b/x/crisis/keeper/params.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) @@ -13,14 +15,26 @@ func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { return constantFee } k.cdc.MustUnmarshal(bz, &constantFee) - // k.paramSpace.Get(ctx, types.ParamStoreKeyConstantFee, &constantFee) return } // GetConstantFee set's the constant fee in the paramSpace -func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) { +func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) error { + fmt.Printf("\"0\": %v\n", "0") + fmt.Printf("k.storeKey: %v\n", k.storeKey) + store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&constantFee) + fmt.Println("1") + bz, err := k.cdc.Marshal(&constantFee) + fmt.Println("2") + + if err != nil { + fmt.Printf("\"3\": %v\n", "3") + + return err + } + fmt.Printf("\"4\": %v\n", "4") store.Set(types.ConstantFee, bz) - // k.paramSpace.Set(ctx, types.ParamStoreKeyConstantFee, constantFee) + fmt.Printf("\"5\": %v\n", "5") + return nil } diff --git a/x/crisis/keeper/params_test.go b/x/crisis/keeper/params_test.go new file mode 100644 index 000000000000..78fdd0c2ffb5 --- /dev/null +++ b/x/crisis/keeper/params_test.go @@ -0,0 +1,47 @@ +package keeper_test + +// import ( +// sdk "github.com/cosmos/cosmos-sdk/types" +// ) + +// func (s *KeeperTestSuite) TestParams() { +// // default params +// constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% + +// testCases := []struct { +// name string +// constantFee sdk.Coin +// expErr bool +// expErrMsg string +// }{ +// { +// name: "invalid constant fee", +// constantFee: sdk.Coin{}, +// expErr: true, +// }, +// { +// name: "all good", +// constantFee: constantFee, +// expErr: false, +// }, +// } + +// for _, tc := range testCases { +// tc := tc +// s.Run(tc.name, func() { +// expected := s.app.CrisisKeeper.GetConstantFee(s.ctx) +// err := s.app.CrisisKeeper.SetConstantFee(s.ctx, tc.constantFee) + +// if tc.expErr { +// s.Require().Error(err) +// s.Require().Contains(err.Error(), tc.expErrMsg) +// } else { +// expected = tc.constantFee +// s.Require().NoError(err) +// } + +// params := s.app.CrisisKeeper.GetConstantFee(s.ctx) +// s.Require().Equal(expected, params) +// }) +// } +// } diff --git a/x/crisis/module.go b/x/crisis/module.go index e54e418d850b..e02e719921ae 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -215,6 +215,7 @@ func provideModule(in crisisInputs) crisisOutputs { feeCollectorName = authtypes.FeeCollectorName } + fmt.Printf("in.Key: %v\n", in.Key) k := keeper.NewKeeper( in.Cdc, in.Key, diff --git a/x/crisis/testutil/app.yaml b/x/crisis/testutil/app.yaml new file mode 100644 index 000000000000..ddcdd200e9ce --- /dev/null +++ b/x/crisis/testutil/app.yaml @@ -0,0 +1,47 @@ +modules: + - name: runtime + config: + "@type": cosmos.app.runtime.v1alpha1.Module + + app_name: MintApp + + begin_blockers: [crisis, staking, auth, bank, genutil, params] + end_blockers: [staking, auth, bank, crisis, genutil, params] + init_genesis: [auth, bank, staking, crisis, genutil, params] + + - name: auth + config: + "@type": cosmos.auth.module.v1.Module + bech32_prefix: cosmos + module_account_permissions: + - account: fee_collector + - account: mint + permissions: [minter] + - account: bonded_tokens_pool + permissions: [burner, staking] + - account: not_bonded_tokens_pool + permissions: [burner, staking] + + - name: bank + config: + "@type": cosmos.bank.module.v1.Module + + - name: params + config: + "@type": cosmos.params.module.v1.Module + + - name: tx + config: + "@type": cosmos.tx.module.v1.Module + + - name: staking + config: + "@type": cosmos.staking.module.v1.Module + + - name: genutil + config: + "@type": cosmos.genutil.module.v1.Module + + - name: crisis + config: + "@type": cosmos.crisis.module.v1.Module diff --git a/x/crisis/testutil/app_config.go b/x/crisis/testutil/app_config.go new file mode 100644 index 000000000000..c36f4677a997 --- /dev/null +++ b/x/crisis/testutil/app_config.go @@ -0,0 +1,19 @@ +package testutil + +import ( + _ "embed" + + "cosmossdk.io/core/appconfig" + _ "github.com/cosmos/cosmos-sdk/x/auth" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" + _ "github.com/cosmos/cosmos-sdk/x/bank" + _ "github.com/cosmos/cosmos-sdk/x/crisis" + _ "github.com/cosmos/cosmos-sdk/x/genutil" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" +) + +//go:embed app.yaml +var appConfig []byte + +var AppConfig = appconfig.LoadYAML(appConfig) From fe05ed85e9ca294a7c3718e2706a46202b77c7c5 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 14:48:35 +0530 Subject: [PATCH 05/13] review --- x/crisis/testutil/app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/crisis/testutil/app.yaml b/x/crisis/testutil/app.yaml index ddcdd200e9ce..62d062929082 100644 --- a/x/crisis/testutil/app.yaml +++ b/x/crisis/testutil/app.yaml @@ -3,7 +3,7 @@ modules: config: "@type": cosmos.app.runtime.v1alpha1.Module - app_name: MintApp + app_name: CrisisApp begin_blockers: [crisis, staking, auth, bank, genutil, params] end_blockers: [staking, auth, bank, crisis, genutil, params] From 3dd14feba8853795382b2d72ff8a63d919c4c1c7 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 15:06:29 +0530 Subject: [PATCH 06/13] fix tests --- x/crisis/keeper/msg_server_test.go | 21 +++++-------- x/crisis/keeper/params.go | 12 +------- x/crisis/testutil/app.yaml | 47 ------------------------------ x/crisis/testutil/app_config.go | 19 ------------ 4 files changed, 9 insertions(+), 90 deletions(-) delete mode 100644 x/crisis/testutil/app.yaml delete mode 100644 x/crisis/testutil/app_config.go diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index cfad954cb1f5..1fa7f1ba9850 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -3,10 +3,9 @@ package keeper_test import ( "testing" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" - "github.com/cosmos/cosmos-sdk/x/crisis/testutil" "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" @@ -16,29 +15,25 @@ import ( type KeeperTestSuite struct { suite.Suite - // app *simapp.SimApp + app *simapp.SimApp ctx sdk.Context - keeper keeper.Keeper + keeper *keeper.Keeper } -func (s *KeeperTestSuite) SetupSuite(t *testing.T) { - app, err := simtestutil.Setup(testutil.AppConfig, - &s.keeper, - ) - s.Require().NoError(err) - - // app := simapp.Setup(t, false) +func (s *KeeperTestSuite) SetupTest() { + app := simapp.Setup(s.T(), false) app.Commit() app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) ctx := app.NewContext(true, tmproto.Header{}) - // s.app = app + s.app = app s.ctx = ctx + s.keeper = app.CrisisKeeper } func (s *KeeperTestSuite) TestMsgUpdateParams() { // default params - constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% + constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) testCases := []struct { name string diff --git a/x/crisis/keeper/params.go b/x/crisis/keeper/params.go index badeae940311..da2a35d023a3 100644 --- a/x/crisis/keeper/params.go +++ b/x/crisis/keeper/params.go @@ -1,8 +1,6 @@ package keeper import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) @@ -20,21 +18,13 @@ func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { // GetConstantFee set's the constant fee in the paramSpace func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) error { - fmt.Printf("\"0\": %v\n", "0") - fmt.Printf("k.storeKey: %v\n", k.storeKey) - store := ctx.KVStore(k.storeKey) - fmt.Println("1") bz, err := k.cdc.Marshal(&constantFee) - fmt.Println("2") if err != nil { - fmt.Printf("\"3\": %v\n", "3") - return err } - fmt.Printf("\"4\": %v\n", "4") + store.Set(types.ConstantFee, bz) - fmt.Printf("\"5\": %v\n", "5") return nil } diff --git a/x/crisis/testutil/app.yaml b/x/crisis/testutil/app.yaml deleted file mode 100644 index 62d062929082..000000000000 --- a/x/crisis/testutil/app.yaml +++ /dev/null @@ -1,47 +0,0 @@ -modules: - - name: runtime - config: - "@type": cosmos.app.runtime.v1alpha1.Module - - app_name: CrisisApp - - begin_blockers: [crisis, staking, auth, bank, genutil, params] - end_blockers: [staking, auth, bank, crisis, genutil, params] - init_genesis: [auth, bank, staking, crisis, genutil, params] - - - name: auth - config: - "@type": cosmos.auth.module.v1.Module - bech32_prefix: cosmos - module_account_permissions: - - account: fee_collector - - account: mint - permissions: [minter] - - account: bonded_tokens_pool - permissions: [burner, staking] - - account: not_bonded_tokens_pool - permissions: [burner, staking] - - - name: bank - config: - "@type": cosmos.bank.module.v1.Module - - - name: params - config: - "@type": cosmos.params.module.v1.Module - - - name: tx - config: - "@type": cosmos.tx.module.v1.Module - - - name: staking - config: - "@type": cosmos.staking.module.v1.Module - - - name: genutil - config: - "@type": cosmos.genutil.module.v1.Module - - - name: crisis - config: - "@type": cosmos.crisis.module.v1.Module diff --git a/x/crisis/testutil/app_config.go b/x/crisis/testutil/app_config.go deleted file mode 100644 index c36f4677a997..000000000000 --- a/x/crisis/testutil/app_config.go +++ /dev/null @@ -1,19 +0,0 @@ -package testutil - -import ( - _ "embed" - - "cosmossdk.io/core/appconfig" - _ "github.com/cosmos/cosmos-sdk/x/auth" - _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" - _ "github.com/cosmos/cosmos-sdk/x/bank" - _ "github.com/cosmos/cosmos-sdk/x/crisis" - _ "github.com/cosmos/cosmos-sdk/x/genutil" - _ "github.com/cosmos/cosmos-sdk/x/params" - _ "github.com/cosmos/cosmos-sdk/x/staking" -) - -//go:embed app.yaml -var appConfig []byte - -var AppConfig = appconfig.LoadYAML(appConfig) From 3bd2428ad801e22756bb51cc43d4f7e7863fd2b5 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 15:14:18 +0530 Subject: [PATCH 07/13] fix tests --- x/crisis/keeper/msg_server.go | 4 +- x/crisis/keeper/params_test.go | 75 ++++++++++++++++------------------ 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 2a02ad72a76f..5cb0dacfb8cc 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" @@ -74,12 +73,11 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) } if !req.ConstantFee.IsValid() { - return nil, errors.ErrInvalidCoins.Wrap("invalid costant fee") + return nil, errors.ErrInvalidCoins.Wrap("invalid constant fee") } ctx := sdk.UnwrapSDKContext(goCtx) if err := k.SetConstantFee(ctx, req.ConstantFee); err != nil { - fmt.Printf("err::::::::::::::::::::::::::::::::::: %v\n", err) return nil, err } diff --git a/x/crisis/keeper/params_test.go b/x/crisis/keeper/params_test.go index 78fdd0c2ffb5..270c1ef470d5 100644 --- a/x/crisis/keeper/params_test.go +++ b/x/crisis/keeper/params_test.go @@ -1,47 +1,42 @@ package keeper_test -// import ( -// sdk "github.com/cosmos/cosmos-sdk/types" -// ) +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) -// func (s *KeeperTestSuite) TestParams() { -// // default params -// constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% +func (s *KeeperTestSuite) TestParams() { + // default params + constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% -// testCases := []struct { -// name string -// constantFee sdk.Coin -// expErr bool -// expErrMsg string -// }{ -// { -// name: "invalid constant fee", -// constantFee: sdk.Coin{}, -// expErr: true, -// }, -// { -// name: "all good", -// constantFee: constantFee, -// expErr: false, -// }, -// } + testCases := []struct { + name string + constantFee sdk.Coin + expErr bool + expErrMsg string + }{ + { + name: "all good", + constantFee: constantFee, + expErr: false, + }, + } -// for _, tc := range testCases { -// tc := tc -// s.Run(tc.name, func() { -// expected := s.app.CrisisKeeper.GetConstantFee(s.ctx) -// err := s.app.CrisisKeeper.SetConstantFee(s.ctx, tc.constantFee) + for _, tc := range testCases { + tc := tc + s.Run(tc.name, func() { + expected := s.app.CrisisKeeper.GetConstantFee(s.ctx) + err := s.app.CrisisKeeper.SetConstantFee(s.ctx, tc.constantFee) -// if tc.expErr { -// s.Require().Error(err) -// s.Require().Contains(err.Error(), tc.expErrMsg) -// } else { -// expected = tc.constantFee -// s.Require().NoError(err) -// } + if tc.expErr { + s.Require().Error(err) + s.Require().Contains(err.Error(), tc.expErrMsg) + } else { + expected = tc.constantFee + s.Require().NoError(err) + } -// params := s.app.CrisisKeeper.GetConstantFee(s.ctx) -// s.Require().Equal(expected, params) -// }) -// } -// } + params := s.app.CrisisKeeper.GetConstantFee(s.ctx) + s.Require().Equal(expected, params) + }) + } +} From 3d4e0423e30529c6c199c92bb3f6a5cefbef5065 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 15:16:57 +0530 Subject: [PATCH 08/13] review --- x/crisis/keeper/msg_server_test.go | 2 -- x/crisis/keeper/params_test.go | 6 +++--- x/crisis/module.go | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index 1fa7f1ba9850..c1de220be327 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -15,7 +15,6 @@ import ( type KeeperTestSuite struct { suite.Suite - app *simapp.SimApp ctx sdk.Context keeper *keeper.Keeper } @@ -26,7 +25,6 @@ func (s *KeeperTestSuite) SetupTest() { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) ctx := app.NewContext(true, tmproto.Header{}) - s.app = app s.ctx = ctx s.keeper = app.CrisisKeeper } diff --git a/x/crisis/keeper/params_test.go b/x/crisis/keeper/params_test.go index 270c1ef470d5..adce9dc34db4 100644 --- a/x/crisis/keeper/params_test.go +++ b/x/crisis/keeper/params_test.go @@ -24,8 +24,8 @@ func (s *KeeperTestSuite) TestParams() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - expected := s.app.CrisisKeeper.GetConstantFee(s.ctx) - err := s.app.CrisisKeeper.SetConstantFee(s.ctx, tc.constantFee) + expected := s.keeper.GetConstantFee(s.ctx) + err := s.keeper.SetConstantFee(s.ctx, tc.constantFee) if tc.expErr { s.Require().Error(err) @@ -35,7 +35,7 @@ func (s *KeeperTestSuite) TestParams() { s.Require().NoError(err) } - params := s.app.CrisisKeeper.GetConstantFee(s.ctx) + params := s.keeper.GetConstantFee(s.ctx) s.Require().Equal(expected, params) }) } diff --git a/x/crisis/module.go b/x/crisis/module.go index 52fc19c2c16b..a17aa0550147 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -215,7 +215,6 @@ func provideModule(in crisisInputs) crisisOutputs { feeCollectorName = authtypes.FeeCollectorName } - fmt.Printf("in.Key: %v\n", in.Key) k := keeper.NewKeeper( in.Cdc, in.Key, From befbbc0e76c0823ea8804030aacea578315324d7 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 15:41:08 +0530 Subject: [PATCH 09/13] fix tests --- x/crisis/keeper/params.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x/crisis/keeper/params.go b/x/crisis/keeper/params.go index da2a35d023a3..92d8f29f6633 100644 --- a/x/crisis/keeper/params.go +++ b/x/crisis/keeper/params.go @@ -2,10 +2,11 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) -// GetConstantFee get's the constant fee from the paramSpace +// GetConstantFee get's the constant fee from the store func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.ConstantFee) @@ -16,11 +17,15 @@ func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { return } -// GetConstantFee set's the constant fee in the paramSpace +// GetConstantFee set's the constant fee in the store func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) error { store := ctx.KVStore(k.storeKey) bz, err := k.cdc.Marshal(&constantFee) + if !constantFee.IsValid() { + return errors.ErrInvalidCoins.Wrap("invalid constant fee") + } + if err != nil { return err } From 14c5909d5719eec7ef9e89899c4b9a4580eb7d71 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 16:54:42 +0530 Subject: [PATCH 10/13] add migrations --- CHANGELOG.md | 2 ++ x/crisis/exported/exported.go | 19 ++++++++++ x/crisis/keeper/keeper.go | 17 ++++----- x/crisis/keeper/migrator.go | 28 +++++++++++++++ x/crisis/migrations/v046/migrate.go | 40 +++++++++++++++++++++ x/crisis/migrations/v046/migrate_test.go | 44 ++++++++++++++++++++++++ x/crisis/module.go | 20 ++++++++--- 7 files changed, 155 insertions(+), 15 deletions(-) create mode 100644 x/crisis/exported/exported.go create mode 100644 x/crisis/keeper/migrator.go create mode 100644 x/crisis/migrations/v046/migrate.go create mode 100644 x/crisis/migrations/v046/migrate_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b561e6c9027..95d306b7485e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/slashing) [#12399](https://github.com/cosmos/cosmos-sdk/pull/12399) Migrate `x/slashing` to self-managed parameters and deprecate its usage of `x/params`. * (x/mint) [#12363](https://github.com/cosmos/cosmos-sdk/pull/12363) Migrate `x/mint` to self-managed parameters and deprecate it's usage of `x/params`. * (x/distribution) [#12434](https://github.com/cosmos/cosmos-sdk/pull/12434) Migrate `x/distribution` to self-managed parameters and deprecate it's usage of `x/params`. +* (x/crisis) [#12445](https://github.com/cosmos/cosmos-sdk/pull/12445) Migrate `x/crisis` to self-managed parameters and deprecate it's usage of `x/params`. ### API Breaking Changes @@ -72,6 +73,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/staking) [#12102](https://github.com/cosmos/cosmos-sdk/pull/12102) Staking keeper now is passed by reference instead of copy. Keeper's SetHooks no longer returns keeper. It updates the keeper in place instead. * (linting) [#12141](https://github.com/cosmos/cosmos-sdk/pull/12141) Fix usability related linting for database. This means removing the infix Prefix from `prefix.NewPrefixWriter` and such so that it is `prefix.NewWriter` and making `db.DBConnection` and such into `db.Connection` * (x/distribution) [#12434](https://github.com/cosmos/cosmos-sdk/pull/12434) `x/distribution` module `SetParams` keeper method definition is now updated to return `error`. +* (x/crisis) [#12445](https://github.com/cosmos/cosmos-sdk/pull/12445) `x/crisis` module `SetConstantFee` keeper method definition is now updated to return `error`. ### Bug Fixes diff --git a/x/crisis/exported/exported.go b/x/crisis/exported/exported.go new file mode 100644 index 000000000000..4360786511eb --- /dev/null +++ b/x/crisis/exported/exported.go @@ -0,0 +1,19 @@ +package exported + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +type ( + ParamSet = paramtypes.ParamSet + + // Subspace defines an interface that implements the legacy x/params Subspace + // type. + // + // NOTE: This is used solely for migration of x/params managed parameters. + Subspace interface { + // GetParamSet(ctx sdk.Context, ps ParamSet) + Get(ctx sdk.Context, key []byte, ptr interface{}) + } +) diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index 9997469b8c30..c806e917134f 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -10,17 +10,18 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/crisis/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Keeper - crisis keeper type Keeper struct { routes []types.InvarRoute - paramSpace paramtypes.Subspace invCheckPeriod uint storeKey storetypes.StoreKey cdc codec.BinaryCodec - authority string + + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string supplyKeeper types.SupplyKeeper @@ -33,20 +34,14 @@ func (k *Keeper) GetAuthority() string { // NewKeeper creates a new Keeper object func NewKeeper( - cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, - invCheckPeriod uint, supplyKeeper types.SupplyKeeper, feeCollectorName string, - authority string, + cdc codec.BinaryCodec, storeKey storetypes.StoreKey, invCheckPeriod uint, + supplyKeeper types.SupplyKeeper, feeCollectorName string, authority string, ) *Keeper { - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) - } return &Keeper{ storeKey: storeKey, cdc: cdc, routes: make([]types.InvarRoute, 0), - paramSpace: paramSpace, invCheckPeriod: invCheckPeriod, supplyKeeper: supplyKeeper, feeCollectorName: feeCollectorName, diff --git a/x/crisis/keeper/migrator.go b/x/crisis/keeper/migrator.go new file mode 100644 index 000000000000..6094e0dbb3d8 --- /dev/null +++ b/x/crisis/keeper/migrator.go @@ -0,0 +1,28 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis/exported" + v046 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v046" +) + +// Migrator is a struct for handling in-place state migrations. +type Migrator struct { + keeper *Keeper + legacySubspace exported.Subspace +} + +func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { + return Migrator{ + keeper: k, + legacySubspace: ss, + } +} + +// Migrate1to2 migrates the x/mint module state from the consensus version 1 to +// version 2. Specifically, it takes the parameters that are currently stored +// and managed by the x/params modules and stores them directly into the x/mint +// module state. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v046.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc) +} diff --git a/x/crisis/migrations/v046/migrate.go b/x/crisis/migrations/v046/migrate.go new file mode 100644 index 000000000000..03c165d3b87f --- /dev/null +++ b/x/crisis/migrations/v046/migrate.go @@ -0,0 +1,40 @@ +package v046 + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/crisis/exported" +) + +const ( + ModuleName = "crisis" +) + +var ( + ConstantFee = []byte("ConstantFee") +) + +// MigrateStore migrates the x/crisis module state from the consensus version 1 to +// version 2. Specifically, it takes the `ConstantFee` parameter that is currently stored +// and managed by the x/params module and stores it directly into the x/crisis +// module state. +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + var currConstantFee sdk.Coin + legacySubspace.Get(ctx, ConstantFee, &currConstantFee) + + if !currConstantFee.IsValid() { + return errors.ErrInvalidCoins.Wrap("constant fee") + } + + bz, err := cdc.Marshal(&currConstantFee) + if err != nil { + return err + } + + store.Set(ConstantFee, bz) + + return nil +} diff --git a/x/crisis/migrations/v046/migrate_test.go b/x/crisis/migrations/v046/migrate_test.go new file mode 100644 index 000000000000..0f14cb3a2e14 --- /dev/null +++ b/x/crisis/migrations/v046/migrate_test.go @@ -0,0 +1,44 @@ +package v046_test + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + v046 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v046" + "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/cosmos/cosmos-sdk/x/distribution" + "github.com/stretchr/testify/require" +) + +type mockSubspace struct { + constantFee sdk.Coin +} + +func newMockSubspace(fee sdk.Coin) mockSubspace { + return mockSubspace{constantFee: fee} +} + +func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { + *ptr.(*sdk.Coin) = ms.constantFee +} + +func TestMigrate(t *testing.T) { + encCfg := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + cdc := encCfg.Codec + + storeKey := sdk.NewKVStoreKey(v046.ModuleName) + tKey := sdk.NewTransientStoreKey("transient_test") + ctx := testutil.DefaultContext(storeKey, tKey) + store := ctx.KVStore(storeKey) + + legacySubspace := newMockSubspace(types.DefaultGenesisState().ConstantFee) + require.NoError(t, v046.MigrateStore(ctx, storeKey, legacySubspace, cdc)) + + var res sdk.Coin + bz := store.Get(v046.ConstantFee) + require.NoError(t, cdc.Unmarshal(bz, &res)) + require.NotNil(t, res) + require.Equal(t, legacySubspace.constantFee, res) +} diff --git a/x/crisis/module.go b/x/crisis/module.go index a17aa0550147..74b2d0c97709 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -25,12 +25,16 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" + "github.com/cosmos/cosmos-sdk/x/crisis/exported" "github.com/cosmos/cosmos-sdk/x/crisis/keeper" "github.com/cosmos/cosmos-sdk/x/crisis/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" ) +// ConsensusVersion defines the current x/distribution module consensus version. +const ConsensusVersion = 2 + var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} @@ -96,6 +100,9 @@ type AppModule struct { // executed. keeper *keeper.Keeper + // legacySubspace is used solely for migration of x/params managed parameters + legacySubspace exported.Subspace + skipGenesisInvariants bool } @@ -103,10 +110,11 @@ type AppModule struct { // we will call keeper.AssertInvariants during InitGenesis (it may take a significant time) // - which doesn't impact the chain security unless 66+% of validators have a wrongly // modified genesis file. -func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool) AppModule { +func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool, ss exported.Subspace) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, + legacySubspace: ss, skipGenesisInvariants: skipGenesisInvariants, } @@ -139,6 +147,11 @@ func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return n // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + + m := keeper.NewMigrator(am.keeper, am.legacySubspace) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err)) + } } // InitGenesis performs genesis initialization for the crisis module. It returns @@ -164,7 +177,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // BeginBlock performs a no-op. func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} @@ -218,7 +231,6 @@ func provideModule(in crisisInputs) crisisOutputs { k := keeper.NewKeeper( in.Cdc, in.Key, - in.Subspace, invalidCheckPeriod, in.BankKeeper, feeCollectorName, @@ -227,7 +239,7 @@ func provideModule(in crisisInputs) crisisOutputs { skipGenesisInvariants := cast.ToBool(in.AppOpts.Get(FlagSkipGenesisInvariants)) - m := NewAppModule(k, skipGenesisInvariants) + m := NewAppModule(k, skipGenesisInvariants, in.Subspace) return crisisOutputs{CrisisKeeper: k, Module: runtime.WrapAppModule(m)} } From 959921d6ad9c4e1e45ad060ea16739a17a5bcc83 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 17:18:31 +0530 Subject: [PATCH 11/13] review --- api/cosmos/crisis/v1beta1/tx.pulsar.go | 2 -- proto/cosmos/crisis/v1beta1/tx.proto | 2 -- x/crisis/types/tx.pb.go | 2 -- 3 files changed, 6 deletions(-) diff --git a/api/cosmos/crisis/v1beta1/tx.pulsar.go b/api/cosmos/crisis/v1beta1/tx.pulsar.go index b778998bd52b..1b6acca498ef 100644 --- a/api/cosmos/crisis/v1beta1/tx.pulsar.go +++ b/api/cosmos/crisis/v1beta1/tx.pulsar.go @@ -1878,8 +1878,6 @@ type MsgUpdateParams struct { // authority is the address of the governance account. Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` // constant_fee defines the x/crisis parameter. - // - // NOTE: All parameters must be supplied. ConstantFee *v1beta1.Coin `protobuf:"bytes,2,opt,name=constant_fee,json=constantFee,proto3" json:"constant_fee,omitempty"` } diff --git a/proto/cosmos/crisis/v1beta1/tx.proto b/proto/cosmos/crisis/v1beta1/tx.proto index 02c09f9da9f2..b87f10951b7d 100644 --- a/proto/cosmos/crisis/v1beta1/tx.proto +++ b/proto/cosmos/crisis/v1beta1/tx.proto @@ -45,8 +45,6 @@ message MsgUpdateParams { string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // constant_fee defines the x/crisis parameter. - // - // NOTE: All parameters must be supplied. cosmos.base.v1beta1.Coin constant_fee = 2 [(gogoproto.nullable) = false]; } diff --git a/x/crisis/types/tx.pb.go b/x/crisis/types/tx.pb.go index de1d9e434022..a996aab1c068 100644 --- a/x/crisis/types/tx.pb.go +++ b/x/crisis/types/tx.pb.go @@ -115,8 +115,6 @@ type MsgUpdateParams struct { // authority is the address of the governance account. Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` // constant_fee defines the x/crisis parameter. - // - // NOTE: All parameters must be supplied. ConstantFee types.Coin `protobuf:"bytes,2,opt,name=constant_fee,json=constantFee,proto3" json:"constant_fee"` } From 18059a99fff5406b14dbf14844a48912c0166212 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 20:35:26 +0530 Subject: [PATCH 12/13] review changes --- x/crisis/keeper/msg_server.go | 4 ---- x/crisis/keeper/msg_server_test.go | 8 ++++++++ x/crisis/keeper/params.go | 15 +++++++-------- x/crisis/keeper/params_test.go | 12 +++++++++++- x/crisis/migrations/v046/migrate.go | 5 +++-- x/crisis/migrations/v046/migrate_test.go | 2 +- x/crisis/module.go | 2 +- x/crisis/types/keys.go | 2 +- x/crisis/types/msgs.go | 4 ++++ 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index 5cb0dacfb8cc..e0bede26214c 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -72,10 +72,6 @@ func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) } - if !req.ConstantFee.IsValid() { - return nil, errors.ErrInvalidCoins.Wrap("invalid constant fee") - } - ctx := sdk.UnwrapSDKContext(goCtx) if err := k.SetConstantFee(ctx, req.ConstantFee); err != nil { return nil, err diff --git a/x/crisis/keeper/msg_server_test.go b/x/crisis/keeper/msg_server_test.go index c1de220be327..6d4ba8e546f1 100644 --- a/x/crisis/keeper/msg_server_test.go +++ b/x/crisis/keeper/msg_server_test.go @@ -56,6 +56,14 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { }, expErr: true, }, + { + name: "negative constant fee", + input: &types.MsgUpdateParams{ + Authority: s.keeper.GetAuthority(), + ConstantFee: sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(-1000)}, + }, + expErr: true, + }, { name: "all good", input: &types.MsgUpdateParams{ diff --git a/x/crisis/keeper/params.go b/x/crisis/keeper/params.go index 92d8f29f6633..e24eb58bd46a 100644 --- a/x/crisis/keeper/params.go +++ b/x/crisis/keeper/params.go @@ -9,27 +9,26 @@ import ( // GetConstantFee get's the constant fee from the store func (k *Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConstantFee) + bz := store.Get(types.ConstantFeeKey) if bz == nil { return constantFee } k.cdc.MustUnmarshal(bz, &constantFee) - return + return constantFee } // GetConstantFee set's the constant fee in the store func (k *Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) error { - store := ctx.KVStore(k.storeKey) - bz, err := k.cdc.Marshal(&constantFee) - - if !constantFee.IsValid() { - return errors.ErrInvalidCoins.Wrap("invalid constant fee") + if !constantFee.IsValid() || constantFee.IsNegative() { + return errors.Wrapf(errors.ErrInvalidCoins, "negative or invalid constant fee: %s", constantFee) } + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(&constantFee) if err != nil { return err } - store.Set(types.ConstantFee, bz) + store.Set(types.ConstantFeeKey, bz) return nil } diff --git a/x/crisis/keeper/params_test.go b/x/crisis/keeper/params_test.go index adce9dc34db4..b5c65e5e5806 100644 --- a/x/crisis/keeper/params_test.go +++ b/x/crisis/keeper/params_test.go @@ -6,7 +6,7 @@ import ( func (s *KeeperTestSuite) TestParams() { // default params - constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) // 4% + constantFee := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)) testCases := []struct { name string @@ -14,6 +14,16 @@ func (s *KeeperTestSuite) TestParams() { expErr bool expErrMsg string }{ + { + name: "invalid constant fee", + constantFee: sdk.Coin{}, + expErr: true, + }, + { + name: "negative constant fee", + constantFee: sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(-1000)}, + expErr: true, + }, { name: "all good", constantFee: constantFee, diff --git a/x/crisis/migrations/v046/migrate.go b/x/crisis/migrations/v046/migrate.go index 03c165d3b87f..333b4be89403 100644 --- a/x/crisis/migrations/v046/migrate.go +++ b/x/crisis/migrations/v046/migrate.go @@ -13,7 +13,8 @@ const ( ) var ( - ConstantFee = []byte("ConstantFee") + ConstantFee = []byte("ConstantFee") + ConstantFeeKey = []byte{0x01} ) // MigrateStore migrates the x/crisis module state from the consensus version 1 to @@ -34,7 +35,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace return err } - store.Set(ConstantFee, bz) + store.Set(ConstantFeeKey, bz) return nil } diff --git a/x/crisis/migrations/v046/migrate_test.go b/x/crisis/migrations/v046/migrate_test.go index 0f14cb3a2e14..ae283a688f85 100644 --- a/x/crisis/migrations/v046/migrate_test.go +++ b/x/crisis/migrations/v046/migrate_test.go @@ -37,7 +37,7 @@ func TestMigrate(t *testing.T) { require.NoError(t, v046.MigrateStore(ctx, storeKey, legacySubspace, cdc)) var res sdk.Coin - bz := store.Get(v046.ConstantFee) + bz := store.Get(v046.ConstantFeeKey) require.NoError(t, cdc.Unmarshal(bz, &res)) require.NotNil(t, res) require.Equal(t, legacySubspace.constantFee, res) diff --git a/x/crisis/module.go b/x/crisis/module.go index 74b2d0c97709..424fcaec3790 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -32,7 +32,7 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" ) -// ConsensusVersion defines the current x/distribution module consensus version. +// ConsensusVersion defines the current x/params module consensus version. const ConsensusVersion = 2 var ( diff --git a/x/crisis/types/keys.go b/x/crisis/types/keys.go index 449f4f5ba8fa..9cc09faf5808 100644 --- a/x/crisis/types/keys.go +++ b/x/crisis/types/keys.go @@ -8,5 +8,5 @@ const ( ) var ( - ConstantFee = []byte("ConstantFee") + ConstantFeeKey = []byte{0x01} ) diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index 8b933586d559..02f37af6f912 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -78,5 +78,9 @@ func (msg MsgUpdateParams) ValidateBasic() error { return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "invalid costant fee") } + if msg.ConstantFee.IsNegative() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "negative costant fee") + } + return nil } From 5b3aef466c0a0896abd49694a1d654bf0fbf7076 Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 11 Jul 2022 20:36:20 +0530 Subject: [PATCH 13/13] - new line --- x/crisis/keeper/genesis.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/crisis/keeper/genesis.go b/x/crisis/keeper/genesis.go index 4885221ace7e..c0249989a443 100644 --- a/x/crisis/keeper/genesis.go +++ b/x/crisis/keeper/genesis.go @@ -10,7 +10,6 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { if err := k.SetConstantFee(ctx, data.ConstantFee); err != nil { panic(err) } - } // ExportGenesis returns a GenesisState for a given context and keeper.