Skip to content

Commit

Permalink
feat(x/gov): hard min voting period to 3 weeks (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
giunatale authored Sep 17, 2024
1 parent bf92e1e commit 77ae416
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion x/gov/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -1023,7 +1024,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() {
}
},
expErr: true,
expErrMsg: "voting period must be positive",
expErrMsg: fmt.Sprintf("voting period must be at least %s: 0s", v1.MinVotingPeriod.String()),
},
}

Expand Down
17 changes: 10 additions & 7 deletions x/gov/types/v1/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Default period for deposits & voting
// Default period for deposits & voting and min voting period
const (
DefaultPeriod time.Duration = time.Hour * 24 * 2 // 2 days
DefaultVotingPeriod time.Duration = time.Hour * 24 * 21 // 21 days
MinVotingPeriod time.Duration = time.Hour * 24 * 21 // 21 days
DefaultDepositPeriod time.Duration = time.Hour * 24 * 14 // 14 days
)

// Default governance params
var (
minVotingPeriod = MinVotingPeriod
DefaultMinDepositTokens = sdk.NewInt(10000000)
DefaultQuorum = sdk.NewDecWithPrec(334, 3)
DefaultThreshold = sdk.NewDecWithPrec(5, 1)
Expand Down Expand Up @@ -73,8 +76,8 @@ func NewParams(
func DefaultParams() Params {
return NewParams(
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinDepositTokens)),
DefaultPeriod,
DefaultPeriod,
DefaultDepositPeriod,
DefaultVotingPeriod,
DefaultQuorum.String(),
DefaultThreshold.String(),
DefaultVetoThreshold.String(),
Expand Down Expand Up @@ -133,11 +136,11 @@ func (p Params) ValidateBasic() error {
}

if p.VotingPeriod == nil {
return fmt.Errorf("voting period must not be nil: %d", p.VotingPeriod)
return fmt.Errorf("voting period must not be nil")
}

if p.VotingPeriod.Seconds() <= 0 {
return fmt.Errorf("voting period must be positive: %s", p.VotingPeriod)
if p.VotingPeriod.Seconds() < minVotingPeriod.Seconds() {
return fmt.Errorf("voting period must be at least %s: %s", minVotingPeriod.String(), p.VotingPeriod.String())
}

minInitialDepositRatio, err := math.LegacyNewDecFromStr(p.MinInitialDepositRatio)
Expand Down
4 changes: 2 additions & 2 deletions x/gov/types/v1/params_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func validateVotingParams(i interface{}) error {
return errors.New("voting period must not be nil")
}

if v.VotingPeriod.Seconds() <= 0 {
return fmt.Errorf("voting period must be positive: %s", v.VotingPeriod)
if v.VotingPeriod.Seconds() < MinVotingPeriod.Seconds() {
return fmt.Errorf("voting period must be at least %s: %s", MinVotingPeriod.String(), v.VotingPeriod.String())
}

return nil
Expand Down
7 changes: 4 additions & 3 deletions x/gov/types/v1beta1/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

// Default period for deposits & voting
const (
DefaultPeriod time.Duration = time.Hour * 24 * 2 // 2 days
DefaultVotingPeriod time.Duration = time.Hour * 24 * 21 // 21 days
DefaultDepositPeriod time.Duration = time.Hour * 24 * 14 // 14 days
)

// Default governance params
Expand All @@ -33,7 +34,7 @@ func NewDepositParams(minDeposit sdk.Coins, maxDepositPeriod time.Duration) Depo
func DefaultDepositParams() DepositParams {
return NewDepositParams(
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinDepositTokens)),
DefaultPeriod,
DefaultDepositPeriod,
)
}

Expand Down Expand Up @@ -82,7 +83,7 @@ func NewVotingParams(votingPeriod time.Duration) VotingParams {

// DefaultVotingParams default parameters for voting
func DefaultVotingParams() VotingParams {
return NewVotingParams(DefaultPeriod)
return NewVotingParams(DefaultVotingPeriod)
}

// Equal checks equality of TallyParams
Expand Down

0 comments on commit 77ae416

Please sign in to comment.