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

Make all keepers pointers, use multiple initialization methods #697

Merged
merged 5 commits into from
Jan 5, 2022
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
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// https://github.com/cosmos/cosmos-sdk/blob/v0.43.0/x/auth/ante/ante.go#L41
func NewAnteHandler(
ak ante.AccountKeeper, bankKeeper authtypes.BankKeeper,
txFeesKeeper txfeeskeeper.Keeper, spotPriceCalculator txfeestypes.SpotPriceCalculator,
txFeesKeeper *txfeeskeeper.Keeper, spotPriceCalculator txfeestypes.SpotPriceCalculator,
sigGasConsumer ante.SignatureVerificationGasConsumer,
signModeHandler signing.SignModeHandler,
channelKeeper channelkeeper.Keeper,
Expand All @@ -30,7 +30,7 @@ func NewAnteHandler(
NewMempoolMaxGasPerTxDecorator(),
// Use Mempool Fee Decorator from our txfees module instead of default one from auth
// https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/middleware/fee.go#L34
txfeeskeeper.NewMempoolFeeDecorator(txFeesKeeper),
txfeeskeeper.NewMempoolFeeDecorator(*txFeesKeeper),
ante.NewValidateBasicDecorator(),
ante.TxTimeoutHeightDecorator{},
ante.NewValidateMemoDecorator(ak),
Expand Down
373 changes: 98 additions & 275 deletions app/app.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (app *OsmosisApp) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
validators, err := staking.WriteValidators(ctx, *app.StakingKeeper)
return servertypes.ExportedApp{
AppState: appState,
Validators: validators,
Expand Down
2 changes: 1 addition & 1 deletion app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func BeginBlockForks(ctx sdk.Context, app *OsmosisApp) {
switch ctx.BlockHeight() {
case v3.UpgradeHeight:
v3.RunForkLogic(ctx, &app.GovKeeper, &app.StakingKeeper)
v3.RunForkLogic(ctx, app.GovKeeper, app.StakingKeeper)
case v6.UpgradeHeight:
v6.RunForkLogic(ctx)
default:
Expand Down
326 changes: 326 additions & 0 deletions app/keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
package app

import (
"github.com/cosmos/cosmos-sdk/baseapp"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"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"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
transfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v2/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
"github.com/osmosis-labs/bech32-ibc/x/bech32ibc"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
bech32ics20keeper "github.com/osmosis-labs/bech32-ibc/x/bech32ics20/keeper"
claimkeeper "github.com/osmosis-labs/osmosis/x/claim/keeper"
claimtypes "github.com/osmosis-labs/osmosis/x/claim/types"
epochskeeper "github.com/osmosis-labs/osmosis/x/epochs/keeper"
epochstypes "github.com/osmosis-labs/osmosis/x/epochs/types"
gammkeeper "github.com/osmosis-labs/osmosis/x/gamm/keeper"
gammtypes "github.com/osmosis-labs/osmosis/x/gamm/types"
incentiveskeeper "github.com/osmosis-labs/osmosis/x/incentives/keeper"
incentivestypes "github.com/osmosis-labs/osmosis/x/incentives/types"
lockupkeeper "github.com/osmosis-labs/osmosis/x/lockup/keeper"
lockuptypes "github.com/osmosis-labs/osmosis/x/lockup/types"
mintkeeper "github.com/osmosis-labs/osmosis/x/mint/keeper"
minttypes "github.com/osmosis-labs/osmosis/x/mint/types"
poolincentives "github.com/osmosis-labs/osmosis/x/pool-incentives"
poolincentiveskeeper "github.com/osmosis-labs/osmosis/x/pool-incentives/keeper"
poolincentivestypes "github.com/osmosis-labs/osmosis/x/pool-incentives/types"
txfeeskeeper "github.com/osmosis-labs/osmosis/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/x/txfees/types"
)

func (app *OsmosisApp) InitSpecialKeepers(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
) {
appCodec := app.appCodec
bApp := app.BaseApp
cdc := app.cdc
keys := app.keys
tkeys := app.tkeys
memKeys := app.memKeys

paramsKeeper := initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
app.ParamsKeeper = &paramsKeeper

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
app.CapabilityKeeper.Seal()

// TODO: Make a SetInvCheckPeriod fn on CrisisKeeper.
// IMO, its bad design atm that it requires this in state machine initialization
crisisKeeper := crisiskeeper.NewKeeper(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)
app.CrisisKeeper = &crisisKeeper

upgradeKeeper := upgradekeeper.NewKeeper(
skipUpgradeHeights,
keys[upgradetypes.StoreKey],
appCodec,
homePath,
bApp,
)
app.UpgradeKeeper = &upgradeKeeper
}

func (app *OsmosisApp) InitNormalKeepers() {
appCodec := app.appCodec
bApp := app.BaseApp
keys := app.keys

// Add 'normal' keepers
accountKeeper := authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
app.GetSubspace(authtypes.ModuleName),
authtypes.ProtoBaseAccount,
maccPerms,
)
app.AccountKeeper = &accountKeeper
bankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
app.GetSubspace(banktypes.ModuleName),
app.BlockedAddrs(),
)
app.BankKeeper = &bankKeeper

authzKeeper := authzkeeper.NewKeeper(
keys[authzkeeper.StoreKey],
appCodec,
bApp.MsgServiceRouter(),
)
app.AuthzKeeper = &authzKeeper

stakingKeeper := stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
)
app.StakingKeeper = &stakingKeeper

distrKeeper := distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey],
app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.BlockedAddrs(),
)
app.DistrKeeper = &distrKeeper

slashingKeeper := slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)
app.SlashingKeeper = &slashingKeeper

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
keys[ibchost.StoreKey],
app.GetSubspace(ibchost.ModuleName),
&stakingKeeper,
app.UpgradeKeeper,
app.ScopedIBCKeeper)

// Create Transfer Keepers
transferKeeper := ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper,
)
app.TransferKeeper = &transferKeeper
app.transferModule = transfer.NewAppModule(*app.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, app.transferModule)
app.IBCKeeper.SetRouter(ibcRouter)

app.Bech32IBCKeeper = bech32ibckeeper.NewKeeper(
app.IBCKeeper.ChannelKeeper, appCodec, keys[bech32ibctypes.StoreKey],
app.TransferKeeper,
)

// TODO: Should we be passing this instead of bank in many places?
// Where do we want send coins to be cross-chain?
app.Bech32ICS20Keeper = bech32ics20keeper.NewKeeper(
app.IBCKeeper.ChannelKeeper,
app.BankKeeper, app.TransferKeeper,
app.Bech32IBCKeeper,
app.TransferKeeper,
appCodec,
)

// create evidence keeper with router
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper,
)

app.ClaimKeeper = claimkeeper.NewKeeper(
appCodec,
keys[claimtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper, app.StakingKeeper, app.DistrKeeper)

gammKeeper := gammkeeper.NewKeeper(
appCodec, keys[gammtypes.StoreKey],
app.GetSubspace(gammtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper)
app.GAMMKeeper = &gammKeeper

app.LockupKeeper = lockupkeeper.NewKeeper(
appCodec, keys[lockuptypes.StoreKey],
// TODO: Visit why this needs to be deref'd
*app.AccountKeeper,
app.BankKeeper)
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

app.EpochsKeeper = epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey])

app.IncentivesKeeper = incentiveskeeper.NewKeeper(
appCodec, keys[incentivestypes.StoreKey],
app.GetSubspace(incentivestypes.ModuleName),
*app.AccountKeeper,
app.BankKeeper, app.LockupKeeper, app.EpochsKeeper)
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

mintKeeper := mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey],
app.GetSubspace(minttypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.EpochsKeeper,
authtypes.FeeCollectorName,
)
app.MintKeeper = &mintKeeper

poolIncentivesKeeper := poolincentiveskeeper.NewKeeper(
appCodec,
keys[poolincentivestypes.StoreKey],
app.GetSubspace(poolincentivestypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.IncentivesKeeper,
app.DistrKeeper,
distrtypes.ModuleName,
authtypes.FeeCollectorName,
)
app.PoolIncentivesKeeper = &poolIncentivesKeeper

txFeesKeeper := txfeeskeeper.NewKeeper(
appCodec,
keys[txfeestypes.StoreKey],
app.GAMMKeeper,
)
app.TxFeesKeeper = &txFeesKeeper

// register the proposal types
// TODO: This appears to be missing tx fees proposal type
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(*app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distribution.NewCommunityPoolSpendProposalHandler(*app.DistrKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(*app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(poolincentivestypes.RouterKey, poolincentives.NewPoolIncentivesProposalHandler(*app.PoolIncentivesKeeper)).
AddRoute(bech32ibctypes.RouterKey, bech32ibc.NewBech32IBCProposalHandler(*app.Bech32IBCKeeper))

govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, govRouter)
app.GovKeeper = &govKeeper
}

func (app *OsmosisApp) SetupHooks() {
// For every module that has hooks set on it,
// you must check InitNormalKeepers to ensure that its not passed by de-reference
// e.g. *app.StakingKeeper doesn't appear

// Recall that SetHooks is a mutative call.
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.ClaimKeeper.Hooks()),
)

app.GAMMKeeper.SetHooks(
gammtypes.NewMultiGammHooks(
// insert gamm hooks receivers here
app.PoolIncentivesKeeper.Hooks(),
app.ClaimKeeper.Hooks(),
),
)

app.LockupKeeper.SetHooks(
lockuptypes.NewMultiLockupHooks(
// insert lockup hooks receivers here
),
)

app.IncentivesKeeper.SetHooks(
incentivestypes.NewMultiIncentiveHooks(
// insert incentive hooks receivers here
),
)

app.MintKeeper.SetHooks(
minttypes.NewMultiMintHooks(
// insert mint hooks receivers here
app.PoolIncentivesKeeper.Hooks(),
),
)

app.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
// insert epoch hooks receivers here
app.IncentivesKeeper.Hooks(),
app.MintKeeper.Hooks(),
),
)

app.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// insert governance hooks receivers here
app.ClaimKeeper.Hooks(),
),
)
}
4 changes: 2 additions & 2 deletions app/upgrades/v4/prop12.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
)

func Prop12(ctx sdk.Context, bank *bankkeeper.Keeper, distr *distrkeeper.Keeper) {
func Prop12(ctx sdk.Context, bank bankkeeper.Keeper, distr *distrkeeper.Keeper) {
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
payments := GetProp12Payments()

var total = int64(0)
Expand All @@ -25,7 +25,7 @@ func Prop12(ctx sdk.Context, bank *bankkeeper.Keeper, distr *distrkeeper.Keeper)
panic(err)
}
coins := sdk.NewCoins(sdk.NewInt64Coin("uosmo", amount))
if err := (*bank).SendCoinsFromModuleToAccount(ctx, "distribution", addr, coins); err != nil {
if err := bank.SendCoinsFromModuleToAccount(ctx, "distribution", addr, coins); err != nil {
panic(err)
}
total += amount
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator,
bank *bankkeeper.Keeper,
bank bankkeeper.Keeper,
distr *distrkeeper.Keeper,
gamm *gammkeeper.Keeper) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/osmosis-labs/bech32-ibc v0.2.0-rc1
github.com/osmosis-labs/bech32-ibc v0.2.0-rc1.0.20211229033539-6398fe1c7f8c
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
Expand Down
Loading