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

Slashing fixes #466

Merged
merged 4 commits into from
Mar 20, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"

"github.com/notional-labs/composable/v6/app/keepers"
"github.com/notional-labs/composable/v6/app/upgrades/v6_4_7"
"github.com/notional-labs/composable/v6/app/upgrades/v6_4_8"

// bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

Expand Down Expand Up @@ -147,7 +147,7 @@ var (
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""

Upgrades = []upgrades.Upgrade{v6_4_7.Upgrade}
Upgrades = []upgrades.Upgrade{v6_4_8.Upgrade}
Forks = []upgrades.Fork{}
)

Expand Down
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ 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(),
)
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/v6_4_8/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v6_4_8

import (
"github.com/notional-labs/composable/v6/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name for the composable upgrade.
UpgradeName = "v6_4_8"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
43 changes: 43 additions & 0 deletions app/upgrades/v6_4_8/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v6_4_8

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"
)

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) {
// remove broken proposals
BrokenProposals := [3]uint64{2, 6, 11}
for _, proposal_id := range BrokenProposals {
_, ok := keepers.GovKeeper.GetProposal(ctx, proposal_id)
if ok {
keepers.GovKeeper.DeleteProposal(ctx, proposal_id)
}

}

// 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)
}
return mm.RunMigrations(ctx, configurator, vm)
}
}
17 changes: 0 additions & 17 deletions custom/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -93,11 +82,5 @@ func (k Keeper) TotalSupply(ctx context.Context, req *types.QueryTotalSupplyRequ
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
}
45 changes: 43 additions & 2 deletions custom/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package keeper

import (
"fmt"

"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"
)

Expand All @@ -16,6 +21,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 {
Expand Down Expand Up @@ -117,6 +125,39 @@ 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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ replace (

github.com/cosmos/cosmos-sdk v0.47.5 => github.com/rust-ninja/cosmos-sdk v0.47.5-patch-validators-trim-tag

github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 => github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827
// ibc-go with wasm client
github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827 h1:PkDT2gEjAgttuF9lZTP+niYjcXutnmqHHK2UaAL9bLs=
github.com/ComposableFi/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20240320115741-f32994360827/go.mod h1:3PHOr4UiPNtnZJutT22fm5+pjIefTlDEgtWGoOJg3A0=
github.com/CosmWasm/wasmd v0.40.1 h1:LxbO78t/6S8TkeQlUrJ0m5O87HtAwLx4RGHq3rdrOEU=
github.com/CosmWasm/wasmd v0.40.1/go.mod h1:6EOwnv7MpuFaEqxcUOdFV9i4yvrdOciaY6VQ1o7A3yg=
github.com/CosmWasm/wasmvm v1.2.6 h1:QmOaiJUyeh8+pPCjJBTgWrbi/hCzCuWewduDO85Pcpc=
Expand Down Expand Up @@ -968,8 +970,6 @@ github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm
github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c=
github.com/notional-labs/alliance v1.0.1-0.20231106184124-5cc1ff759647 h1:vCSokMIO60u0td51l7NB+pikUChJozIwIb4u8UeqTKI=
github.com/notional-labs/alliance v1.0.1-0.20231106184124-5cc1ff759647/go.mod h1:GFQ8TsXDMTpu7kif0Dwddz6rxazy0ZJQHfN38ZmAodI=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9 h1:4rte3LTbrQnlu0Gnw6gouj2voGwgjweORA1dcgnQxlU=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0-20231027045618-f659894b12d9/go.mod h1:3PHOr4UiPNtnZJutT22fm5+pjIefTlDEgtWGoOJg3A0=
github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f h1:Uw35VHCdLTsQf8B4UGTjHCR6HqcYFF6dwPW8uJzS0f4=
github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f/go.mod h1:hjcl3RPLSDf0LSXrFyk2iTQCCFs5pfLbJb8h/5gJ2Vg=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
6 changes: 1 addition & 5 deletions tests/interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ 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
}
7 changes: 2 additions & 5 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()),
),
)
Expand Down
2 changes: 2 additions & 0 deletions x/mint/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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"
Expand Down
2 changes: 1 addition & 1 deletion x/transfermiddleware/ibc_ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// NOTE: This is the address of the gov authority on the chain that is being tested.
// This means that we need to check bech32 .... everywhere.
var govAuthorityAddress = "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
var govAuthorityAddress = "centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m"

// ORIGINAL NOTES:
// convert from: centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m
Expand Down
Loading