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

add empty keepers checking in ibc NewKeeper #1284

Merged
merged 14 commits into from
Apr 29, 2022
Merged
Changes from 2 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
24 changes: 24 additions & 0 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package keeper

import (
"fmt"
"reflect"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
catShaark marked this conversation as resolved.
Show resolved Hide resolved
clientkeeper "github.com/cosmos/ibc-go/v3/modules/core/02-client/keeper"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
connectionkeeper "github.com/cosmos/ibc-go/v3/modules/core/03-connection/keeper"
Expand Down Expand Up @@ -46,6 +51,11 @@ func NewKeeper(
paramSpace = paramSpace.WithKeyTable(keyTable)
}

err := checkEmptyKeepers(stakingKeeper, upgradeKeeper, scopedKeeper)
if err != nil {
panic(fmt.Errorf("cannot initialize ibc keeper: %w", err))
}

catShaark marked this conversation as resolved.
Show resolved Hide resolved
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper)
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper)
portKeeper := portkeeper.NewKeeper(scopedKeeper)
Expand Down Expand Up @@ -76,3 +86,17 @@ func (k *Keeper) SetRouter(rtr *porttypes.Router) {
k.Router = rtr
k.Router.Seal()
}

func checkEmptyKeepers(stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper,
catShaark marked this conversation as resolved.
Show resolved Hide resolved
scopedKeeper capabilitykeeper.ScopedKeeper) error {
if reflect.DeepEqual(stakingkeeper.Keeper{}, stakingKeeper.(stakingkeeper.Keeper)) {
return fmt.Errorf("empty staking keeper")
}
if reflect.DeepEqual(upgradekeeper.Keeper{}, upgradeKeeper.(upgradekeeper.Keeper)) {
return fmt.Errorf("empty upgradeKeeper")
}
if reflect.DeepEqual(capabilitykeeper.ScopedKeeper{}, scopedKeeper) {
return fmt.Errorf("empty scopedKeeper")
}
return nil
}