Skip to content

Commit

Permalink
chg: rename MaxVoteOptionsLen
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Apr 18, 2024
1 parent 0453e03 commit 5f55293
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func NewKeeper(
config.MaxMetadataLen = types.DefaultConfig().MaxMetadataLen
}

// Enforce MaxOptionsLen to be 1.
if config.MaxOptionsLen != 1 {
config.MaxOptionsLen = types.DefaultConfig().MaxOptionsLen
// Enforce MaxVoteOptionsLen to be 1.
if config.MaxVoteOptionsLen != 1 {
config.MaxVoteOptionsLen = types.DefaultConfig().MaxVoteOptionsLen
}

sb := collections.NewSchemaBuilder(storeService)
Expand Down Expand Up @@ -189,11 +189,11 @@ func (k Keeper) assertMetadataLength(metadata string) error {
return nil
}

// assertOptionsLength returns an error if given options length
// is greater than a pre-defined MaxOptionsLen.
func (k Keeper) assertOptionsLength(options v1.WeightedVoteOptions) error {
if uint64(len(options)) > k.config.MaxOptionsLen {
return types.ErrTooManyVoteOptions.Wrapf("got %d options, maximum allowed is %d", len(options), k.config.MaxOptionsLen)
// assertVoteOptionsLength returns an error if given vote options length
// is greater than a pre-defined MaxVoteOptionsLen.
func (k Keeper) assertVoteOptionsLength(options v1.WeightedVoteOptions) error {
if uint64(len(options)) > k.config.MaxVoteOptionsLen {
return types.ErrTooManyVoteOptions.Wrapf("got %d options, maximum allowed is %d", len(options), k.config.MaxVoteOptionsLen)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b

// HV2: check on the length of the options.
// This should never fail as all votes must have only 1 option, hence we panic if something goes wrong
err := keeper.assertOptionsLength(val.Vote)
err := keeper.assertVoteOptionsLength(val.Vote)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (keeper Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr s
// HV2: check on the length of the options. This should never fail as it is only used by `MsgServer.Vote`.
// There, `v1.NewNonSplitVoteOption` is used to enforce the constraints (only 1 option with weight=1)
// Hence, we panic if something goes wrong
err = keeper.assertOptionsLength(options)
err = keeper.assertVoteOptionsLength(options)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions x/gov/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package types
type Config struct {
// MaxMetadataLen defines the maximum proposal metadata length.
MaxMetadataLen uint64
// MaxOptionsLen defines the maximum number of options a proposal can have.
MaxOptionsLen uint64
// MaxVoteOptionsLen defines the maximum number of options a proposal can have.
MaxVoteOptionsLen uint64
}

// DefaultConfig returns the default config for gov.
func DefaultConfig() Config {
return Config{
MaxMetadataLen: 255,
MaxOptionsLen: 1,
MaxMetadataLen: 255,
MaxVoteOptionsLen: 1,
}
}

0 comments on commit 5f55293

Please sign in to comment.