Skip to content

Commit

Permalink
Set the new gov params fields during the umber upgrade. (#2027)
Browse files Browse the repository at this point in the history
* [1760]: In the umber upgrades, set the new gov params fields as desired.

* [1760]: Add changelog entry.

* [1760]: Tweek setNewGovParamsMainnet and setNewGovParamsTestnet to use a new setNewGovParams function so that the values are defined in the former and the updating is standardized for both.

* [1760]: Lint fix: upgrades.go import ordering.
  • Loading branch information
SpicyLemon committed Jun 14, 2024
1 parent 07042b4 commit 2058ec2
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Update `app.New` to get the home directory, invariant check period, and skip-upgrade heights from the appOptions instead of arguments [#2015](https://github.com/provenance-io/provenance/pull/2015).
* Simplify the module lists (e.g. `SetOrderEndBlockers`) by removing unneeded entries [#2015](https://github.com/provenance-io/provenance/pull/2015).
* Update the `upgrade-test.sh` script to work with v0.50 commands [#2026](https://github.com/provenance-io/provenance/pull/2026).
* Set the new gov params fields during the umber upgrades [#2027](https://github.com/provenance-io/provenance/pull/2027).

### Client Breaking

Expand Down
88 changes: 88 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"
circuittypes "cosmossdk.io/x/circuit/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand All @@ -13,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations"
Expand Down Expand Up @@ -82,6 +85,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 @@ -121,6 +129,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 @@ -478,3 +491,78 @@ func migrateIbcHooksParams(ctx sdk.Context, app *App) {

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

// 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 {
expVP := time.Hour * 24
params := govv1.Params{
MinInitialDepositRatio: "0.02",
MinDepositRatio: "0",
ProposalCancelRatio: "0.5",
ProposalCancelDest: "",
ExpeditedVotingPeriod: &expVP,
ExpeditedThreshold: "0.667",
ExpeditedMinDeposit: nil, // Will end up being the current MinDeposit value.
BurnVoteQuorum: false,
BurnProposalDepositPrevote: true,
BurnVoteVeto: true,
}
return setNewGovParams(ctx, app, params, "mainnet")
}

// 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 {
expVP := time.Minute * 5
params := govv1.Params{
MinInitialDepositRatio: "0.00002",
MinDepositRatio: "0",
ProposalCancelRatio: "0",
ProposalCancelDest: "",
ExpeditedVotingPeriod: &expVP,
ExpeditedThreshold: "0.667",
ExpeditedMinDeposit: nil, // Will end up being the current MinDeposit value.
BurnVoteQuorum: false,
BurnProposalDepositPrevote: false,
BurnVoteVeto: true,
}
return setNewGovParams(ctx, app, params, "testnet")
}

// setNewGovParams updates the gov params state to populate the new fields.
// Only the newly added fields are used from newParams.
// Fields that already existed will remain unchanged and are ignored in newParams.
// TODO: Remove with the umber handlers.
func setNewGovParams(ctx sdk.Context, app *App, newParams govv1.Params, chain string) error {
ctx.Logger().Info(fmt.Sprintf("Setting new gov params for %s.", chain))

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

params.MinInitialDepositRatio = sdkmath.LegacyMustNewDecFromStr(newParams.MinInitialDepositRatio).String()
params.MinDepositRatio = sdkmath.LegacyMustNewDecFromStr(newParams.MinDepositRatio).String()
params.ProposalCancelRatio = sdkmath.LegacyMustNewDecFromStr(newParams.ProposalCancelRatio).String()
params.ProposalCancelDest = newParams.ProposalCancelDest
params.ExpeditedVotingPeriod = newParams.ExpeditedVotingPeriod
params.ExpeditedThreshold = sdkmath.LegacyMustNewDecFromStr(newParams.ExpeditedThreshold).String()
if len(newParams.ExpeditedMinDeposit) != 0 {
params.ExpeditedMinDeposit = newParams.ExpeditedMinDeposit
} else {
params.ExpeditedMinDeposit = params.MinDeposit
}

params.BurnVoteQuorum = newParams.BurnVoteQuorum
params.BurnProposalDepositPrevote = newParams.BurnProposalDepositPrevote
params.BurnVoteVeto = newParams.BurnVoteVeto

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

ctx.Logger().Info(fmt.Sprintf("Done setting new gov params for %s.", chain))
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 2058ec2

Please sign in to comment.