Skip to content

Commit

Permalink
[1760]: In the umber upgrades, set the new gov params fields as desired.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Jun 12, 2024
1 parent ba03fc5 commit ad1ce0c
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 0 deletions.
80 changes: 80 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package app
import (
"context"
"fmt"
"time"

sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

Expand Down Expand Up @@ -81,6 +83,11 @@ var upgrades = map[string]appUpgrade{
return nil, err
}

err = setNewGovParamsTestnet(ctx, app)
if err != nil {
return nil, err
}

updateIBCClients(ctx, app)

removeInactiveValidatorDelegations(ctx, app)
Expand Down Expand Up @@ -120,6 +127,11 @@ var upgrades = map[string]appUpgrade{
return nil, err
}

err = setNewGovParamsMainnet(ctx, app)
if err != nil {
return nil, err
}

updateIBCClients(ctx, app)

removeInactiveValidatorDelegations(ctx, app)
Expand Down Expand Up @@ -477,3 +489,71 @@ func migrateIbcHooksParams(ctx sdk.Context, app *App) {

ctx.Logger().Info("Done migrating ibchooks params.")
}

// setNewGovParamsTestnet updates the newly added gov params fields to have the values we want for testnet.
// TODO: Remove with the umber handlers.
func setNewGovParamsTestnet(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Setting new gov params for testnet.")

params, err := app.GovKeeper.Params.Get(ctx)
if err != nil {
return fmt.Errorf("error getting gov params: %w", err)
}

params.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.00002").String()
params.MinDepositRatio = sdkmath.LegacyZeroDec().String()

params.ProposalCancelRatio = sdkmath.LegacyZeroDec().String()
params.ProposalCancelDest = ""

expVP := time.Minute * 5
params.ExpeditedVotingPeriod = &expVP
params.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.667").String()
params.ExpeditedMinDeposit = params.MinDeposit

params.BurnVoteQuorum = false
params.BurnProposalDepositPrevote = false
params.BurnVoteVeto = true

err = app.GovKeeper.Params.Set(ctx, params)
if err != nil {
return fmt.Errorf("error setting updated gov params: %w", err)
}

ctx.Logger().Info("Done setting new gov params for testnet.")
return nil
}

// setNewGovParamsMainnet updates the newly added gov params fields to have the values we want for mainnet.
// TODO: Remove with the umber handlers.
func setNewGovParamsMainnet(ctx sdk.Context, app *App) error {
ctx.Logger().Info("Setting new gov params for mainnet.")

params, err := app.GovKeeper.Params.Get(ctx)
if err != nil {
return fmt.Errorf("error getting gov params: %w", err)
}

params.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.02").String()
params.MinDepositRatio = sdkmath.LegacyZeroDec().String()

params.ProposalCancelRatio = sdkmath.LegacyMustNewDecFromStr("0.5").String()
params.ProposalCancelDest = ""

expVP := time.Hour * 24
params.ExpeditedVotingPeriod = &expVP
params.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.667").String()
params.ExpeditedMinDeposit = params.MinDeposit

params.BurnVoteQuorum = false
params.BurnProposalDepositPrevote = true
params.BurnVoteVeto = true

err = app.GovKeeper.Params.Set(ctx, params)
if err != nil {
return fmt.Errorf("error setting updated gov params: %w", err)
}

ctx.Logger().Info("Done setting new gov params for mainnet.")
return nil
}
105 changes: 105 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

internalsdk "github.com/provenance-io/provenance/internal/sdk"
Expand Down Expand Up @@ -383,6 +384,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Migrating ibchooks params.",
"INF Done migrating ibchooks params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Setting new gov params for testnet.",
"INF Done setting new gov params for testnet.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
"INF Removing inactive validator delegations.",
Expand Down Expand Up @@ -414,6 +417,8 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Migrating ibchooks params.",
"INF Done migrating ibchooks params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Setting new gov params for mainnet.",
"INF Done setting new gov params for mainnet.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
"INF Removing inactive validator delegations.",
Expand Down Expand Up @@ -647,3 +652,103 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Assert().Len(validators, 3, "GetAllValidators after %s", runnerName)
})
}

func (s *UpgradeTestSuite) TestSetNewGovParamsTestnet() {
var runErr error
runner := func() {
runErr = setNewGovParamsTestnet(s.ctx, s.app)
}
runnerName := "setNewGovParamsTestnet"

threeDays := time.Hour * 24 * 3
fiveMinutes := time.Minute * 5

iniParams := govv1.DefaultParams()
iniParams.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.25").String()
iniParams.MinDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.10").String()
iniParams.ProposalCancelRatio = sdkmath.LegacyMustNewDecFromStr("0.83").String()
iniParams.ProposalCancelDest = sdk.AccAddress("addr________________").String()
iniParams.ExpeditedVotingPeriod = &threeDays
iniParams.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.406").String()
iniParams.ExpeditedMinDeposit = []sdk.Coin{sdk.NewInt64Coin("banana", 1000)}
iniParams.BurnVoteQuorum = true
iniParams.BurnProposalDepositPrevote = true
iniParams.BurnVoteVeto = false

err := s.app.GovKeeper.Params.Set(s.ctx, iniParams)
s.Require().NoError(err, "Setting initial gov params")

expParams := govv1.DefaultParams()
expParams.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.00002").String()
expParams.MinDepositRatio = sdkmath.LegacyZeroDec().String()
expParams.ProposalCancelRatio = sdkmath.LegacyZeroDec().String()
expParams.ProposalCancelDest = ""
expParams.ExpeditedVotingPeriod = &fiveMinutes
expParams.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.667").String()
expParams.ExpeditedMinDeposit = iniParams.MinDeposit
expParams.BurnVoteQuorum = false
expParams.BurnProposalDepositPrevote = false
expParams.BurnVoteVeto = true

expLogLines := []string{
"INF Setting new gov params for testnet.",
"INF Done setting new gov params for testnet.",
}

s.ExecuteAndAssertLogs(runner, expLogLines, nil, true, runnerName)
s.Require().NoError(runErr, runnerName)

actParams, err := s.app.GovKeeper.Params.Get(s.ctx)
s.Require().NoError(err, "getting gov params after %s", runnerName)
s.Assert().Equal(expParams, actParams, "resulting gov params")
}

func (s *UpgradeTestSuite) TestSetNewGovParamsMainnet() {
var runErr error
runner := func() {
runErr = setNewGovParamsMainnet(s.ctx, s.app)
}
runnerName := "setNewGovParamsMainnet"

threeDays := time.Hour * 24 * 3
oneDay := time.Hour * 24

iniParams := govv1.DefaultParams()
iniParams.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.25").String()
iniParams.MinDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.10").String()
iniParams.ProposalCancelRatio = sdkmath.LegacyMustNewDecFromStr("0.83").String()
iniParams.ProposalCancelDest = sdk.AccAddress("addr________________").String()
iniParams.ExpeditedVotingPeriod = &threeDays
iniParams.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.406").String()
iniParams.ExpeditedMinDeposit = []sdk.Coin{sdk.NewInt64Coin("banana", 1000)}
iniParams.BurnVoteQuorum = true
iniParams.BurnProposalDepositPrevote = false
iniParams.BurnVoteVeto = false

err := s.app.GovKeeper.Params.Set(s.ctx, iniParams)
s.Require().NoError(err, "Setting initial gov params")

expParams := govv1.DefaultParams()
expParams.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr("0.02").String()
expParams.MinDepositRatio = sdkmath.LegacyZeroDec().String()
expParams.ProposalCancelRatio = sdkmath.LegacyMustNewDecFromStr("0.5").String()
expParams.ProposalCancelDest = ""
expParams.ExpeditedVotingPeriod = &oneDay
expParams.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr("0.667").String()
expParams.ExpeditedMinDeposit = iniParams.MinDeposit
expParams.BurnVoteQuorum = false
expParams.BurnProposalDepositPrevote = true
expParams.BurnVoteVeto = true

expLogLines := []string{
"INF Setting new gov params for mainnet.",
"INF Done setting new gov params for mainnet.",
}

s.ExecuteAndAssertLogs(runner, expLogLines, nil, true, runnerName)
s.Require().NoError(runErr, runnerName)

actParams, err := s.app.GovKeeper.Params.Get(s.ctx)
s.Require().NoError(err, "getting gov params after %s", runnerName)
s.Assert().Equal(expParams, actParams, "resulting gov params")
}

0 comments on commit ad1ce0c

Please sign in to comment.