Skip to content

Commit

Permalink
remove distribution module
Browse files Browse the repository at this point in the history
  • Loading branch information
jpeersyst committed Jan 17, 2024
1 parent b865683 commit 6a9a267
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 94 deletions.
33 changes: 5 additions & 28 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app

import (
"cosmossdk.io/math"
"encoding/json"
ethante "github.com/evmos/evmos/v15/app/ante/evm"
"io"
"os"
"path/filepath"

"cosmossdk.io/math"
ethante "github.com/evmos/evmos/v15/app/ante/evm"

"github.com/ethereum/go-ethereum/core/vm"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -59,9 +60,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
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 @@ -163,7 +161,6 @@ var (
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -187,7 +184,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 All @@ -199,9 +195,7 @@ var (
}

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
}
allowedReceivingModAcc = map[string]bool{}
)

var (
Expand Down Expand Up @@ -249,7 +243,6 @@ type App 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 @@ -313,7 +306,7 @@ func New(

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, authz.ModuleName, banktypes.StoreKey, stakingtypes.StoreKey,
distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey,
slashingtypes.StoreKey, govtypes.StoreKey,
paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, capabilitytypes.StoreKey, crisistypes.StoreKey, consensusparamtypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
Expand Down Expand Up @@ -392,16 +385,6 @@ func New(
govAuthAddress,
)

app.DistrKeeper = distrkeeper.NewKeeper(
appCodec,
keys[distrtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
govAuthAddress,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
cdc,
Expand Down Expand Up @@ -448,7 +431,6 @@ func New(

app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.PoaKeeper.Hooks(),
),
Expand Down Expand Up @@ -574,7 +556,6 @@ func New(
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down Expand Up @@ -602,7 +583,6 @@ func New(
capabilitytypes.ModuleName,
feemarkettypes.ModuleName,
evmtypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
Expand Down Expand Up @@ -636,7 +616,6 @@ func New(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand All @@ -653,7 +632,6 @@ func New(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
Expand Down Expand Up @@ -933,7 +911,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
Expand Down
61 changes: 0 additions & 61 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,71 +77,10 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* 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
})

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

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()); err != nil {
return true
}
return false
})

// 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
}
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
return err
}
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
return err
}
}

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

Expand Down
5 changes: 4 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

Expand Down Expand Up @@ -51,7 +52,9 @@ func (app *App) setupUpgradeHandlers() {
consensusparamtypes.StoreKey,
crisistypes.ModuleName,
},
Deleted: []string{},
Deleted: []string{
distrtypes.ModuleName,
},
}
}

Expand Down
7 changes: 3 additions & 4 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,10 @@ func CreateUpgradeHandler(
logger.Error("error while enabling EIPs", "error", err)
}

// we are deprecating the crisis module since it is not being used
// TODO: subsitute this for distribution module
// we are deprecating the distribution module since it is not being used
// NOTE: this was already removed on testnet
// logger.Debug("deleting crisis module from version map...")
// delete(vm, "crisis")
logger.Debug("deleting distribution module from version map...")
delete(vm, distrtypes.ModuleName) // TODO check correct version map key

// Leave modules are as-is to avoid running InitGenesis.
logger.Debug("running module migrations ...")
Expand Down

0 comments on commit 6a9a267

Please sign in to comment.