diff --git a/CHANGELOG.md b/CHANGELOG.md index 79db5acab634..f70753e0cc1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (x/gov) [#18428](https://github.com/cosmos/cosmos-sdk/pull/18428) Extend governance config. * (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve ` q gov proposer` by querying directly a proposal instead of tx events. It is an alias of `q gov proposal` as the proposer is a field of the proposal. * (version) [#18063](https://github.com/cosmos/cosmos-sdk/pull/18063) Allow to define extra info to be displayed in ` version --long` command. @@ -97,6 +98,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#18204](https://github.com/cosmos/cosmos-sdk/pull/18204) Use streaming json parser to parse chain-id from genesis file. * (x/gov) [#18189](https://github.com/cosmos/cosmos-sdk/pull/18189) Limit the accepted deposit coins for a proposal to the minimum proposal deposit denoms. * (x/staking) [#18049](https://github.com/cosmos/cosmos-sdk/pull/18049) Return early if Slash encounters zero tokens to burn. * (x/staking) [#18035](https://github.com/cosmos/cosmos-sdk/pull/18035) Hoisted out of the redelegation loop, the non-changing validator and delegator addresses parsing. diff --git a/api/cosmos/gov/module/v1/module.pulsar.go b/api/cosmos/gov/module/v1/module.pulsar.go index 43e32585116a..76ec7e34c06f 100644 --- a/api/cosmos/gov/module/v1/module.pulsar.go +++ b/api/cosmos/gov/module/v1/module.pulsar.go @@ -17,6 +17,8 @@ var ( md_Module protoreflect.MessageDescriptor fd_Module_max_metadata_len protoreflect.FieldDescriptor fd_Module_authority protoreflect.FieldDescriptor + fd_Module_max_title_len protoreflect.FieldDescriptor + fd_Module_max_summary_len protoreflect.FieldDescriptor ) func init() { @@ -24,6 +26,8 @@ func init() { md_Module = File_cosmos_gov_module_v1_module_proto.Messages().ByName("Module") fd_Module_max_metadata_len = md_Module.Fields().ByName("max_metadata_len") fd_Module_authority = md_Module.Fields().ByName("authority") + fd_Module_max_title_len = md_Module.Fields().ByName("max_title_len") + fd_Module_max_summary_len = md_Module.Fields().ByName("max_summary_len") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -103,6 +107,18 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto return } } + if x.MaxTitleLen != uint64(0) { + value := protoreflect.ValueOfUint64(x.MaxTitleLen) + if !f(fd_Module_max_title_len, value) { + return + } + } + if x.MaxSummaryLen != uint64(0) { + value := protoreflect.ValueOfUint64(x.MaxSummaryLen) + if !f(fd_Module_max_summary_len, value) { + return + } + } } // Has reports whether a field is populated. @@ -122,6 +138,10 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { return x.MaxMetadataLen != uint64(0) case "cosmos.gov.module.v1.Module.authority": return x.Authority != "" + case "cosmos.gov.module.v1.Module.max_title_len": + return x.MaxTitleLen != uint64(0) + case "cosmos.gov.module.v1.Module.max_summary_len": + return x.MaxSummaryLen != uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -142,6 +162,10 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { x.MaxMetadataLen = uint64(0) case "cosmos.gov.module.v1.Module.authority": x.Authority = "" + case "cosmos.gov.module.v1.Module.max_title_len": + x.MaxTitleLen = uint64(0) + case "cosmos.gov.module.v1.Module.max_summary_len": + x.MaxSummaryLen = uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -164,6 +188,12 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro case "cosmos.gov.module.v1.Module.authority": value := x.Authority return protoreflect.ValueOfString(value) + case "cosmos.gov.module.v1.Module.max_title_len": + value := x.MaxTitleLen + return protoreflect.ValueOfUint64(value) + case "cosmos.gov.module.v1.Module.max_summary_len": + value := x.MaxSummaryLen + return protoreflect.ValueOfUint64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -188,6 +218,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto x.MaxMetadataLen = value.Uint() case "cosmos.gov.module.v1.Module.authority": x.Authority = value.Interface().(string) + case "cosmos.gov.module.v1.Module.max_title_len": + x.MaxTitleLen = value.Uint() + case "cosmos.gov.module.v1.Module.max_summary_len": + x.MaxSummaryLen = value.Uint() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -212,6 +246,10 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore panic(fmt.Errorf("field max_metadata_len of message cosmos.gov.module.v1.Module is not mutable")) case "cosmos.gov.module.v1.Module.authority": panic(fmt.Errorf("field authority of message cosmos.gov.module.v1.Module is not mutable")) + case "cosmos.gov.module.v1.Module.max_title_len": + panic(fmt.Errorf("field max_title_len of message cosmos.gov.module.v1.Module is not mutable")) + case "cosmos.gov.module.v1.Module.max_summary_len": + panic(fmt.Errorf("field max_summary_len of message cosmos.gov.module.v1.Module is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -229,6 +267,10 @@ func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protor return protoreflect.ValueOfUint64(uint64(0)) case "cosmos.gov.module.v1.Module.authority": return protoreflect.ValueOfString("") + case "cosmos.gov.module.v1.Module.max_title_len": + return protoreflect.ValueOfUint64(uint64(0)) + case "cosmos.gov.module.v1.Module.max_summary_len": + return protoreflect.ValueOfUint64(uint64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.gov.module.v1.Module")) @@ -305,6 +347,12 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } + if x.MaxTitleLen != 0 { + n += 1 + runtime.Sov(uint64(x.MaxTitleLen)) + } + if x.MaxSummaryLen != 0 { + n += 1 + runtime.Sov(uint64(x.MaxSummaryLen)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -334,6 +382,16 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.MaxSummaryLen != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.MaxSummaryLen)) + i-- + dAtA[i] = 0x20 + } + if x.MaxTitleLen != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.MaxTitleLen)) + i-- + dAtA[i] = 0x18 + } if len(x.Authority) > 0 { i -= len(x.Authority) copy(dAtA[i:], x.Authority) @@ -446,6 +504,44 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { } x.Authority = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MaxTitleLen", wireType) + } + x.MaxTitleLen = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.MaxTitleLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MaxSummaryLen", wireType) + } + x.MaxSummaryLen = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.MaxSummaryLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -505,6 +601,12 @@ type Module struct { MaxMetadataLen uint64 `protobuf:"varint,1,opt,name=max_metadata_len,json=maxMetadataLen,proto3" json:"max_metadata_len,omitempty"` // authority defines the custom module authority. If not set, defaults to the governance module. Authority string `protobuf:"bytes,2,opt,name=authority,proto3" json:"authority,omitempty"` + // max_title_len defines the maximum proposal title length. + // Defaults to 255 if not explicitly set. + MaxTitleLen uint64 `protobuf:"varint,3,opt,name=max_title_len,json=maxTitleLen,proto3" json:"max_title_len,omitempty"` + // max_summary_len defines the maximum proposal summary length. + // Defaults to 10200 if not explicitly set. + MaxSummaryLen uint64 `protobuf:"varint,4,opt,name=max_summary_len,json=maxSummaryLen,proto3" json:"max_summary_len,omitempty"` } func (x *Module) Reset() { @@ -541,6 +643,20 @@ func (x *Module) GetAuthority() string { return "" } +func (x *Module) GetMaxTitleLen() uint64 { + if x != nil { + return x.MaxTitleLen + } + return 0 +} + +func (x *Module) GetMaxSummaryLen() uint64 { + if x != nil { + return x.MaxSummaryLen + } + return 0 +} + var File_cosmos_gov_module_v1_module_proto protoreflect.FileDescriptor var file_cosmos_gov_module_v1_module_proto_rawDesc = []byte{ @@ -549,28 +665,33 @@ var file_cosmos_gov_module_v1_module_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x6f, 0x76, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7c, 0x0a, 0x06, 0x4d, - 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6d, 0x61, 0x78, 0x5f, 0x6d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x6c, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0e, 0x6d, 0x61, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x4c, 0x65, 0x6e, 0x12, - 0x1c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x3a, 0x2a, 0xba, - 0xc0, 0x96, 0xda, 0x01, 0x24, 0x0a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, - 0x73, 0x64, 0x6b, 0x2f, 0x78, 0x2f, 0x67, 0x6f, 0x76, 0x42, 0xca, 0x01, 0x0a, 0x18, 0x63, 0x6f, - 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x6f, 0x76, 0x2e, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, - 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, - 0x6f, 0x76, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x4d, 0xaa, 0x02, 0x14, 0x43, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x47, 0x6f, 0x76, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, - 0x56, 0x31, 0xca, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x6f, 0x76, 0x5c, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x20, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x5c, 0x47, 0x6f, 0x76, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, - 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x43, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x6f, 0x76, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, - 0x6c, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc8, 0x01, 0x0a, 0x06, + 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6d, 0x61, 0x78, 0x5f, 0x6d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x6c, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x0e, 0x6d, 0x61, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x4c, 0x65, 0x6e, + 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x22, + 0x0a, 0x0d, 0x6d, 0x61, 0x78, 0x5f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x6e, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x61, 0x78, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x4c, + 0x65, 0x6e, 0x12, 0x26, 0x0a, 0x0f, 0x6d, 0x61, 0x78, 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, + 0x79, 0x5f, 0x6c, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x6d, 0x61, 0x78, + 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x4c, 0x65, 0x6e, 0x3a, 0x2a, 0xba, 0xc0, 0x96, 0xda, + 0x01, 0x24, 0x0a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, + 0x2f, 0x78, 0x2f, 0x67, 0x6f, 0x76, 0x42, 0xca, 0x01, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x67, 0x6f, 0x76, 0x2e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x67, 0x6f, 0x76, 0x2f, + 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, + 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x47, 0x4d, 0xaa, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x47, 0x6f, 0x76, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x56, 0x31, 0xca, + 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x47, 0x6f, 0x76, 0x5c, 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x20, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, + 0x47, 0x6f, 0x76, 0x5c, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x17, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x3a, 0x3a, 0x47, 0x6f, 0x76, 0x3a, 0x3a, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x3a, + 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/go.mod b/go.mod index d5f0a801e143..a5ffab9c9747 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ toolchain go1.21.0 module github.com/cosmos/cosmos-sdk require ( - cosmossdk.io/api v0.7.2 + cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 // TODO tag before v0.50.2 release cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/go.sum b/go.sum index 380050d4e1e8..980665c8585e 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4= -cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 h1:huwGblabKP0MUvGVBwFVRx+FBfwTM3O4BMvwpt7m77g= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310/go.mod h1:7B/5XWh1HYwJk3DzWeNoxOSI+nGx1m5UyYfHLFuKzkw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/proto/cosmos/gov/module/v1/module.proto b/proto/cosmos/gov/module/v1/module.proto index 9cade9af0159..f6622fc40f52 100644 --- a/proto/cosmos/gov/module/v1/module.proto +++ b/proto/cosmos/gov/module/v1/module.proto @@ -16,4 +16,12 @@ message Module { // authority defines the custom module authority. If not set, defaults to the governance module. string authority = 2; -} \ No newline at end of file + + // max_title_len defines the maximum proposal title length. + // Defaults to 255 if not explicitly set. + uint64 max_title_len = 3; + + // max_summary_len defines the maximum proposal summary length. + // Defaults to 10200 if not explicitly set. + uint64 max_summary_len = 4; +} diff --git a/simapp/go.mod b/simapp/go.mod index 57e83eed42ae..503cdb789d66 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/simapp go 1.21 require ( - cosmossdk.io/api v0.7.2 + cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 cosmossdk.io/client/v2 v2.0.0-beta.1 cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/core v0.11.0 diff --git a/simapp/go.sum b/simapp/go.sum index 6a1d2707cf4f..4cfd9fe1b5f3 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4= -cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 h1:huwGblabKP0MUvGVBwFVRx+FBfwTM3O4BMvwpt7m77g= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310/go.mod h1:7B/5XWh1HYwJk3DzWeNoxOSI+nGx1m5UyYfHLFuKzkw= cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q= cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= diff --git a/tests/go.mod b/tests/go.mod index f3f2ba0d9874..2a40257d986f 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -3,7 +3,7 @@ module github.com/cosmos/cosmos-sdk/tests go 1.21 require ( - cosmossdk.io/api v0.7.2 + cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 diff --git a/tests/go.sum b/tests/go.sum index 0bfd815fa259..fda8026df8aa 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.2 h1:BO3i5fvKMKvfaUiMkCznxViuBEfyWA/k6w2eAF6q1C4= -cosmossdk.io/api v0.7.2/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310 h1:huwGblabKP0MUvGVBwFVRx+FBfwTM3O4BMvwpt7m77g= +cosmossdk.io/api v0.7.3-0.20231110151756-89296ccdd310/go.mod h1:7B/5XWh1HYwJk3DzWeNoxOSI+nGx1m5UyYfHLFuKzkw= cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q= cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= diff --git a/x/gov/README.md b/x/gov/README.md index 87b2fc5fad6c..d26637ef151c 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -308,8 +308,8 @@ the following `JSON` template: This makes it far easier for clients to support multiple networks. -The metadata has a maximum length that is chosen by the app developer, and -passed into the gov keeper as a config. The default maximum length in the SDK is 255 characters. +Fields metadata, title and summary have a maximum length that is chosen by the app developer, and +passed into the gov keeper as a config. The default maximum length are: for the title 255 characters, for the metadata 255 characters and for summary 10200 characters (40 times the one of the title). #### Writing a module that uses governance diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 63ff7c252783..44f2f8c64c00 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -85,9 +85,18 @@ func NewKeeper( panic(fmt.Sprintf("invalid authority address: %s", authority)) } + defaultConfig := types.DefaultConfig() + // If MaxMetadataLen not set by app developer, set to default value. + if config.MaxTitleLen == 0 { + config.MaxTitleLen = defaultConfig.MaxTitleLen + } // If MaxMetadataLen not set by app developer, set to default value. if config.MaxMetadataLen == 0 { - config.MaxMetadataLen = types.DefaultConfig().MaxMetadataLen + config.MaxMetadataLen = defaultConfig.MaxMetadataLen + } + // If MaxMetadataLen not set by app developer, set to default value. + if config.MaxSummaryLen == 0 { + config.MaxSummaryLen = defaultConfig.MaxSummaryLen } sb := collections.NewSchemaBuilder(storeService) @@ -175,6 +184,32 @@ func (k Keeper) ModuleAccountAddress() sdk.AccAddress { return k.authKeeper.GetModuleAddress(types.ModuleName) } +// validateProposalLengths checks message metadata, summary and title +// to have the expected length otherwise returns an error. +func (k Keeper) validateProposalLengths(metadata, title, summary string) error { + if err := k.assertMetadataLength(metadata); err != nil { + return err + } + if err := k.assertSummaryLength(summary); err != nil { + return err + } + if err := k.assertTitleLength(title); err != nil { + return err + } + return nil +} + +// assertTitleLength returns an error if given title length +// is greater than a pre-defined MaxTitleLen. +func (k Keeper) assertTitleLength(title string) error { + if title != "" && uint64(len(title)) > k.config.MaxTitleLen { + // this message will specify title instead of metadata in v0.51. + // this is done in the backported PR like this to avoid breaking changes in v0.50 + return types.ErrMetadataTooLong.Wrapf("got metadata with length %d", len(title)) + } + return nil +} + // assertMetadataLength returns an error if given metadata length // is greater than a pre-defined MaxMetadataLen. func (k Keeper) assertMetadataLength(metadata string) error { @@ -185,9 +220,9 @@ func (k Keeper) assertMetadataLength(metadata string) error { } // assertSummaryLength returns an error if given summary length -// is greater than a pre-defined 40*MaxMetadataLen. +// is greater than a pre-defined MaxSummaryLen. func (k Keeper) assertSummaryLength(summary string) error { - if summary != "" && uint64(len(summary)) > 40*k.config.MaxMetadataLen { + if summary != "" && uint64(len(summary)) > k.config.MaxSummaryLen { return types.ErrSummaryTooLong.Wrapf("got summary with length %d", len(summary)) } return nil diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index 7274ba89cd69..d4ee06c3fc60 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -48,7 +48,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() { []sdk.Msg{bankMsg}, initialDeposit, "", - strings.Repeat("1", 300), + strings.Repeat("1", 100), "Proposal", "description of proposal", false, @@ -132,13 +132,28 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() { expErr: true, expErrMsg: "metadata summary '' must equal proposal summary 'description'", }, + "title too long": { + preRun: func() (*v1.MsgSubmitProposal, error) { + return v1.NewMsgSubmitProposal( + []sdk.Msg{bankMsg}, + initialDeposit, + proposer.String(), + "Metadata", + strings.Repeat("1", 256), + "description of proposal", + false, + ) + }, + expErr: true, + expErrMsg: "metadata too long", + }, "metadata too long": { preRun: func() (*v1.MsgSubmitProposal, error) { return v1.NewMsgSubmitProposal( []sdk.Msg{bankMsg}, initialDeposit, proposer.String(), - strings.Repeat("1", 300), + strings.Repeat("1", 256), "Proposal", "description of proposal", false, @@ -155,7 +170,7 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() { proposer.String(), "", "Proposal", - strings.Repeat("1", 300*40), + strings.Repeat("1", 10201), false, ) }, diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 20eb6763d069..f0b4426c7f3f 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -18,20 +18,10 @@ import ( // SubmitProposal creates a new proposal given an array of messages func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, expedited bool) (v1.Proposal, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - err := keeper.assertMetadataLength(metadata) - if err != nil { - return v1.Proposal{}, err - } - - // assert summary is no longer than predefined max length of metadata - err = keeper.assertSummaryLength(summary) - if err != nil { - return v1.Proposal{}, err - } - // assert title is no longer than predefined max length of metadata - err = keeper.assertMetadataLength(title) - if err != nil { + // This method checks that all message metadata, summary and title + // has te expected length defined in the module configuration. + if err := keeper.validateProposalLengths(metadata, title, summary); err != nil { return v1.Proposal{}, err } diff --git a/x/gov/module.go b/x/gov/module.go index dc84dd9bcad1..faf773c1f1d3 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -188,9 +188,15 @@ type ModuleOutputs struct { func ProvideModule(in ModuleInputs) ModuleOutputs { defaultConfig := govtypes.DefaultConfig() + if in.Config.MaxTitleLen != 0 { + defaultConfig.MaxTitleLen = in.Config.MaxTitleLen + } if in.Config.MaxMetadataLen != 0 { defaultConfig.MaxMetadataLen = in.Config.MaxMetadataLen } + if in.Config.MaxSummaryLen != 0 { + defaultConfig.MaxSummaryLen = in.Config.MaxSummaryLen + } // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) diff --git a/x/gov/types/config.go b/x/gov/types/config.go index d19767f7d15c..39a809688c64 100644 --- a/x/gov/types/config.go +++ b/x/gov/types/config.go @@ -2,13 +2,19 @@ package types // Config is a config struct used for intialising the gov module to avoid using globals. type Config struct { - // MaxMetadataLen defines the maximum proposal metadata length. + // MaxTitleLen defines the amount of characters that can be used for proposal title + MaxTitleLen uint64 + // MaxMetadataLen defines the amount of characters that can be used for proposal metadata. MaxMetadataLen uint64 + // MaxSummaryLen defines the amount of characters that can be used for proposal summary + MaxSummaryLen uint64 } // DefaultConfig returns the default config for gov. func DefaultConfig() Config { return Config{ + MaxTitleLen: 255, MaxMetadataLen: 255, + MaxSummaryLen: 10200, } } diff --git a/x/gov/types/errors.go b/x/gov/types/errors.go index e89723bbb813..d200ae583b31 100644 --- a/x/gov/types/errors.go +++ b/x/gov/types/errors.go @@ -25,4 +25,5 @@ var ( ErrInvalidProposal = errors.Register(ModuleName, 21, "invalid proposal") ErrSummaryTooLong = errors.Register(ModuleName, 22, "summary too long") ErrInvalidDepositDenom = errors.Register(ModuleName, 23, "invalid deposit denom") + ErrTitleTooLong = errors.Register(ModuleName, 24, "title too long") )