Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/gov): extend governance config #18428

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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) [#18189](https://github.com/cosmos/cosmos-sdk/pull/18189) Limit the accepted deposit coins for a proposal to the minimum proposal deposit denoms.
* (x/gov) [#18025](https://github.com/cosmos/cosmos-sdk/pull/18025) Improve `<appd> 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.
* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details.
Expand Down
17 changes: 13 additions & 4 deletions x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,28 @@ func (k Keeper) ModuleAccountAddress() sdk.AccAddress {
return k.authKeeper.GetModuleAddress(types.ModuleName)
}

// assertTitleLength returns an error if given title length
// is greater than a pre-defined MaxTitleLen.
func (k Keeper) assertTitleLength(title string) error {
if title != "" && len(title) > k.config.MaxTitleLen {
return types.ErrMetadataTooLong.Wrapf("got title with length %d", len(title))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself, in the backport PR, make this message identical as the metadata message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, for main let's create a new error for the title being too long. I'll revert in the backport.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks for that one

}
return nil
}

// assertMetadataLength returns an error if given metadata length
// is greater than a pre-defined MaxMetadataLen.
func (k Keeper) assertMetadataLength(metadata string) error {
if metadata != "" && uint64(len(metadata)) > k.config.MaxMetadataLen {
if metadata != "" && len(metadata) > k.config.MaxMetadataLen {
return types.ErrMetadataTooLong.Wrapf("got metadata with length %d", len(metadata))
}
return nil
}

// assertSummaryLength returns an error if given summary length
// is greater than a pre-defined 40*MaxMetadataLen.
func (keeper Keeper) assertSummaryLength(summary string) error {
if summary != "" && uint64(len(summary)) > 40*keeper.config.MaxMetadataLen {
// is greater than a pre-defined MaxSummaryLen.
func (k Keeper) assertSummaryLength(summary string) error {
if summary != "" && len(summary) > k.config.MaxSummaryLen {
return types.ErrSummaryTooLong.Wrapf("got summary with length %d", len(summary))
}
return nil
Expand Down
10 changes: 7 additions & 3 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ 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)
// check that the proposal has
// the expected metadata length
err := keeper.assertMetadataLength(metadata)
if err != nil {
return v1.Proposal{}, err
}

// assert summary is no longer than predefined max length of metadata
// check that the proposal has
// the expected summary length
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)
// check that the proposal has
// the expected title length
err = keeper.assertTitleLength(title)
if err != nil {
return v1.Proposal{}, err
}
emidev98 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 8 additions & 2 deletions x/gov/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
MaxMetadataLen uint64
// MaxTitleLen defines the amount of characters that can be used for proposal title
MaxTitleLen int
// MaxMetadataLen defines the amount of characters that can be used for proposal metadata.
MaxMetadataLen int
// MaxSummaryLen defines the amount of characters that can be used for proposal summary
MaxSummaryLen int
}

// DefaultConfig returns the default config for gov.
func DefaultConfig() Config {
return Config{
MaxTitleLen: 100,
MaxMetadataLen: 255,
MaxSummaryLen: 10200,
}
}
Loading