0g-chain/x/community/keeper/disable_inflation.go

80 lines
2.6 KiB
Go
Raw Normal View History

package keeper
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/community/types"
)
// CheckAndDisableMintAndKavaDistInflation compares the disable inflation time and block time,
// and disables inflation if time is set and before block time. Inflation time is reset,
// so this method is safe to call more than once.
func (k Keeper) CheckAndDisableMintAndKavaDistInflation(ctx sdk.Context) {
// panic if params are not found since this can only be reached if chain state is corrupted or method is ran at an invalid height
params := k.mustGetParams(ctx)
// if disable inflation time is in the future or zero there is nothing to do, so return
if params.UpgradeTimeDisableInflation.IsZero() || params.UpgradeTimeDisableInflation.After(ctx.BlockTime()) {
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!")
// reset disable inflation time to ensure next call is a no-op
params.UpgradeTimeDisableInflation = time.Time{}
// set staking rewards to provided intial value
params.StakingRewardsPerSecond = params.UpgradeTimeSetStakingRewardsPerSecond
k.SetParams(ctx, params)
`x/community` events and e2e test improvements (#1766) * Initial e2e setup * Fix inflation disable tests * Add upgrade handler * Add param tests for after upgrade * Replace deprecated grpc creds * Remove upgrade for e2e test * Update upgrade handler to set x/community params * Remove params check in upgrade * Update tests for switchover time and params check * wip inflation * Add attribute to disable inflation event * Add before/after switchover mint and dist checks * Add missing attribute to disable inflation test check * Check mint events are 0 * Check total supply doesn't change * Check inflation and events before switchover * Check staking reward payouts from x/community * move events funcs to util * Add keyring to chain, fetch keys from kvtool and test withdrawal * Remove duplicate KavaHomePath * Update subtest names to specify before/after switchover Co-authored-by: Draco <draco@dracoli.com> * Use blocktime for InflationStop event DisableTime * Test 5 blocks for staking rewards payout * Remove logging and unused lines * Check val claimed balance with queried * Enable and update consolidation tests * Update test for modified EventTypeInflationStop time attr * Test x/distribution community tax * Fix test names * Update e2e tests for better live network test support (#1749) * Update e2e tests to support mirrornet * Skip claim rewards on live network, require no errors for existing tests * Update readme with upgrade height * Update .env example with usdt contract address * Restore .env file to original local e2e * Log community params when set * Make AttributeKeyInflationDisableTime more precise * Add mainnet and testnet community params (#1753) * Re-enable ibc tests * Remove duplicate types.EventTypeInflationStop emit * feat: set validator minimum commissions to at least 5% in upgrade handler (#1761) * Update validator min commission in upgrade * Add min commission upgrade test * Update changelog * Set validator MaxRate, call BeforeValidatorModified hook * Check max commission and update time in tests * Update e2e test for max rate * Test val update time * Use SdkBlock instead of Block * Remove upgrade related handlers and tests Preserve any module and test util changes * Update e2e x/community params proposal test to work without upgrade handler --------- Co-authored-by: Draco <draco@dracoli.com>
2023-10-31 23:37:40 +00:00
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeInflationStop,
sdk.NewAttribute(
types.AttributeKeyInflationDisableTime,
ctx.BlockTime().Format(time.RFC3339),
),
),
)
if err := k.StartCommunityFundConsolidation(ctx); err != nil {
panic(err)
}
}
// TODO: double check this is correct method for disabling inflation in kavadist without
// affecting rewards. In addition, inflation periods in kavadist should be removed.
func (k Keeper) disableInflation(ctx sdk.Context) {
logger := k.Logger(ctx)
// set x/min inflation to 0
mintParams := k.mintKeeper.GetParams(ctx)
mintParams.InflationMin = sdk.ZeroDec()
mintParams.InflationMax = sdk.ZeroDec()
k.mintKeeper.SetParams(ctx, mintParams)
logger.Info("x/mint inflation set to 0")
// disable kavadist inflation
kavadistParams := k.kavadistKeeper.GetParams(ctx)
kavadistParams.Active = false
k.kavadistKeeper.SetParams(ctx, kavadistParams)
logger.Info("x/kavadist inflation disabled")
}
// 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")
}