From 391729c158db810657d7a8e0e11a878649456a1f Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 6 Mar 2024 17:22:15 +0000 Subject: [PATCH] Revert "Merge pull request #451 from ComposableFi/slashing_fix" This reverts commit 1ad42931734cfe7a9021ea27c70a45f8e52ad5c6, reversing changes made to 85e2bf9d7dbda4bcbdc5fb0698479f98aa8453ec. --- Makefile | 2 +- app/keepers/keepers.go | 2 -- app/upgrades/v6_4_5/constants.go | 6 ----- app/upgrades/v6_4_5/upgrade.go | 17 ------------ app/upgrades/v6_4_6/constants.go | 22 +++++++++++++++ app/upgrades/v6_4_6/upgrade.go | 28 +++++++++++++++++++ custom/bank/keeper/keeper.go | 19 +++++++++++++ custom/staking/keeper/keeper.go | 46 +++----------------------------- tests/interchaintest/setup.go | 3 ++- x/mint/abci.go | 7 +++-- x/mint/types/events.go | 2 -- 11 files changed, 80 insertions(+), 74 deletions(-) create mode 100644 app/upgrades/v6_4_6/constants.go create mode 100644 app/upgrades/v6_4_6/upgrade.go diff --git a/Makefile b/Makefile index d2191acdc..26d1cf2b2 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ build: go build $(BUILD_FLAGS) -o bin/centaurid ./cmd/centaurid docker-build-debug: - @DOCKER_BUILDKIT=1 docker build -t centauri:local -f Dockerfile . + @DOCKER_BUILDKIT=1 docker build -t centauri:debug -f Dockerfile . lint: @find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run mvdan.cc/gofumpt -w . diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index a0a6f810f..4d1af8e2f 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -211,8 +211,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers( appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - appKeepers.StakingKeeper.RegisterKeepers(appKeepers.DistrKeeper, appKeepers.BankKeeper) - appKeepers.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, cdc, appKeepers.keys[slashingtypes.StoreKey], appKeepers.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) diff --git a/app/upgrades/v6_4_5/constants.go b/app/upgrades/v6_4_5/constants.go index 19a44a04c..27afc17b0 100644 --- a/app/upgrades/v6_4_5/constants.go +++ b/app/upgrades/v6_4_5/constants.go @@ -1,9 +1,7 @@ package v6_4_5 import ( - store "github.com/cosmos/cosmos-sdk/store/types" "github.com/notional-labs/composable/v6/app/upgrades" - ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" ) const ( @@ -14,8 +12,4 @@ const ( var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: store.StoreUpgrades{ - Added: []string{ibctransfermiddleware.StoreKey}, - Deleted: []string{}, - }, } diff --git a/app/upgrades/v6_4_5/upgrade.go b/app/upgrades/v6_4_5/upgrade.go index 91b0cf81a..72dbebe02 100644 --- a/app/upgrades/v6_4_5/upgrade.go +++ b/app/upgrades/v6_4_5/upgrade.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/notional-labs/composable/v6/app/keepers" "github.com/notional-labs/composable/v6/app/upgrades" - ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" ) func CreateUpgradeHandler( @@ -19,26 +18,10 @@ func CreateUpgradeHandler( keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // remove broken proposals BrokenProposals := [3]uint64{2, 6, 11} for _, proposal := range BrokenProposals { keepers.GovKeeper.DeleteProposal(ctx, proposal) } - - // burn extra ppica in escrow account - // this ppica is unused because it is a native token stored in escrow account - // it was unnecessarily minted to match pica escrowed on picasso to ppica minted - // in genesis, to make initial native ppica transferrable to picasso - amount, ok := sdk.NewIntFromString("1066669217167120000000") - if ok { - coins := sdk.Coins{sdk.NewCoin("ppica", amount)} - keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32("centauri12k2pyuylm9t7ugdvz67h9pg4gmmvhn5vmvgw48"), "gov", coins) - keepers.BankKeeper.BurnCoins(ctx, "gov", coins) - } - - custommiddlewareparams := ibctransfermiddleware.DefaultGenesisState() - keepers.IbcTransferMiddlewareKeeper.SetParams(ctx, custommiddlewareparams.Params) - return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/app/upgrades/v6_4_6/constants.go b/app/upgrades/v6_4_6/constants.go new file mode 100644 index 000000000..981d04382 --- /dev/null +++ b/app/upgrades/v6_4_6/constants.go @@ -0,0 +1,22 @@ +package v6_4_6 + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/notional-labs/composable/v6/app/upgrades" + ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" +) + +const ( + // UpgradeName defines the on-chain upgrade name for the composable upgrade. + UpgradeName = "v6_4_6" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{ibctransfermiddleware.StoreKey}, + Deleted: []string{}, + }, +} diff --git a/app/upgrades/v6_4_6/upgrade.go b/app/upgrades/v6_4_6/upgrade.go new file mode 100644 index 000000000..183e63e80 --- /dev/null +++ b/app/upgrades/v6_4_6/upgrade.go @@ -0,0 +1,28 @@ +package v6_4_6 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/notional-labs/composable/v6/app/keepers" + "github.com/notional-labs/composable/v6/app/upgrades" + ibctransfermiddleware "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + _ upgrades.BaseAppParamManager, + _ codec.Codec, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // Add params for custom middleware + custommiddlewareparams := ibctransfermiddleware.DefaultGenesisState() + keepers.IbcTransferMiddlewareKeeper.SetParams(ctx, custommiddlewareparams.Params) + + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/custom/bank/keeper/keeper.go b/custom/bank/keeper/keeper.go index 4b6d87e03..a7c312c6d 100644 --- a/custom/bank/keeper/keeper.go +++ b/custom/bank/keeper/keeper.go @@ -18,6 +18,7 @@ import ( transfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/transfermiddleware/keeper" alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper" + alliancetypes "github.com/terra-money/alliance/x/alliance/types" ) type Keeper struct { @@ -67,6 +68,16 @@ func (k Keeper) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) (*t ctx := sdk.UnwrapSDKContext(c) supply := k.GetSupply(ctx, req.Denom) + if req.Denom == k.sk.BondDenom(ctx) { + assets := k.ak.GetAllAssets(ctx) + totalRewardWeights := sdk.ZeroDec() + for _, asset := range assets { + totalRewardWeights = totalRewardWeights.Add(asset.RewardWeight) + } + allianceBonded := k.ak.GetAllianceBondedAmount(ctx, k.acck.GetModuleAddress(alliancetypes.ModuleName)) + supply.Amount = supply.Amount.Sub(allianceBonded) + } + return &types.QuerySupplyOfResponse{Amount: sdk.NewCoin(req.Denom, supply.Amount)}, nil } @@ -77,8 +88,16 @@ func (k Keeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequ if err != nil { return nil, status.Error(codes.Internal, err.Error()) } + // Get duplicate token from transfermiddeware duplicateCoins := k.tfmk.GetTotalEscrowedToken(sdkCtx) totalSupply = totalSupply.Sub(duplicateCoins...) + + allianceBonded := k.ak.GetAllianceBondedAmount(sdkCtx, k.acck.GetModuleAddress(alliancetypes.ModuleName)) + bondDenom := k.sk.BondDenom(sdkCtx) + if totalSupply.AmountOf(bondDenom).IsPositive() { + totalSupply = totalSupply.Sub(sdk.NewCoin(bondDenom, allianceBonded)) + } + return &types.QueryTotalSupplyResponse{Supply: totalSupply, Pagination: pageRes}, nil } diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index c5a2fcbc3..2c5b6a5dd 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -1,17 +1,13 @@ package keeper import ( - "fmt" - - "cosmossdk.io/math" abcicometbft "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - distkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/types" - minttypes "github.com/notional-labs/composable/v6/x/mint/types" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -20,9 +16,6 @@ type Keeper struct { cdc codec.BinaryCodec Stakingmiddleware *stakingmiddleware.Keeper authority string - mintKeeper minttypes.BankKeeper - distrKeeper distkeeper.Keeper - authKeeper minttypes.AccountKeeper } func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, height int64) []abcicometbft.ValidatorUpdate { @@ -124,39 +117,6 @@ func NewKeeper( authority: authority, Stakingmiddleware: stakingmiddleware, cdc: cdc, - mintKeeper: nil, - distrKeeper: distkeeper.Keeper{}, - authKeeper: ak, } return &keeper } - -func (k *Keeper) RegisterKeepers(dk distkeeper.Keeper, mk minttypes.BankKeeper) { - k.distrKeeper = dk - k.mintKeeper = mk -} - -// SlashWithInfractionReason send coins to community pool -func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, _ types.Infraction) math.Int { - // keep slashing logic the same - amountBurned := k.Slash(ctx, consAddr, infractionHeight, power, slashFactor) - // after usual slashing and burning is done, mint burned coinds into community pool - coins := sdk.NewCoins(sdk.NewCoin(k.BondDenom(ctx), amountBurned)) - err := k.mintKeeper.MintCoins(ctx, types.ModuleName, coins) - if err != nil { - k.Logger(ctx).Error("Failed to mint slashed coins: ", amountBurned) - } else { - err = k.distrKeeper.FundCommunityPool(ctx, coins, k.authKeeper.GetModuleAddress(types.ModuleName)) - if err != nil { - k.Logger(ctx).Error(fmt.Sprintf("Failed to fund community pool. Tokens minted to the staking module account: %d. ", amountBurned)) - } else { - ctx.EventManager().EmitEvent( - sdk.NewEvent( - minttypes.EventTypeMintSlashed, - sdk.NewAttribute(sdk.AttributeKeyAmount, amountBurned.String()), - ), - ) - } - } - return amountBurned -} diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 28a2fcbed..384f31cb5 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -45,10 +45,11 @@ func GetDockerImageInfo() (repo, version string) { if !found { // make local-image repo = "centauri" - branchVersion = "local" + branchVersion = "debug" } // github converts / to - for pushed docker images // branchVersion = strings.ReplaceAll(branchVersion, "/", "-") + branchVersion = "latest" return repo, branchVersion } diff --git a/x/mint/abci.go b/x/mint/abci.go index 42964667d..c24f80747 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -25,7 +25,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply) k.SetMinter(ctx, minter) - // calculate how many we would mint, but we dont mint them, we take them from the prefunded account + // mint coins, update supply mintedCoin := minter.BlockProvision(params) mintedCoins := sdk.NewCoins(mintedCoin) @@ -41,7 +41,10 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeReward, + types.EventTypeMint, + sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), + sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), + sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), ), ) diff --git a/x/mint/types/events.go b/x/mint/types/events.go index 92d52efac..891f50768 100644 --- a/x/mint/types/events.go +++ b/x/mint/types/events.go @@ -3,8 +3,6 @@ package types // Minting module event types const ( EventTypeMint = ModuleName - EventTypeReward = "reward_distributed" - EventTypeMintSlashed = "mint_slashed_into_comminity_pool" EventAddAllowedFundAddress = "add_allowed_fund" AttributeKeyBondedRatio = "bonded_ratio"