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

Change signature of NewKeeper to directly accept a ConsensusHost #6084

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (core/02-client, light-clients) [\#5806](https://github.com/cosmos/ibc-go/pull/5806) Decouple light client routing from their encoding structure.
* (core/04-channel) [\#5991](https://github.com/cosmos/ibc-go/pull/5991) The client CLI `QueryLatestConsensusState` has been removed.
* (light-clients/06-solomachine) [\#6037](https://github.com/cosmos/ibc-go/pull/6037) Remove `Initialize` function from `ClientState` and move logic to `Initialize` function of `LightClientModule`.
* (core/02-client) [\#6084](https://github.com/cosmos/ibc-go/pull/6084) Removed `stakingKeeper` as an argument to `NewKeeper` and replaced with a `ConsensusHost` implementation.

### State Machine Breaking

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the NewConsensusHost function properly handles the StakingKeeper argument and any potential errors.

- ibctm.NewConsensusHost(app.StakingKeeper)
+ consensusHost, err := ibctm.NewConsensusHost(app.StakingKeeper)
+ if err != nil {
+     panic(fmt.Errorf("failed to create NewConsensusHost: %w", err))
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), consensusHost, err := ibctm.NewConsensusHost(app.StakingKeeper)
if err != nil {
panic(fmt.Errorf("failed to create NewConsensusHost: %w", err))
}, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),

)

// NOTE: The mock ContractKeeper is only created for testing.
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Keeper struct {
}

// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper {
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, consensusHost types.ConsensusHost, uk types.UpgradeKeeper) Keeper {
router := types.NewRouter(key)
localhostModule := localhost.NewLightClientModule(cdc, key)
router.AddRoute(exported.Localhost, localhostModule)
Expand All @@ -42,7 +42,7 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace ty
storeKey: key,
cdc: cdc,
router: router,
consensusHost: ibctm.NewConsensusHost(sk),
consensusHost: consensusHost,
legacySubspace: legacySubspace,
upgradeKeeper: uk,
}
Expand Down
9 changes: 5 additions & 4 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ type Keeper struct {
// NewKeeper creates a new ibc Keeper
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace,
stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper,
consensusHost clienttypes.ConsensusHost, upgradeKeeper clienttypes.UpgradeKeeper,
scopedKeeper capabilitykeeper.ScopedKeeper, authority string,
) *Keeper {
// panic if any of the keepers passed in is empty
if isEmpty(stakingKeeper) {
panic(errors.New("cannot initialize IBC keeper: empty staking keeper"))
if isEmpty(consensusHost) {
panic(errors.New("cannot initialize IBC keeper: empty consensus host"))
}

if isEmpty(upgradeKeeper) {
panic(errors.New("cannot initialize IBC keeper: empty upgrade keeper"))
}
Expand All @@ -59,7 +60,7 @@ func NewKeeper(
panic(errors.New("authority must be non-empty"))
}

clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper)
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, consensusHost, upgradeKeeper)
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, &clientKeeper)
portKeeper := portkeeper.NewKeeper(scopedKeeper)
channelKeeper := channelkeeper.NewKeeper(cdc, key, &clientKeeper, &connectionKeeper, &portKeeper, scopedKeeper)
Expand Down
31 changes: 10 additions & 21 deletions modules/core/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

upgradekeeper "cosmossdk.io/x/upgrade/keeper"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

Expand Down Expand Up @@ -61,7 +61,7 @@ func (MockStakingKeeper) UnbondingTime(_ context.Context) (time.Duration, error)
// It verifies if ibckeeper.NewKeeper panic when any of the keepers passed in is empty.
func (suite *KeeperTestSuite) TestNewKeeper() {
var (
stakingKeeper clienttypes.StakingKeeper
consensusHost clienttypes.ConsensusHost
upgradeKeeper clienttypes.UpgradeKeeper
scopedKeeper capabilitykeeper.ScopedKeeper
newIBCKeeperFn func()
Expand All @@ -72,21 +72,11 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
malleate func()
expPass bool
}{
{"failure: empty staking keeper value", func() {
emptyStakingKeeperValue := stakingkeeper.Keeper{}

stakingKeeper = emptyStakingKeeperValue
}, false},
{"failure: empty staking keeper pointer", func() {
emptyStakingKeeperPointer := &stakingkeeper.Keeper{}

stakingKeeper = emptyStakingKeeperPointer
{"failure: empty consensus host value", func() {
consensusHost = &ibctm.ConsensusHost{}
}, false},
{"failure: empty mock staking keeper", func() {
// use a different implementation of clienttypes.StakingKeeper
emptyMockStakingKeeper := MockStakingKeeper{}

stakingKeeper = emptyMockStakingKeeper
{"failure: nil consensus host value", func() {
consensusHost = nil
}, false},
{"failure: empty upgrade keeper value", func() {
emptyUpgradeKeeperValue := upgradekeeper.Keeper{}
Expand All @@ -109,7 +99,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey),
suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName),
stakingKeeper,
consensusHost,
upgradeKeeper,
scopedKeeper,
"", // authority
Expand All @@ -119,8 +109,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"success: replace stakingKeeper with non-empty MockStakingKeeper", func() {
// use a different implementation of clienttypes.StakingKeeper
mockStakingKeeper := MockStakingKeeper{"not empty"}

stakingKeeper = mockStakingKeeper
consensusHost = ibctm.NewConsensusHost(mockStakingKeeper)
}, true},
}

Expand All @@ -135,14 +124,14 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
suite.chainA.GetSimApp().AppCodec(),
suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey),
suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName),
stakingKeeper,
consensusHost,
upgradeKeeper,
scopedKeeper,
suite.chainA.App.GetIBCKeeper().GetAuthority(),
)
}

stakingKeeper = suite.chainA.GetSimApp().StakingKeeper
consensusHost = ibctm.NewConsensusHost(suite.chainA.GetSimApp().StakingKeeper)
upgradeKeeper = suite.chainA.GetSimApp().UpgradeKeeper
scopedKeeper = suite.chainA.GetSimApp().ScopedIBCKeeper

Expand Down
4 changes: 4 additions & 0 deletions modules/light-clients/07-tendermint/consensus_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type StakingKeeper interface {

// NewConsensusHost creates and returns a new ConsensusHost for tendermint consensus.
func NewConsensusHost(stakingKeeper clienttypes.StakingKeeper) clienttypes.ConsensusHost {
if stakingKeeper == nil {
panic("staking keeper cannot be nil")
}

return &ConsensusHost{
stakingKeeper: stakingKeeper,
}
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Register the proposal types
Expand Down
2 changes: 1 addition & 1 deletion testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
Expand Down
Loading