Skip to content

Commit

Permalink
fix(app): remove distribution and claims modules
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Apr 1, 2024
1 parent fc7bd45 commit 584f6bb
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 337 deletions.
33 changes: 4 additions & 29 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ import (
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"

distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand Down Expand Up @@ -239,7 +235,6 @@ var (
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler,
Expand Down Expand Up @@ -278,7 +273,6 @@ var (
// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
Expand Down Expand Up @@ -324,7 +318,6 @@ type ExocoreApp struct {
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
Expand Down Expand Up @@ -419,7 +412,7 @@ func NewExocoreApp(
keys := sdk.NewKVStoreKeys(
// SDK keys
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
distrtypes.StoreKey, slashingtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey,
feegrant.StoreKey, authzkeeper.StoreKey, crisistypes.StoreKey,
Expand Down Expand Up @@ -522,10 +515,6 @@ func NewExocoreApp(
appCodec, keys[stakingtypes.StoreKey], accountK, bankK, authAddr,
)
app.StakingKeeper = *stakingKeeper
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], accountK, bankK,
stakingKeeper, authtypes.FeeCollectorName, authAddr,
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, app.LegacyAmino(), keys[slashingtypes.StoreKey], stakingKeeper, authAddr,
)
Expand Down Expand Up @@ -599,11 +588,10 @@ func NewExocoreApp(

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
// NOTE: Distr and Slashing must be created before calling the Hooks method to avoid
// NOTE: Slashing must be created before calling the Hooks method to avoid
// returning a Keeper without its table generated
stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
),
)
Expand Down Expand Up @@ -670,7 +658,6 @@ func NewExocoreApp(
evmKeeper.WithPrecompiles(
evmkeeper.AvailablePrecompiles(
*stakingKeeper,
app.DistrKeeper,
app.AuthzKeeper,
app.TransferKeeper,
app.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -801,14 +788,6 @@ func NewExocoreApp(
app.StakingKeeper,
app.GetSubspace(slashingtypes.ModuleName),
),
distr.NewAppModule(
appCodec,
app.DistrKeeper,
accountK,
bankK,
app.StakingKeeper,
app.GetSubspace(distrtypes.ModuleName),
),
staking.NewAppModule(
appCodec,
&app.StakingKeeper,
Expand Down Expand Up @@ -862,7 +841,7 @@ func NewExocoreApp(
exoslash.NewAppModule(appCodec, app.ExoSlashKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
// During begin block slashing happens after reward.BeginBlocker so that
// there is nothing left over in the validator fee pool, to keep the
// CanWithdrawInvariant invariant.
// NOTE: upgrade module must go first to handle software upgrades.
Expand All @@ -877,7 +856,6 @@ func NewExocoreApp(
epochstypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
Expand Down Expand Up @@ -923,7 +901,6 @@ func NewExocoreApp(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand Down Expand Up @@ -955,7 +932,6 @@ func NewExocoreApp(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
Expand Down Expand Up @@ -1076,7 +1052,7 @@ func (app *ExocoreApp) setAnteHandler(txConfig client.TxConfig, maxGasWanted uin
ExtensionOptionChecker: evmostypes.HasDynamicFeeExtensionOption,
StakingKeeper: app.StakingKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
DistributionKeeper: app.DistrKeeper,
DistributionKeeper: app.RewardKeeper,
IBCKeeper: app.IBCKeeper,
SignModeHandler: txConfig.SignModeHandler(),
SigGasConsumer: ante.SigVerificationGasConsumer,
Expand Down Expand Up @@ -1331,7 +1307,6 @@ func initParamsKeeper(
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).
// nolint: staticcheck
Expand Down
141 changes: 16 additions & 125 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"encoding/json"
"fmt"

"cosmossdk.io/simapp"

Expand All @@ -17,7 +16,6 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
claimstypes "github.com/evmos/evmos/v14/x/claims/types"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"

"github.com/evmos/evmos/v14/encoding"
Expand Down Expand Up @@ -57,11 +55,11 @@ func NewDefaultGenesisState(cdc codec.Codec) simapp.GenesisState {
defaultGenesis[evmtypes.ModuleName] = cdc.MustMarshalJSON(&evmGenesis)

// claims module
claimsGenesis := claimstypes.GenesisState{}
rawGenesis = defaultGenesis[claimstypes.ModuleName]
cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis)
claimsGenesis.Params.ClaimsDenom = utils.BaseDenom
defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis)
// claimsGenesis := claimstypes.GenesisState{}
// rawGenesis = defaultGenesis[claimstypes.ModuleName]
// cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis)
// claimsGenesis.Params.ClaimsDenom = utils.BaseDenom
// defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis)

return defaultGenesis
}
Expand Down Expand Up @@ -111,157 +109,50 @@ func (app *ExocoreApp) ExportAppStateAndValidators(
// in favor of export at a block height
func (app *ExocoreApp) prepForZeroHeightGenesis(
ctx sdk.Context,
jailAllowedAddrs []string,
_ []string,
) error {
applyAllowedAddrs := false
// allowedAddrsMap := make(map[string]bool)

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}

allowedAddrsMap := make(map[string]bool)

for _, addr := range jailAllowedAddrs {
_, err := sdk.ValAddressFromBech32(addr)
if err != nil {
return err
}
allowedAddrsMap[addr] = true
}
// for _, addr := range jailAllowedAddrs {
// _, err := sdk.ValAddressFromBech32(addr)
// if err != nil {
// return err
// }
// allowedAddrsMap[addr] = true
// }

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)

/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
return false
},
)
// TODO(mm): replace with new reward distribution keeper.

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
return err
}

delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
if err != nil {
return err
}
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
}

// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(
ctx,
func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(
ctx,
val.GetOperator(),
)
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
// this lets us stop in case there's an error
return err != nil
},
)

// reinitialize all delegations
for _, del := range dels {
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if err != nil {
return err
}
delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress)
if err != nil {
return err
}
err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
if err != nil {
return err
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
if err != nil {
return err
}
}

// reset context height
ctx = ctx.WithBlockHeight(height)

/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(
ctx,
func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
return false
},
)
// not supported: iterate through redelegations, reset creation height

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(
ctx,
func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false
},
)

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
return fmt.Errorf("expected validator %s not found", addr)
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}

if err := iter.Close(); err != nil {
return err
}

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
return err
Expand Down
21 changes: 10 additions & 11 deletions precompiles/delegation/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/evmos/v14/utils"
"github.com/evmos/evmos/v14/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v14/x/evm/types"
)
Expand Down Expand Up @@ -98,11 +97,11 @@ func (s *DelegationPrecompileSuite) TestRunDelegateToThroughClientChain() {
}
commonMalleate := func() (common.Address, []byte) {
// prepare the call input for delegation test
valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
s.Require().NoError(err)
val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
// valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
// s.Require().NoError(err)
// val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
// coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
// s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
input, err := s.precompile.Pack(
delegation.MethodDelegateToThroughClientChain,
uint16(clientChainLzID),
Expand Down Expand Up @@ -340,11 +339,11 @@ func (s *DelegationPrecompileSuite) TestRunUnDelegateFromThroughClientChain() {
}
commonMalleate := func() (common.Address, []byte) {
// prepare the call input for delegation test
valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
s.Require().NoError(err)
val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
// valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress)
// s.Require().NoError(err)
// val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr)
// coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18)))
// s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...))
input, err := s.precompile.Pack(
delegation.MethodUndelegateFromThroughClientChain,
uint16(clientChainLzID),
Expand Down
Loading

0 comments on commit 584f6bb

Please sign in to comment.