Skip to content

Commit 9f6fca8

Browse files
chattoncharleenfeicrodriguezvega
authored
Change signature of NewKeeper to directly accept a ConsensusHost (#6084)
* chore: change signature of NewKeeper to directly accept a ConsensusHost * chore: updated PR number in CHANGELOG * chore: add panic on invalid staking keeper --------- Co-authored-by: Charly <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
1 parent bce50ea commit 9f6fca8

File tree

8 files changed

+25
-30
lines changed

8 files changed

+25
-30
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4343
* (core/02-client, light-clients) [\#5806](https://github.com/cosmos/ibc-go/pull/5806) Decouple light client routing from their encoding structure.
4444
* (core/04-channel) [\#5991](https://github.com/cosmos/ibc-go/pull/5991) The client CLI `QueryLatestConsensusState` has been removed.
4545
* (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`.
46+
* (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.
4647

4748
### State Machine Breaking
4849

modules/apps/callbacks/testing/simapp/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func NewSimApp(
407407
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
408408

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

413413
// NOTE: The mock ContractKeeper is only created for testing.

modules/core/02-client/keeper/keeper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Keeper struct {
3333
}
3434

3535
// NewKeeper creates a new NewKeeper instance
36-
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper {
36+
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, consensusHost types.ConsensusHost, uk types.UpgradeKeeper) Keeper {
3737
router := types.NewRouter(key)
3838
localhostModule := localhost.NewLightClientModule(cdc, key)
3939
router.AddRoute(exported.Localhost, localhostModule)
@@ -42,7 +42,7 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace ty
4242
storeKey: key,
4343
cdc: cdc,
4444
router: router,
45-
consensusHost: ibctm.NewConsensusHost(sk),
45+
consensusHost: consensusHost,
4646
legacySubspace: legacySubspace,
4747
upgradeKeeper: uk,
4848
}

modules/core/keeper/keeper.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ type Keeper struct {
4040
// NewKeeper creates a new ibc Keeper
4141
func NewKeeper(
4242
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace types.ParamSubspace,
43-
stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper,
43+
consensusHost clienttypes.ConsensusHost, upgradeKeeper clienttypes.UpgradeKeeper,
4444
scopedKeeper capabilitykeeper.ScopedKeeper, authority string,
4545
) *Keeper {
4646
// panic if any of the keepers passed in is empty
47-
if isEmpty(stakingKeeper) {
48-
panic(errors.New("cannot initialize IBC keeper: empty staking keeper"))
47+
if isEmpty(consensusHost) {
48+
panic(errors.New("cannot initialize IBC keeper: empty consensus host"))
4949
}
50+
5051
if isEmpty(upgradeKeeper) {
5152
panic(errors.New("cannot initialize IBC keeper: empty upgrade keeper"))
5253
}
@@ -59,7 +60,7 @@ func NewKeeper(
5960
panic(errors.New("authority must be non-empty"))
6061
}
6162

62-
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper)
63+
clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, consensusHost, upgradeKeeper)
6364
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, &clientKeeper)
6465
portKeeper := portkeeper.NewKeeper(scopedKeeper)
6566
channelKeeper := channelkeeper.NewKeeper(cdc, key, &clientKeeper, &connectionKeeper, &portKeeper, scopedKeeper)

modules/core/keeper/keeper_test.go

+10-21
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99

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

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

1514
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
1615
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
1716
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
1817
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
18+
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
1919
ibctesting "github.com/cosmos/ibc-go/v8/testing"
2020
)
2121

@@ -61,7 +61,7 @@ func (MockStakingKeeper) UnbondingTime(_ context.Context) (time.Duration, error)
6161
// It verifies if ibckeeper.NewKeeper panic when any of the keepers passed in is empty.
6262
func (suite *KeeperTestSuite) TestNewKeeper() {
6363
var (
64-
stakingKeeper clienttypes.StakingKeeper
64+
consensusHost clienttypes.ConsensusHost
6565
upgradeKeeper clienttypes.UpgradeKeeper
6666
scopedKeeper capabilitykeeper.ScopedKeeper
6767
newIBCKeeperFn func()
@@ -72,21 +72,11 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
7272
malleate func()
7373
expPass bool
7474
}{
75-
{"failure: empty staking keeper value", func() {
76-
emptyStakingKeeperValue := stakingkeeper.Keeper{}
77-
78-
stakingKeeper = emptyStakingKeeperValue
79-
}, false},
80-
{"failure: empty staking keeper pointer", func() {
81-
emptyStakingKeeperPointer := &stakingkeeper.Keeper{}
82-
83-
stakingKeeper = emptyStakingKeeperPointer
75+
{"failure: empty consensus host value", func() {
76+
consensusHost = &ibctm.ConsensusHost{}
8477
}, false},
85-
{"failure: empty mock staking keeper", func() {
86-
// use a different implementation of clienttypes.StakingKeeper
87-
emptyMockStakingKeeper := MockStakingKeeper{}
88-
89-
stakingKeeper = emptyMockStakingKeeper
78+
{"failure: nil consensus host value", func() {
79+
consensusHost = nil
9080
}, false},
9181
{"failure: empty upgrade keeper value", func() {
9282
emptyUpgradeKeeperValue := upgradekeeper.Keeper{}
@@ -109,7 +99,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
10999
suite.chainA.GetSimApp().AppCodec(),
110100
suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey),
111101
suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName),
112-
stakingKeeper,
102+
consensusHost,
113103
upgradeKeeper,
114104
scopedKeeper,
115105
"", // authority
@@ -119,8 +109,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
119109
{"success: replace stakingKeeper with non-empty MockStakingKeeper", func() {
120110
// use a different implementation of clienttypes.StakingKeeper
121111
mockStakingKeeper := MockStakingKeeper{"not empty"}
122-
123-
stakingKeeper = mockStakingKeeper
112+
consensusHost = ibctm.NewConsensusHost(mockStakingKeeper)
124113
}, true},
125114
}
126115

@@ -135,14 +124,14 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
135124
suite.chainA.GetSimApp().AppCodec(),
136125
suite.chainA.GetSimApp().GetKey(ibcexported.StoreKey),
137126
suite.chainA.GetSimApp().GetSubspace(ibcexported.ModuleName),
138-
stakingKeeper,
127+
consensusHost,
139128
upgradeKeeper,
140129
scopedKeeper,
141130
suite.chainA.App.GetIBCKeeper().GetAuthority(),
142131
)
143132
}
144133

145-
stakingKeeper = suite.chainA.GetSimApp().StakingKeeper
134+
consensusHost = ibctm.NewConsensusHost(suite.chainA.GetSimApp().StakingKeeper)
146135
upgradeKeeper = suite.chainA.GetSimApp().UpgradeKeeper
147136
scopedKeeper = suite.chainA.GetSimApp().ScopedIBCKeeper
148137

modules/light-clients/07-tendermint/consensus_host.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type StakingKeeper interface {
3434

3535
// NewConsensusHost creates and returns a new ConsensusHost for tendermint consensus.
3636
func NewConsensusHost(stakingKeeper clienttypes.StakingKeeper) clienttypes.ConsensusHost {
37+
if stakingKeeper == nil {
38+
panic("staking keeper cannot be nil")
39+
}
40+
3741
return &ConsensusHost{
3842
stakingKeeper: stakingKeeper,
3943
}

modules/light-clients/08-wasm/testing/simapp/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func NewSimApp(
416416
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
417417

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

422422
// Register the proposal types

testing/simapp/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func NewSimApp(
408408
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())
409409

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

0 commit comments

Comments
 (0)