From 580f27628a346c2b43a68f443bf6d1675f9be3c6 Mon Sep 17 00:00:00 2001 From: Christian Gorenflo Date: Fri, 3 Nov 2023 21:25:57 -0400 Subject: [PATCH 1/3] refactor: store keepers by reference --- app/app.go | 63 ++++--------------- app/keepers.go | 166 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 136 insertions(+), 93 deletions(-) diff --git a/app/app.go b/app/app.go index caca87e55..c4a928674 100644 --- a/app/app.go +++ b/app/app.go @@ -235,7 +235,7 @@ func NewAxelarApp( stakingK = *stakingK.SetHooks( stakingtypes.NewMultiStakingHooks(getKeeper[distrkeeper.Keeper](keepers).Hooks(), getKeeper[slashingkeeper.Keeper](keepers).Hooks()), ) - setKeeper(keepers, stakingK) + setKeeper(keepers, &stakingK) // add capability keeper and ScopeToModule for ibc module memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -247,14 +247,11 @@ func NewAxelarApp( scopedWasmK := capabilityK.ScopeToModule(wasm.ModuleName) capabilityK.Seal() - setKeeper(keepers, *capabilityK) + setKeeper(keepers, capabilityK) setKeeper(keepers, initIBCKeeper(appCodec, keys, keepers, scopedIBCK)) // Custom axelarnet/evm/nexus keepers - setKeeper(keepers, axelarnetKeeper.NewKeeper( - appCodec, keys[axelarnetTypes.StoreKey], keepers.getSubspace(axelarnetTypes.ModuleName), getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[feegrantkeeper.Keeper](keepers), - )) - - setKeeper(keepers, evmKeeper.NewKeeper(appCodec, keys[evmTypes.StoreKey], getKeeper[paramskeeper.Keeper](keepers))) + setKeeper(keepers, initAxelarnetKeeper(appCodec, keys, keepers)) + setKeeper(keepers, initEvmKeeper(appCodec, keys, keepers)) setKeeper(keepers, initNexusKeeper(appCodec, keys, keepers)) // IBC Transfer Stack: SendPacket @@ -265,7 +262,7 @@ func NewAxelarApp( // After this, the wasm keeper is required to be set on WasmHooks // Create IBC rate limiter - rateLimiter := axelarnet.NewRateLimiter(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[nexusKeeper.Keeper](keepers)) + rateLimiter := axelarnet.NewRateLimiter(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[nexusKeeper.Keeper](keepers)) var ibcHooksMiddleware ibchooks.ICS4Middleware var ics4Wrapper ibctransfertypes.ICS4Wrapper var wasmHooks ibchooks.WasmHooks @@ -287,13 +284,7 @@ func NewAxelarApp( } // Create Transfer Keepers - setKeeper(keepers, ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], keepers.getSubspace(ibctransfertypes.ModuleName), - // Use the IBC middleware stack - ics4Wrapper, - getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper, &getKeeper[*ibckeeper.Keeper](keepers).PortKeeper, - getKeeper[authkeeper.AccountKeeper](keepers), getKeeper[bankkeeper.BaseKeeper](keepers), scopedTransferK, - )) + setKeeper(keepers, initIBCTransferKeeper(appCodec, keys, keepers, ics4Wrapper, scopedTransferK)) // IBC Transfer Stack: RecvPacket // @@ -304,7 +295,7 @@ func NewAxelarApp( transferStack = ibchooks.NewIBCMiddleware(transferStack, &ibcHooksMiddleware) } - setKeeper(keepers, axelarnetKeeper.NewIBCKeeper(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[ibctransferkeeper.Keeper](keepers), getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper)) + setKeeper(keepers, initAxelarIBCKeeper(keepers)) axelarnetModule := axelarnet.NewAppModule(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), axelarbankkeeper.NewBankKeeper(getKeeper[bankkeeper.BaseKeeper](keepers)), getKeeper[authkeeper.AccountKeeper](keepers), getKeeper[axelarnetKeeper.IBCKeeper](keepers), transferStack, rateLimiter, logger) @@ -355,7 +346,7 @@ func NewAxelarApp( ) // Create wasm ibc stack - var wasmStack porttypes.IBCModule = wasm.NewIBCHandler(wasmK, getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[*ibckeeper.Keeper](keepers).ChannelKeeper) + var wasmStack porttypes.IBCModule = wasm.NewIBCHandler(wasmK, getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper) ibcRouter.AddRoute(wasm.ModuleName, wasmStack) // set the contract keeper for the Ics20WasmHooks @@ -364,7 +355,7 @@ func NewAxelarApp( } // Finalize the IBC router - getKeeper[*ibckeeper.Keeper](keepers).SetRouter(ibcRouter) + getKeeperAsRef[ibckeeper.Keeper](keepers).SetRouter(ibcRouter) setKeeper(keepers, initGovernanceKeeper(appCodec, keys, keepers)) @@ -430,7 +421,7 @@ func NewAxelarApp( // we need to ensure that all chain subspaces are loaded at start-up to prevent unexpected consensus failures // when the params keeper is used outside the evm module's context - getKeeper[*evmKeeper.BaseKeeper](keepers).InitChains(app.NewContext(true, tmproto.Header{})) + getKeeperAsRef[evmKeeper.BaseKeeper](keepers).InitChains(app.NewContext(true, tmproto.Header{})) return app } @@ -481,7 +472,7 @@ func initAppModules(keepers *keeperCache, bApp *bam.BaseApp, encodingConfig axel appModules = append(appModules, evidence.NewAppModule(getKeeper[evidencekeeper.Keeper](keepers)), - ibc.NewAppModule(getKeeper[*ibckeeper.Keeper](keepers)), + ibc.NewAppModule(getKeeperAsRef[ibckeeper.Keeper](keepers)), transfer.NewAppModule(getKeeper[ibctransferkeeper.Keeper](keepers)), feegrantmodule.NewAppModule(appCodec, getKeeper[authkeeper.AccountKeeper](keepers), getKeeper[bankkeeper.BaseKeeper](keepers), getKeeper[feegrantkeeper.Keeper](keepers), encodingConfig.InterfaceRegistry), @@ -490,7 +481,7 @@ func initAppModules(keepers *keeperCache, bApp *bam.BaseApp, encodingConfig axel tss.NewAppModule(getKeeper[tssKeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[multisigKeeper.Keeper](keepers)), vote.NewAppModule(getKeeper[voteKeeper.Keeper](keepers)), nexus.NewAppModule(getKeeper[nexusKeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[slashingkeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[rewardKeeper.Keeper](keepers)), - evm.NewAppModule(getKeeper[*evmKeeper.BaseKeeper](keepers), getKeeper[voteKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[slashingkeeper.Keeper](keepers), getKeeper[multisigKeeper.Keeper](keepers)), + evm.NewAppModule(getKeeperAsRef[evmKeeper.BaseKeeper](keepers), getKeeper[voteKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[slashingkeeper.Keeper](keepers), getKeeper[multisigKeeper.Keeper](keepers)), axelarnetModule, reward.NewAppModule(getKeeper[rewardKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[mintkeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[slashingkeeper.Keeper](keepers), getKeeper[multisigKeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[bankkeeper.BaseKeeper](keepers), bApp.MsgServiceRouter(), bApp.Router()), permission.NewAppModule(getKeeper[permissionKeeper.Keeper](keepers)), @@ -542,7 +533,7 @@ func initAnteHandlers(encodingConfig axelarParams.EncodingConfig, keys map[strin ante.NewCheckRefundFeeDecorator(encodingConfig.InterfaceRegistry, getKeeper[authkeeper.AccountKeeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), getKeeper[snapKeeper.Keeper](keepers), getKeeper[rewardKeeper.Keeper](keepers)), ante.NewCheckProxy(getKeeper[snapKeeper.Keeper](keepers)), ante.NewRestrictedTx(getKeeper[permissionKeeper.Keeper](keepers)), - ibcante.NewAnteDecorator(getKeeper[*ibckeeper.Keeper](keepers)), + ibcante.NewAnteDecorator(getKeeperAsRef[ibckeeper.Keeper](keepers)), ) anteHandler := sdk.ChainAnteDecorators( @@ -768,34 +759,6 @@ func createStoreKeys() map[string]*sdk.KVStoreKey { permissionTypes.StoreKey) } -func initParamsKeeper(encodingConfig axelarParams.EncodingConfig, key, tkey sdk.StoreKey) paramskeeper.Keeper { - paramsKeeper := paramskeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, key, tkey) - - paramsKeeper.Subspace(bam.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()) - - paramsKeeper.Subspace(authtypes.ModuleName) - paramsKeeper.Subspace(banktypes.ModuleName) - paramsKeeper.Subspace(stakingtypes.ModuleName) - paramsKeeper.Subspace(minttypes.ModuleName) - paramsKeeper.Subspace(distrtypes.ModuleName) - paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) - paramsKeeper.Subspace(crisistypes.ModuleName) - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibchost.ModuleName) - paramsKeeper.Subspace(wasm.ModuleName) - paramsKeeper.Subspace(snapTypes.ModuleName) - paramsKeeper.Subspace(multisigTypes.ModuleName) - paramsKeeper.Subspace(tssTypes.ModuleName) - paramsKeeper.Subspace(nexusTypes.ModuleName) - paramsKeeper.Subspace(axelarnetTypes.ModuleName) - paramsKeeper.Subspace(rewardTypes.ModuleName) - paramsKeeper.Subspace(voteTypes.ModuleName) - paramsKeeper.Subspace(permissionTypes.ModuleName) - - return paramsKeeper -} - // GenesisState represents chain state at the start of the chain. Any initial state (account balances) are stored here. type GenesisState map[string]json.RawMessage diff --git a/app/keepers.go b/app/keepers.go index f093d2ce3..180ca55e0 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -2,6 +2,12 @@ package app import ( "fmt" + axelarParams "github.com/axelarnetwork/axelar-core/app/params" + store "github.com/cosmos/cosmos-sdk/store/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" "reflect" "strings" @@ -89,8 +95,15 @@ func (k *keeperCache) getSubspace(moduleName string) paramstypes.Subspace { } func getKeeper[T any](k *keeperCache) T { + return *getKeeperAsRef[T](k) +} + +func getKeeperAsRef[T any](k *keeperCache) *T { + if reflect.TypeOf(*new(T)).Kind() == reflect.Ptr { + panic(fmt.Sprintf("the generic parameter for %s cannot be a reference type", fullTypeName[T]())) + } key := fullTypeName[T]() - keeper, ok := k.repository[key].(T) + keeper, ok := k.repository[key].(*T) if !ok { panic(fmt.Sprintf("keeper %s not found", key)) } @@ -98,29 +111,59 @@ func getKeeper[T any](k *keeperCache) T { } func setKeeper[T any](k *keeperCache, keeper T) { + if reflect.TypeOf(keeper).Kind() != reflect.Ptr { + panic(fmt.Sprintf("keeper %s must be a reference type", fullTypeName[T]())) + } + k.repository[fullTypeName[T]()] = keeper } func fullTypeName[T any]() string { keeperType := reflect.TypeOf(*new(T)) - var prefix string if keeperType.Kind() == reflect.Ptr { - prefix = "*" keeperType = keeperType.Elem() } - return prefix + keeperType.PkgPath() + "." + keeperType.Name() + return keeperType.PkgPath() + "." + keeperType.Name() } -func initGovernanceKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) govkeeper.Keeper { +func initParamsKeeper(encodingConfig axelarParams.EncodingConfig, key, tkey sdk.StoreKey) *paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(encodingConfig.Codec, encodingConfig.Amino, key, tkey) + + paramsKeeper.Subspace(bam.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(wasm.ModuleName) + paramsKeeper.Subspace(snapTypes.ModuleName) + paramsKeeper.Subspace(multisigTypes.ModuleName) + paramsKeeper.Subspace(tssTypes.ModuleName) + paramsKeeper.Subspace(nexusTypes.ModuleName) + paramsKeeper.Subspace(axelarnetTypes.ModuleName) + paramsKeeper.Subspace(rewardTypes.ModuleName) + paramsKeeper.Subspace(voteTypes.ModuleName) + paramsKeeper.Subspace(permissionTypes.ModuleName) + + return ¶msKeeper +} + +func initGovernanceKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *govkeeper.Keeper { // Add governance proposal hooks govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(getKeeper[paramskeeper.Keeper](keepers))). AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(getKeeper[distrkeeper.Keeper](keepers))). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(getKeeper[upgradekeeper.Keeper](keepers))). - AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(getKeeper[*ibckeeper.Keeper](keepers).ClientKeeper)). + AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(getKeeperAsRef[ibckeeper.Keeper](keepers).ClientKeeper)). AddRoute(axelarnetTypes.RouterKey, axelarnet.NewProposalHandler(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[authkeeper.AccountKeeper](keepers))) if IsWasmEnabled() { @@ -134,20 +177,21 @@ func initGovernanceKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, axelarnetK := getKeeper[axelarnetKeeper.Keeper](keepers) govK.SetHooks(govtypes.NewMultiGovHooks(axelarnetK.Hooks(getKeeper[nexusKeeper.Keeper](keepers), govK))) - return govK + return &govK } -func initPermissionKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) permissionKeeper.Keeper { - return permissionKeeper.NewKeeper(appCodec, keys[permissionTypes.StoreKey], keepers.getSubspace(permissionTypes.ModuleName)) +func initPermissionKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *permissionKeeper.Keeper { + permissionK := permissionKeeper.NewKeeper(appCodec, keys[permissionTypes.StoreKey], keepers.getSubspace(permissionTypes.ModuleName)) + return &permissionK } -func initVoteKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) voteKeeper.Keeper { +func initVoteKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *voteKeeper.Keeper { voteRouter := voteTypes.NewRouter() voteRouter.AddHandler( evmTypes.ModuleName, evmKeeper.NewVoteHandler( appCodec, - getKeeper[*evmKeeper.BaseKeeper](keepers), + getKeeperAsRef[evmKeeper.BaseKeeper](keepers), getKeeper[nexusKeeper.Keeper](keepers), getKeeper[rewardKeeper.Keeper](keepers), ), @@ -162,11 +206,11 @@ func initVoteKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepe getKeeper[rewardKeeper.Keeper](keepers), ) voteK.SetVoteRouter(voteRouter) - return voteK + return &voteK } -func initSnapshotKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) snapKeeper.Keeper { - return snapKeeper.NewKeeper( +func initSnapshotKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *snapKeeper.Keeper { + snapK := snapKeeper.NewKeeper( appCodec, keys[snapTypes.StoreKey], keepers.getSubspace(snapTypes.ModuleName), @@ -174,23 +218,25 @@ func initSnapshotKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, k axelarbankkeeper.NewBankKeeper(getKeeper[bankkeeper.BaseKeeper](keepers)), getKeeper[slashingkeeper.Keeper](keepers), ) + return &snapK } -func initTssKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) tssKeeper.Keeper { - return tssKeeper.NewKeeper(appCodec, keys[tssTypes.StoreKey], keepers.getSubspace(tssTypes.ModuleName)) +func initTssKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *tssKeeper.Keeper { + tssK := tssKeeper.NewKeeper(appCodec, keys[tssTypes.StoreKey], keepers.getSubspace(tssTypes.ModuleName)) + return &tssK } -func initMultisigKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) multisigKeeper.Keeper { +func initMultisigKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *multisigKeeper.Keeper { multisigRouter := multisigTypes.NewSigRouter() - multisigRouter.AddHandler(evmTypes.ModuleName, evmKeeper.NewSigHandler(appCodec, getKeeper[*evmKeeper.BaseKeeper](keepers))) + multisigRouter.AddHandler(evmTypes.ModuleName, evmKeeper.NewSigHandler(appCodec, getKeeperAsRef[evmKeeper.BaseKeeper](keepers))) multisigK := multisigKeeper.NewKeeper(appCodec, keys[multisigTypes.StoreKey], keepers.getSubspace(multisigTypes.ModuleName)) multisigK.SetSigRouter(multisigRouter) - return multisigK + return &multisigK } -func initRewardKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) rewardKeeper.Keeper { - return rewardKeeper.NewKeeper( +func initRewardKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *rewardKeeper.Keeper { + rewardK := rewardKeeper.NewKeeper( appCodec, keys[rewardTypes.StoreKey], keepers.getSubspace(rewardTypes.ModuleName), @@ -198,6 +244,7 @@ func initRewardKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, kee getKeeper[distrkeeper.Keeper](keepers), getKeeper[stakingkeeper.Keeper](keepers), ) + return &rewardK } func initIBCKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, scopedIBCK capabilitykeeper.ScopedKeeper) *ibckeeper.Keeper { @@ -211,7 +258,34 @@ func initIBCKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keeper ) } -func initNexusKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) nexusKeeper.Keeper { +func initIBCTransferKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, ics4Wrapper ibctransfertypes.ICS4Wrapper, scopedTransferK capabilitykeeper.ScopedKeeper) *ibctransferkeeper.Keeper { + transferK := ibctransferkeeper.NewKeeper( + appCodec, keys[ibctransfertypes.StoreKey], getSubspace(keepers, ibctransfertypes.ModuleName), + // Use the IBC middleware stack + ics4Wrapper, + getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, &getKeeperAsRef[ibckeeper.Keeper](keepers).PortKeeper, + getKeeper[authkeeper.AccountKeeper](keepers), getKeeper[bankkeeper.BaseKeeper](keepers), scopedTransferK, + ) + return &transferK +} + +func initAxelarIBCKeeper(keepers *keeperCache) *axelarnetKeeper.IBCKeeper { + ibcK := axelarnetKeeper.NewIBCKeeper(getKeeper[axelarnetKeeper.Keeper](keepers), getKeeper[ibctransferkeeper.Keeper](keepers), getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper) + return &ibcK +} + +func initAxelarnetKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *axelarnetKeeper.Keeper { + axelarnetK := axelarnetKeeper.NewKeeper( + appCodec, keys[axelarnetTypes.StoreKey], getSubspace(keepers, axelarnetTypes.ModuleName), getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[feegrantkeeper.Keeper](keepers), + ) + return &axelarnetK +} + +func initEvmKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *evmKeeper.BaseKeeper { + return evmKeeper.NewKeeper(appCodec, keys[evmTypes.StoreKey], getKeeper[paramskeeper.Keeper](keepers)) +} + +func initNexusKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *nexusKeeper.Keeper { // Setting Router will finalize all routes by sealing router // No more routes can be added nexusRouter := nexusTypes.NewRouter() @@ -221,21 +295,20 @@ func initNexusKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keep nexusK := nexusKeeper.NewKeeper(appCodec, keys[nexusTypes.StoreKey], keepers.getSubspace(nexusTypes.ModuleName)) nexusK.SetRouter(nexusRouter) - return nexusK + return &nexusK } -func initFeegrantKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) feegrantkeeper.Keeper { - return feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], getKeeper[authkeeper.AccountKeeper](keepers)) +func initFeegrantKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *feegrantkeeper.Keeper { + feegrantK := feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], getKeeper[authkeeper.AccountKeeper](keepers)) + return &feegrantK } -func initEvidenceKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) evidencekeeper.Keeper { - // there is no point in this constructor returning a reference, so we deref it - evidenceK := evidencekeeper.NewKeeper(appCodec, keys[evidencetypes.StoreKey], stakingK, getKeeper[slashingkeeper.Keeper](keepers)) - return *evidenceK +func initEvidenceKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) *evidencekeeper.Keeper { + return evidencekeeper.NewKeeper(appCodec, keys[evidencetypes.StoreKey], stakingK, getKeeper[slashingkeeper.Keeper](keepers)) } // todo: clean this up -func initUpgradeKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, skipUpgradeHeights map[int64]bool, homePath string, bApp *bam.BaseApp, configurator *module.Configurator, mm *module.Manager) upgradekeeper.Keeper { +func initUpgradeKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, skipUpgradeHeights map[int64]bool, homePath string, bApp *bam.BaseApp, configurator *module.Configurator, mm *module.Manager) *upgradekeeper.Keeper { upgradeK := upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, bApp) upgradeK.SetUpgradeHandler( upgradeName(bApp.Version()), @@ -261,7 +334,7 @@ func initUpgradeKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, sk bApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } - return upgradeK + return &upgradeK } func upgradeName(version string) string { @@ -275,21 +348,23 @@ func upgradeName(version string) string { return name } -func initCrisisKeeper(keepers *keeperCache, invCheckPeriod uint) crisiskeeper.Keeper { - return crisiskeeper.NewKeeper( +func initCrisisKeeper(keepers *keeperCache, invCheckPeriod uint) *crisiskeeper.Keeper { + crisisK := crisiskeeper.NewKeeper( keepers.getSubspace(crisistypes.ModuleName), invCheckPeriod, getKeeper[bankkeeper.BaseKeeper](keepers), authtypes.FeeCollectorName, ) + return &crisisK } -func initSlashingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) slashingkeeper.Keeper { - return slashingkeeper.NewKeeper(appCodec, keys[slashingtypes.StoreKey], stakingK, keepers.getSubspace(slashingtypes.ModuleName)) +func initSlashingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) *slashingkeeper.Keeper { + slashK := slashingkeeper.NewKeeper(appCodec, keys[slashingtypes.StoreKey], stakingK, keepers.getSubspace(slashingtypes.ModuleName)) + return &slashK } -func initDistributionKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper, moduleAccPerms map[string][]string) distrkeeper.Keeper { - return distrkeeper.NewKeeper( +func initDistributionKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper, moduleAccPerms map[string][]string) *distrkeeper.Keeper { + distrK := distrkeeper.NewKeeper( appCodec, keys[distrtypes.StoreKey], keepers.getSubspace(distrtypes.ModuleName), @@ -299,10 +374,11 @@ func initDistributionKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKe authtypes.FeeCollectorName, moduleAccountAddrs(moduleAccPerms), ) + return &distrK } -func initMintKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) mintkeeper.Keeper { - return mintkeeper.NewKeeper( +func initMintKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, stakingK *stakingkeeper.Keeper) *mintkeeper.Keeper { + mintK := mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], keepers.getSubspace(minttypes.ModuleName), @@ -311,10 +387,11 @@ func initMintKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepe getKeeper[bankkeeper.BaseKeeper](keepers), authtypes.FeeCollectorName, ) + return &mintK } -func initBankKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, moduleAccPerms map[string][]string) bankkeeper.BaseKeeper { - return bankkeeper.NewBaseKeeper( +func initBankKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, moduleAccPerms map[string][]string) *bankkeeper.BaseKeeper { + bankK := bankkeeper.NewBaseKeeper( appCodec, keys[banktypes.StoreKey], getKeeper[authkeeper.AccountKeeper](keepers), @@ -327,16 +404,19 @@ func initBankKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepe return addr != authtypes.NewModuleAddress(axelarnetTypes.ModuleName).String() }), ) + return &bankK } -func initAccountKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, moduleAccPerms map[string][]string) authkeeper.AccountKeeper { - return authkeeper.NewAccountKeeper( +func initAccountKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, moduleAccPerms map[string][]string) *authkeeper.AccountKeeper { + authK := authkeeper.NewAccountKeeper( appCodec, keys[authtypes.StoreKey], keepers.getSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, moduleAccPerms, ) + + return &authK } // moduleAccountAddrs returns all the app's module account addresses. From e6de8f115da0a895212642c278e41862d6daf608 Mon Sep 17 00:00:00 2001 From: Christian Gorenflo Date: Fri, 3 Nov 2023 22:09:52 -0400 Subject: [PATCH 2/3] lint --- app/keepers.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/keepers.go b/app/keepers.go index 180ca55e0..f00d804eb 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -2,12 +2,6 @@ package app import ( "fmt" - axelarParams "github.com/axelarnetwork/axelar-core/app/params" - store "github.com/cosmos/cosmos-sdk/store/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" - ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" - ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" "reflect" "strings" @@ -42,9 +36,12 @@ import ( 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" + ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" ibcclient "github.com/cosmos/ibc-go/v4/modules/core/02-client" ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" @@ -52,6 +49,7 @@ import ( ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" "golang.org/x/mod/semver" + axelarParams "github.com/axelarnetwork/axelar-core/app/params" "github.com/axelarnetwork/axelar-core/x/axelarnet" axelarnetKeeper "github.com/axelarnetwork/axelar-core/x/axelarnet/keeper" axelarnetTypes "github.com/axelarnetwork/axelar-core/x/axelarnet/types" From 7e67de1c15419658f890ef8f86c9b26fda0ba37e Mon Sep 17 00:00:00 2001 From: Christian Gorenflo Date: Mon, 6 Nov 2023 18:08:51 -0500 Subject: [PATCH 3/3] fix merge --- app/keepers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/keepers.go b/app/keepers.go index f00d804eb..a4fd0927f 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -258,7 +258,7 @@ func initIBCKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keeper func initIBCTransferKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache, ics4Wrapper ibctransfertypes.ICS4Wrapper, scopedTransferK capabilitykeeper.ScopedKeeper) *ibctransferkeeper.Keeper { transferK := ibctransferkeeper.NewKeeper( - appCodec, keys[ibctransfertypes.StoreKey], getSubspace(keepers, ibctransfertypes.ModuleName), + appCodec, keys[ibctransfertypes.StoreKey], keepers.getSubspace(ibctransfertypes.ModuleName), // Use the IBC middleware stack ics4Wrapper, getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, &getKeeperAsRef[ibckeeper.Keeper](keepers).PortKeeper, @@ -274,7 +274,7 @@ func initAxelarIBCKeeper(keepers *keeperCache) *axelarnetKeeper.IBCKeeper { func initAxelarnetKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepers *keeperCache) *axelarnetKeeper.Keeper { axelarnetK := axelarnetKeeper.NewKeeper( - appCodec, keys[axelarnetTypes.StoreKey], getSubspace(keepers, axelarnetTypes.ModuleName), getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[feegrantkeeper.Keeper](keepers), + appCodec, keys[axelarnetTypes.StoreKey], keepers.getSubspace(axelarnetTypes.ModuleName), getKeeperAsRef[ibckeeper.Keeper](keepers).ChannelKeeper, getKeeper[feegrantkeeper.Keeper](keepers), ) return &axelarnetK }