Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: add missing gov v5 migration param section (backport #3387) #3389

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3387-add-gov-v5-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Initialize uninitialized governance params
([\#3387](https://github.com/cosmos/gaia/pull/3387))
18 changes: 18 additions & 0 deletions app/upgrades/v21/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govparams "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/cosmos/gaia/v21/app/keepers"
)
Expand Down Expand Up @@ -63,6 +64,11 @@ func CreateUpgradeHandler(
ctx.Logger().Error("Error initializing Constitution Collection:", "message", err.Error())
}

err = InitializeGovParams(ctx, *keepers.GovKeeper)
if err != nil {
ctx.Logger().Error("Error initializing Gov Params:", "message", err.Error())
}

ctx.Logger().Info("Upgrade v21 complete")
return vm, nil
}
Expand Down Expand Up @@ -133,3 +139,15 @@ func AllocateNeutronAndStrideUnaccountedDenoms(ctx sdk.Context, providerKeeper p
func InitializeConstitutionCollection(ctx sdk.Context, govKeeper govkeeper.Keeper) error {
return govKeeper.Constitution.Set(ctx, "This chain has no constitution.")
}

func InitializeGovParams(ctx sdk.Context, govKeeper govkeeper.Keeper) error {
params, err := govKeeper.Params.Get(ctx)
if err != nil {
return err
}

params.ProposalCancelRatio = govparams.DefaultProposalCancelRatio.String()
params.ProposalCancelDest = govparams.DefaultProposalCancelDestAddress

return govKeeper.Params.Set(ctx, params)
}
36 changes: 36 additions & 0 deletions app/upgrades/v21/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

govparams "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

"github.com/cosmos/gaia/v21/app/helpers"
v21 "github.com/cosmos/gaia/v21/app/upgrades/v21"
)
Expand Down Expand Up @@ -44,3 +46,37 @@ func TestInitializeConstitutionCollection(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "This chain has no constitution.", post)
}

func TestInitializeGovParams(t *testing.T) {
gaiaApp := helpers.Setup(t)
ctx := gaiaApp.NewUncachedContext(true, tmproto.Header{})

govKeeper := gaiaApp.GovKeeper

// sets the params to "" so we can confirm that the migration
// function actually changes the parameter to 0.5 from ""
setupParams, err := govKeeper.Params.Get(ctx)
require.NoError(t, err)
setupParams.ProposalCancelRatio = "" // mainnet value
setupParams.ProposalCancelDest = "" // mainnet value
if err := govKeeper.Params.Set(ctx, setupParams); err != nil {
t.Fatalf("error setting params: %s", err)
}

pre, err := govKeeper.Params.Get(ctx)
require.NoError(t, err)
require.Equal(t, "", pre.ProposalCancelRatio) // mainnet value
require.NotEqual(t, govparams.DefaultProposalCancelRatio.String(), pre.ProposalCancelRatio)

err = v21.InitializeGovParams(ctx, *govKeeper)
require.NoError(t, err)

post, err := govKeeper.Params.Get(ctx)
require.NoError(t, err)

require.NotEqual(t, pre.ProposalCancelRatio, post.ProposalCancelRatio)
require.Equal(t, govparams.DefaultProposalCancelRatio.String(), post.ProposalCancelRatio) // confirm change to sdk default

require.Equal(t, pre.ProposalCancelDest, post.ProposalCancelDest) // does not change (it was already default)
require.Equal(t, "", post.ProposalCancelDest)
}
Loading