Skip to content

Commit

Permalink
Disable distribution community tax in disable inflation upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Oct 23, 2023
1 parent 8186367 commit 29c94f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 15 additions & 2 deletions x/community/keeper/disable_inflation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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")
}
13 changes: 13 additions & 0 deletions x/community/testutil/disable_inflation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,6 +30,7 @@ type disableInflationTestSuite struct {

genesisMintState *minttypes.GenesisState
genesisKavadistState *kavadisttypes.GenesisState
genesisDistrState *distrtypes.GenesisState

testFunc testFunc
}
Expand Down Expand Up @@ -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)},
)
}

Expand All @@ -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"

Expand All @@ -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)))
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions x/community/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 29c94f7

Please sign in to comment.