From 29c94f7119237cdc37571b4addc0b7088f7643b0 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Mon, 23 Oct 2023 10:34:38 -0700 Subject: [PATCH] Disable distribution community tax in disable inflation upgrade --- x/community/keeper/disable_inflation.go | 17 +++++++++++++++-- x/community/testutil/disable_inflation.go | 13 +++++++++++++ x/community/types/expected_keepers.go | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/x/community/keeper/disable_inflation.go b/x/community/keeper/disable_inflation.go index 87c486b3db..6eecabfc3e 100644 --- a/x/community/keeper/disable_inflation.go +++ b/x/community/keeper/disable_inflation.go @@ -19,8 +19,14 @@ func (k Keeper) CheckAndDisableMintAndKavaDistInflation(ctx sdk.Context) { return } + logger := k.Logger(ctx) + logger.Info("disable inflation upgrade started") + // run disable inflation logic k.disableInflation(ctx) + k.disableCommunityTax(ctx) + + logger.Info("disable inflation upgrade finished successfully!") ctx.EventManager().EmitEvent( sdk.NewEvent( @@ -43,7 +49,6 @@ func (k Keeper) CheckAndDisableMintAndKavaDistInflation(ctx sdk.Context) { // affecting rewards. In addition, inflation periods in kavadist should be removed. func (k Keeper) disableInflation(ctx sdk.Context) { logger := k.Logger(ctx) - logger.Info("disable inflation upgrade started") // set x/min inflation to 0 mintParams := k.mintKeeper.GetParams(ctx) @@ -57,6 +62,14 @@ func (k Keeper) disableInflation(ctx sdk.Context) { kavadistParams.Active = false k.kavadistKeeper.SetParams(ctx, kavadistParams) logger.Info("x/kavadist inflation disabled") +} - logger.Info("disable inflation upgrade finished successfully!") +// disableCommunityTax sets x/distribution Params.CommunityTax to 0 +func (k Keeper) disableCommunityTax(ctx sdk.Context) { + logger := k.Logger(ctx) + + distrParams := k.distrKeeper.GetParams(ctx) + distrParams.CommunityTax = sdk.ZeroDec() + k.distrKeeper.SetParams(ctx, distrParams) + logger.Info("x/distribution community tax set to 0") } diff --git a/x/community/testutil/disable_inflation.go b/x/community/testutil/disable_inflation.go index 9edff7d481..68b99013bc 100644 --- a/x/community/testutil/disable_inflation.go +++ b/x/community/testutil/disable_inflation.go @@ -4,6 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -29,6 +30,7 @@ type disableInflationTestSuite struct { genesisMintState *minttypes.GenesisState genesisKavadistState *kavadisttypes.GenesisState + genesisDistrState *distrtypes.GenesisState testFunc testFunc } @@ -57,10 +59,15 @@ func (suite *disableInflationTestSuite) SetupTest() { kavadistGen.Params.Active = true suite.genesisKavadistState = kavadistGen + distrGen := distrtypes.DefaultGenesisState() + distrGen.Params.CommunityTax = sdk.MustNewDecFromStr("0.949500000000000000") + suite.genesisDistrState = distrGen + appCodec := tApp.AppCodec() suite.App.InitializeFromGenesisStates( app.GenesisState{minttypes.ModuleName: appCodec.MustMarshalJSON(mintGen)}, app.GenesisState{kavadisttypes.ModuleName: appCodec.MustMarshalJSON(kavadistGen)}, + app.GenesisState{distrtypes.ModuleName: appCodec.MustMarshalJSON(distrGen)}, ) } @@ -70,10 +77,12 @@ func (suite *disableInflationTestSuite) TestDisableInflation() { suite.Require().True(found) mintParams := suite.App.GetMintKeeper().GetParams(suite.Ctx) kavadistParams := suite.App.GetKavadistKeeper().GetParams(suite.Ctx) + distrParams := suite.App.GetDistrKeeper().GetParams(suite.Ctx) disableTimeMsg := "expected inflation disable time to match" expectedMintState := suite.genesisMintState expectedKavadistState := suite.genesisKavadistState + expectedDistrState := suite.genesisDistrState expectedStakingRewards := originalStakingRewards msgSuffix := "before upgrade" @@ -92,6 +101,9 @@ func (suite *disableInflationTestSuite) TestDisableInflation() { expectedMintState.Params.InflationMax = sdk.ZeroDec() expectedKavadistState.Params.Active = false + + expectedDistrState.Params.CommunityTax = sdk.ZeroDec() + msgSuffix = "after upgrade" suite.Require().NoError(app.EventsContains(suite.Ctx.EventManager().Events(), sdk.NewEvent(types.EventTypeInflationStop))) @@ -100,6 +112,7 @@ func (suite *disableInflationTestSuite) TestDisableInflation() { suite.Require().Equal(expectedMintState.Params.InflationMin, mintParams.InflationMin, msg+": expected mint inflation min to match state "+msgSuffix) suite.Require().Equal(expectedMintState.Params.InflationMax, mintParams.InflationMax, msg+": expected mint inflation max to match state "+msgSuffix) suite.Require().Equal(expectedKavadistState.Params.Active, kavadistParams.Active, msg+":expected kavadist active flag match state "+msgSuffix) + suite.Require().Equal(expectedDistrState.Params.CommunityTax, distrParams.CommunityTax, msg+":expected x/distribution community tax to match state "+msgSuffix) suite.Require().Equal(expectedDisableTime, params.UpgradeTimeDisableInflation, msg+": "+disableTimeMsg) // we always check staking rewards per second matches the passed in expectation diff --git a/x/community/types/expected_keepers.go b/x/community/types/expected_keepers.go index 1e6c95a786..d4ca00244b 100644 --- a/x/community/types/expected_keepers.go +++ b/x/community/types/expected_keepers.go @@ -43,6 +43,8 @@ type DistributionKeeper interface { GetFeePoolCommunityCoins(ctx sdk.Context) sdk.DecCoins GetFeePool(ctx sdk.Context) distrtypes.FeePool SetFeePool(ctx sdk.Context, feePool distrtypes.FeePool) + GetParams(ctx sdk.Context) distrtypes.Params + SetParams(ctx sdk.Context, params distrtypes.Params) } type MintKeeper interface {