Skip to content

Commit

Permalink
fix!: add missing gov v5 migration param section (#3387)
Browse files Browse the repository at this point in the history
* fix!: add missing gov v5 migration param section

* chore: changelogs and lint
  • Loading branch information
MSalopek authored Oct 14, 2024
1 parent 76e3448 commit 6f410a5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
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)
}

0 comments on commit 6f410a5

Please sign in to comment.