From 3cd7abbe3b7086494d713c39b0c83b8dac60737b Mon Sep 17 00:00:00 2001 From: kkast Date: Fri, 23 Feb 2024 03:31:04 +0300 Subject: [PATCH 1/5] slashing fixes --- app/keepers/keepers.go | 2 ++ app/upgrades/v6_4_5/upgrade.go | 10 +++++++++ custom/bank/keeper/keeper.go | 21 ------------------- custom/staking/keeper/keeper.go | 36 ++++++++++++++++++++++++++++++--- x/mint/abci.go | 7 ++----- x/mint/types/events.go | 1 + 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index be5bb4282..ae2780a7a 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -204,6 +204,8 @@ 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/upgrade.go b/app/upgrades/v6_4_5/upgrade.go index 72dbebe02..d3fd3a2e0 100644 --- a/app/upgrades/v6_4_5/upgrade.go +++ b/app/upgrades/v6_4_5/upgrade.go @@ -18,10 +18,20 @@ 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 + 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) + } + return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/custom/bank/keeper/keeper.go b/custom/bank/keeper/keeper.go index a7c312c6d..899b69868 100644 --- a/custom/bank/keeper/keeper.go +++ b/custom/bank/keeper/keeper.go @@ -18,7 +18,6 @@ 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 { @@ -68,16 +67,6 @@ 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 } @@ -89,15 +78,5 @@ func (k Keeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequ 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 2c5b6a5dd..3aee09ab6 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -1,13 +1,15 @@ package keeper import ( + "cosmossdk.io/math" abcicometbft "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" - 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" stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" ) @@ -16,6 +18,9 @@ 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 { @@ -117,6 +122,31 @@ 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)) + k.mintKeeper.MintCoins(ctx, types.ModuleName, coins) + k.distrKeeper.FundCommunityPool(ctx, coins, k.authKeeper.GetModuleAddress(types.ModuleName)) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + minttypes.EventTypeMint, + sdk.NewAttribute(sdk.AttributeKeyAmount, amountBurned.String()), + ), + ) + return amountBurned +} diff --git a/x/mint/abci.go b/x/mint/abci.go index c24f80747..42964667d 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) - // mint coins, update supply + // calculate how many we would mint, but we dont mint them, we take them from the prefunded account mintedCoin := minter.BlockProvision(params) mintedCoins := sdk.NewCoins(mintedCoin) @@ -41,10 +41,7 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, ic types.InflationCalculatio ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeMint, - sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()), - sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()), - sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()), + types.EventTypeReward, sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()), ), ) diff --git a/x/mint/types/events.go b/x/mint/types/events.go index 891f50768..4f572b4b5 100644 --- a/x/mint/types/events.go +++ b/x/mint/types/events.go @@ -3,6 +3,7 @@ package types // Minting module event types const ( EventTypeMint = ModuleName + EventTypeReward = "reward_distributed" EventAddAllowedFundAddress = "add_allowed_fund" AttributeKeyBondedRatio = "bonded_ratio" From a7fcb928d1006ecc019b390e266adda94aaa0bff Mon Sep 17 00:00:00 2001 From: kkast Date: Tue, 27 Feb 2024 23:32:47 +0300 Subject: [PATCH 2/5] review fixes --- app/upgrades/v6_4_5/upgrade.go | 3 +++ custom/staking/keeper/keeper.go | 26 ++++++++++++++++++-------- x/mint/types/events.go | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/upgrades/v6_4_5/upgrade.go b/app/upgrades/v6_4_5/upgrade.go index d3fd3a2e0..6318f114a 100644 --- a/app/upgrades/v6_4_5/upgrade.go +++ b/app/upgrades/v6_4_5/upgrade.go @@ -25,6 +25,9 @@ func CreateUpgradeHandler( } // 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)} diff --git a/custom/staking/keeper/keeper.go b/custom/staking/keeper/keeper.go index 3aee09ab6..c5a2fcbc3 100644 --- a/custom/staking/keeper/keeper.go +++ b/custom/staking/keeper/keeper.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + "cosmossdk.io/math" abcicometbft "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" @@ -140,13 +142,21 @@ func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddr 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)) - k.mintKeeper.MintCoins(ctx, types.ModuleName, coins) - k.distrKeeper.FundCommunityPool(ctx, coins, k.authKeeper.GetModuleAddress(types.ModuleName)) - ctx.EventManager().EmitEvent( - sdk.NewEvent( - minttypes.EventTypeMint, - sdk.NewAttribute(sdk.AttributeKeyAmount, amountBurned.String()), - ), - ) + 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/x/mint/types/events.go b/x/mint/types/events.go index 4f572b4b5..92d52efac 100644 --- a/x/mint/types/events.go +++ b/x/mint/types/events.go @@ -4,6 +4,7 @@ package types const ( EventTypeMint = ModuleName EventTypeReward = "reward_distributed" + EventTypeMintSlashed = "mint_slashed_into_comminity_pool" EventAddAllowedFundAddress = "add_allowed_fund" AttributeKeyBondedRatio = "bonded_ratio" From 184986c358e027718ea128f3a4e0702821ba8981 Mon Sep 17 00:00:00 2001 From: kkast Date: Wed, 28 Feb 2024 16:18:15 +0300 Subject: [PATCH 3/5] fix tests --- custom/bank/keeper/keeper.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom/bank/keeper/keeper.go b/custom/bank/keeper/keeper.go index 899b69868..4b6d87e03 100644 --- a/custom/bank/keeper/keeper.go +++ b/custom/bank/keeper/keeper.go @@ -77,6 +77,8 @@ 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...) return &types.QueryTotalSupplyResponse{Supply: totalSupply, Pagination: pageRes}, nil } From ba7e609a06a5507dd94600e4690c0655a4399ac6 Mon Sep 17 00:00:00 2001 From: kkast Date: Wed, 28 Feb 2024 16:35:26 +0300 Subject: [PATCH 4/5] local setup --- Makefile | 2 +- tests/interchaintest/setup.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 26d1cf2b2..d2191acdc 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:debug -f Dockerfile . + @DOCKER_BUILDKIT=1 docker build -t centauri:local -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/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 384f31cb5..28a2fcbed 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -45,11 +45,10 @@ func GetDockerImageInfo() (repo, version string) { if !found { // make local-image repo = "centauri" - branchVersion = "debug" + branchVersion = "local" } // github converts / to - for pushed docker images // branchVersion = strings.ReplaceAll(branchVersion, "/", "-") - branchVersion = "latest" return repo, branchVersion } From c13eed63caed64a53f300a778a374d7dba2fe88d Mon Sep 17 00:00:00 2001 From: rustdev Date: Tue, 5 Mar 2024 17:21:10 +0000 Subject: [PATCH 5/5] upgrade merged. BankKeeper + GovKeeper + IbcTransferMiddlewareKeeper --- app/upgrades/v6_4_5/constants.go | 6 ++++++ app/upgrades/v6_4_5/upgrade.go | 4 ++++ app/upgrades/v6_4_6/constants.go | 22 ---------------------- app/upgrades/v6_4_6/upgrade.go | 28 ---------------------------- 4 files changed, 10 insertions(+), 50 deletions(-) delete mode 100644 app/upgrades/v6_4_6/constants.go delete mode 100644 app/upgrades/v6_4_6/upgrade.go diff --git a/app/upgrades/v6_4_5/constants.go b/app/upgrades/v6_4_5/constants.go index 27afc17b0..19a44a04c 100644 --- a/app/upgrades/v6_4_5/constants.go +++ b/app/upgrades/v6_4_5/constants.go @@ -1,7 +1,9 @@ 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 ( @@ -12,4 +14,8 @@ 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 6318f114a..91b0cf81a 100644 --- a/app/upgrades/v6_4_5/upgrade.go +++ b/app/upgrades/v6_4_5/upgrade.go @@ -8,6 +8,7 @@ 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( @@ -35,6 +36,9 @@ func CreateUpgradeHandler( 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 deleted file mode 100644 index 981d04382..000000000 --- a/app/upgrades/v6_4_6/constants.go +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 183e63e80..000000000 --- a/app/upgrades/v6_4_6/upgrade.go +++ /dev/null @@ -1,28 +0,0 @@ -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) - } -}