diff --git a/x/gov/README.md b/x/gov/README.md index 66f2f3199b8a..d26637ef151c 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -309,7 +309,7 @@ the following `JSON` template: This makes it far easier for clients to support multiple networks. 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 100 characters, for the metadata 255 characters and for summary 10200 characters (40 times the one of the title). +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 76470c7bb560..e7f0f1cdb6b1 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -190,6 +190,8 @@ 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 diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index f6aaf9f39c8a..0d2cfdac8786 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -20,8 +20,9 @@ import ( 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) - // This method checks that all the message metadata, summary and title - // has te expected length defined in the module configuration. + +// 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 685c216fccf0..63f870b22d3c 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -182,9 +182,15 @@ type ModuleOutputs struct { func ProvideModule(in ModuleInputs) ModuleOutputs { defaultConfig := govtypes.DefaultConfig() - defaultConfig.MaxTitleLen = max(in.Config.MaxTitleLen, defaultConfig.MaxTitleLen) - defaultConfig.MaxMetadataLen = max(in.Config.MaxMetadataLen, defaultConfig.MaxMetadataLen) - defaultConfig.MaxSummaryLen = max(in.Config.MaxSummaryLen, defaultConfig.MaxSummaryLen) + 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)