Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 7, 2024
1 parent eaa3606 commit c7d044a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) {
}
}
}

func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
govParams, err := gov.Params.Get(ctx)
if err != nil {
Expand All @@ -83,7 +84,8 @@ func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
}
govParams.ExpeditedThreshold = expeditedThreshold.String()
if govParams.ExpeditedVotingPeriod != nil && govParams.VotingPeriod != nil && *govParams.ExpeditedVotingPeriod >= *govParams.VotingPeriod {
period := time.Second * time.Duration(DefaultPeriodRatio()*govParams.VotingPeriod.Seconds())
votingPeriod := DurationToDec(*govParams.VotingPeriod)
period := DecToDuration(DefaultPeriodRatio().Mul(votingPeriod))
govParams.ExpeditedVotingPeriod = &period
}
if err := govParams.ValidateBasic(); err != nil {
Expand All @@ -96,6 +98,14 @@ func DefaultThresholdRatio() sdkmath.LegacyDec {
return govv1.DefaultExpeditedThreshold.Quo(govv1.DefaultThreshold)
}

func DefaultPeriodRatio() float64 {
return govv1.DefaultExpeditedPeriod.Seconds() / govv1.DefaultPeriod.Seconds()
func DefaultPeriodRatio() sdkmath.LegacyDec {
return DurationToDec(govv1.DefaultExpeditedPeriod).Quo(DurationToDec(govv1.DefaultPeriod))
}

func DurationToDec(d time.Duration) sdkmath.LegacyDec {
return sdkmath.LegacyMustNewDecFromStr(fmt.Sprintf("%f", d.Seconds()))
}

func DecToDuration(d sdkmath.LegacyDec) time.Duration {
return time.Second * time.Duration(d.RoundInt64())
}
3 changes: 2 additions & 1 deletion app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (suite *AppTestSuite) TestUpdateExpeditedParams() {
suite.govParams.VotingPeriod = &period
},
exp: func(params govv1.Params) {
expected := time.Second * time.Duration(app.DefaultPeriodRatio()*suite.govParams.VotingPeriod.Seconds())
votingPeriod := app.DurationToDec(*suite.govParams.VotingPeriod)
expected := app.DecToDuration(app.DefaultPeriodRatio().Mul(votingPeriod))
suite.Require().Equal(expected, *params.ExpeditedVotingPeriod)
},
},
Expand Down

0 comments on commit c7d044a

Please sign in to comment.