@@ -57,6 +57,7 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) {
5757 }
5858 }
5959}
60+
6061func UpdateExpeditedParams (ctx context.Context , gov govkeeper.Keeper ) error {
6162 govParams , err := gov .Params .Get (ctx )
6263 if err != nil {
@@ -83,7 +84,8 @@ func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
8384 }
8485 govParams .ExpeditedThreshold = expeditedThreshold .String ()
8586 if govParams .ExpeditedVotingPeriod != nil && govParams .VotingPeriod != nil && * govParams .ExpeditedVotingPeriod >= * govParams .VotingPeriod {
86- period := time .Second * time .Duration (DefaultPeriodRatio ()* govParams .VotingPeriod .Seconds ())
87+ votingPeriod := DurationToDec (* govParams .VotingPeriod )
88+ period := DecToDuration (DefaultPeriodRatio ().Mul (votingPeriod ))
8789 govParams .ExpeditedVotingPeriod = & period
8890 }
8991 if err := govParams .ValidateBasic (); err != nil {
@@ -96,6 +98,14 @@ func DefaultThresholdRatio() sdkmath.LegacyDec {
9698 return govv1 .DefaultExpeditedThreshold .Quo (govv1 .DefaultThreshold )
9799}
98100
99- func DefaultPeriodRatio () float64 {
100- return govv1 .DefaultExpeditedPeriod .Seconds () / govv1 .DefaultPeriod .Seconds ()
101+ func DefaultPeriodRatio () sdkmath.LegacyDec {
102+ return DurationToDec (govv1 .DefaultExpeditedPeriod ).Quo (DurationToDec (govv1 .DefaultPeriod ))
103+ }
104+
105+ func DurationToDec (d time.Duration ) sdkmath.LegacyDec {
106+ return sdkmath .LegacyMustNewDecFromStr (fmt .Sprintf ("%f" , d .Seconds ()))
107+ }
108+
109+ func DecToDuration (d sdkmath.LegacyDec ) time.Duration {
110+ return time .Second * time .Duration (d .RoundInt64 ())
101111}
0 commit comments