Skip to content

Commit

Permalink
feat: extend governance config
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Nov 10, 2023
1 parent 7208905 commit 7328d03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
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))
}
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
}
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,
}
}

0 comments on commit 7328d03

Please sign in to comment.