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

feat(community): disable x/distribution community tax in disable inflation upgrade #1752

Merged
merged 2 commits into from
Oct 23, 2023
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
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry.
- (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry
- (metrics) [#1669] Add performance timing metrics to all Begin/EndBlockers
- (community) [#1704] Add module params
- (community) [#1706] Add disable inflation upgrade
Expand All @@ -52,8 +52,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

- (community) [#1704] Add param to control when inflation will be disabled
- (community) [#1707] Default staking rewards per second set to `744191`
- (community) [#1706] Add disable inflation upgrade to begin blocker that updates x/mint and x/kavadist params.
- (community) [#1706] Add disable inflation upgrade to begin blocker that updates x/mint and x/kavadist params
- (community) [#1729] Consolidate community funds from `x/distribution` and `x/kavadist` to `x/community`
- (community) [#1752] Set `x/distribution` CommunityTax to zero on inflation disable upgrade

## [v0.24.0]

Expand Down Expand Up @@ -294,10 +295,12 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
large-scale simulations remotely using aws-batch

[#1752]: https://github.com/Kava-Labs/kava/pull/1752
[#1729]: https://github.com/Kava-Labs/kava/pull/1729
[#1745]: https://github.com/Kava-Labs/kava/pull/1745
[#1707]: https://github.com/Kava-Labs/kava/pull/1707
[#1706]: https://github.com/Kava-Labs/kava/pull/1706
[#1704]: https://github.com/Kava-Labs/kava/pull/1704
[#1668]: https://github.com/Kava-Labs/kava/pull/1668
[#1669]: https://github.com/Kava-Labs/kava/pull/1669
[#1655]: https://github.com/Kava-Labs/kava/pull/1655
Expand Down
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