Skip to content

Commit d89cb08

Browse files
authored
refactor: standardise sub keeper usage in core ibc (#6081)
1 parent c15cf6f commit d89cb08

34 files changed

+338
-341
lines changed

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,12 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
354354
// test if the ics4 wrapper is the channel keeper initially
355355
ics4Wrapper := suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()
356356

357-
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
357+
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
358358
suite.Require().False(isChannelKeeper)
359359

360360
// set the ics4 wrapper to the channel keeper
361361
suite.chainA.GetSimApp().ICAControllerKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
362362
ics4Wrapper = suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()
363363

364-
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
365-
suite.Require().True(isChannelKeeper)
364+
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
366365
}

modules/apps/27-interchain-accounts/host/keeper/keeper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,15 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
411411

412412
_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
413413
suite.Require().True(isFeeKeeper)
414-
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
414+
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
415415
suite.Require().False(isChannelKeeper)
416416

417417
// set the ics4 wrapper to the channel keeper
418418
suite.chainA.GetSimApp().ICAHostKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
419419
ics4Wrapper = suite.chainA.GetSimApp().ICAHostKeeper.GetICS4Wrapper()
420420

421-
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
422-
suite.Require().True(isChannelKeeper)
421+
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
422+
423423
_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
424424
suite.Require().False(isFeeKeeper)
425425
}

modules/apps/29-fee/keeper/keeper_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
296296
// test if the ics4 wrapper is the channel keeper initially
297297
ics4Wrapper := suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()
298298

299-
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
300-
suite.Require().True(isChannelKeeper)
299+
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
301300
_, isFeeKeeper := ics4Wrapper.(keeper.Keeper)
302301
suite.Require().False(isFeeKeeper)
303302

@@ -307,6 +306,6 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
307306

308307
_, isFeeKeeper = ics4Wrapper.(keeper.Keeper)
309308
suite.Require().True(isFeeKeeper)
310-
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
309+
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
311310
suite.Require().False(isChannelKeeper)
312311
}

modules/apps/callbacks/ibc_middleware_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
3333
{
3434
"success",
3535
func() {
36-
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
36+
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
3737
},
3838
nil,
3939
},
4040
{
4141
"panics with nil underlying app",
4242
func() {
43-
_ = ibccallbacks.NewIBCMiddleware(nil, channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
43+
_ = ibccallbacks.NewIBCMiddleware(nil, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
4444
},
4545
fmt.Errorf("underlying application does not implement %T", (*types.CallbacksCompatibleModule)(nil)),
4646
},
4747
{
4848
"panics with nil contract keeper",
4949
func() {
50-
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, nil, maxCallbackGas)
50+
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, nil, maxCallbackGas)
5151
},
5252
fmt.Errorf("contract keeper cannot be nil"),
5353
},
@@ -61,7 +61,7 @@ func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
6161
{
6262
"panics with zero maxCallbackGas",
6363
func() {
64-
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, simapp.ContractKeeper{}, uint64(0))
64+
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, uint64(0))
6565
},
6666
fmt.Errorf("maxCallbackGas cannot be zero"),
6767
},
@@ -89,7 +89,7 @@ func (s *CallbacksTestSuite) TestWithICS4Wrapper() {
8989
cbsMiddleware.WithICS4Wrapper(s.chainA.App.GetIBCKeeper().ChannelKeeper)
9090
ics4Wrapper := cbsMiddleware.GetICS4Wrapper()
9191

92-
s.Require().IsType(channelkeeper.Keeper{}, ics4Wrapper)
92+
s.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
9393
}
9494

9595
func (s *CallbacksTestSuite) TestSendPacket() {

modules/apps/transfer/keeper/keeper_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,12 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
341341
// test if the ics4 wrapper is the channel keeper initially
342342
ics4Wrapper := suite.chainA.GetSimApp().TransferKeeper.GetICS4Wrapper()
343343

344-
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
344+
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
345345
suite.Require().False(isChannelKeeper)
346346

347347
// set the ics4 wrapper to the channel keeper
348348
suite.chainA.GetSimApp().TransferKeeper.WithICS4Wrapper(suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper)
349349
ics4Wrapper = suite.chainA.GetSimApp().TransferKeeper.GetICS4Wrapper()
350350

351-
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
352-
suite.Require().True(isChannelKeeper)
351+
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
353352
}

modules/core/02-client/genesis.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// InitGenesis initializes the ibc client submodule's state from a provided genesis
1515
// state.
16-
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
16+
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) {
1717
if err := gs.Params.Validate(); err != nil {
1818
panic(fmt.Errorf("invalid ibc client genesis state parameters: %v", err))
1919
}
@@ -61,7 +61,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
6161
// ExportGenesis returns the ibc client submodule's exported genesis.
6262
// NOTE: the export process is not optimized, it will iterate three
6363
// times over the 02-client sub-store.
64-
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
64+
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) types.GenesisState {
6565
genClients := k.GetAllGenesisClients(ctx)
6666
clientsMetadata, err := k.GetAllClientMetadata(ctx, genClients)
6767
if err != nil {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// client identifier. The light client module is responsible for setting any client-specific data in the store
1818
// via the Initialize method. This includes the client state, initial consensus state and any associated
1919
// metadata. The generated client identifier will be returned if a client was successfully initialized.
20-
func (k Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, consensusState []byte) (string, error) {
20+
func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, consensusState []byte) (string, error) {
2121
if clientType == exported.Localhost {
2222
return "", errorsmod.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientType)
2323
}
@@ -60,7 +60,7 @@ func (k Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, co
6060
}
6161

6262
// UpdateClient updates the consensus state and the state root from a provided header.
63-
func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error {
63+
func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error {
6464
if status := k.GetClientStatus(ctx, clientID); status != exported.Active {
6565
return errorsmod.Wrapf(types.ErrClientNotActive, "cannot update client (%s) with status %s", clientID, status)
6666
}
@@ -122,7 +122,7 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exporte
122122

123123
// UpgradeClient upgrades the client to a new client state if this new client was committed to
124124
// by the old client at the specified upgrade height
125-
func (k Keeper) UpgradeClient(
125+
func (k *Keeper) UpgradeClient(
126126
ctx sdk.Context,
127127
clientID string,
128128
upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof []byte,
@@ -167,7 +167,7 @@ func (k Keeper) UpgradeClient(
167167
// is responsible for validating the parameters of the substitute (ensuring they match the subject's parameters)
168168
// as well as copying the necessary consensus states from the substitute to the subject client store.
169169
// The substitute must be Active and the subject must not be Active.
170-
func (k Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error {
170+
func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error {
171171
if status := k.GetClientStatus(ctx, subjectClientID); status == exported.Active {
172172
return errorsmod.Wrapf(types.ErrInvalidRecoveryClient, "cannot recover %s subject client", exported.Active)
173173
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ import (
77

88
// UnmarshalClientState attempts to decode and return an ClientState object from
99
// raw encoded bytes.
10-
func (k Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) {
10+
func (k *Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) {
1111
return types.UnmarshalClientState(k.cdc, bz)
1212
}
1313

1414
// MustUnmarshalClientState attempts to decode and return an ClientState object from
1515
// raw encoded bytes. It panics on error.
16-
func (k Keeper) MustUnmarshalClientState(bz []byte) exported.ClientState {
16+
func (k *Keeper) MustUnmarshalClientState(bz []byte) exported.ClientState {
1717
return types.MustUnmarshalClientState(k.cdc, bz)
1818
}
1919

2020
// UnmarshalConsensusState attempts to decode and return an ConsensusState object from
2121
// raw encoded bytes.
22-
func (k Keeper) UnmarshalConsensusState(bz []byte) (exported.ConsensusState, error) {
22+
func (k *Keeper) UnmarshalConsensusState(bz []byte) (exported.ConsensusState, error) {
2323
return types.UnmarshalConsensusState(k.cdc, bz)
2424
}
2525

2626
// MustUnmarshalConsensusState attempts to decode and return an ConsensusState object from
2727
// raw encoded bytes. It panics on error.
28-
func (k Keeper) MustUnmarshalConsensusState(bz []byte) exported.ConsensusState {
28+
func (k *Keeper) MustUnmarshalConsensusState(bz []byte) exported.ConsensusState {
2929
return types.MustUnmarshalConsensusState(k.cdc, bz)
3030
}
3131

3232
// MustMarshalClientState attempts to encode an ClientState object and returns the
3333
// raw encoded bytes. It panics on error.
34-
func (k Keeper) MustMarshalClientState(clientState exported.ClientState) []byte {
34+
func (k *Keeper) MustMarshalClientState(clientState exported.ClientState) []byte {
3535
return types.MustMarshalClientState(k.cdc, clientState)
3636
}
3737

3838
// MustMarshalConsensusState attempts to encode an ConsensusState object and returns the
3939
// raw encoded bytes. It panics on error.
40-
func (k Keeper) MustMarshalConsensusState(consensusState exported.ConsensusState) []byte {
40+
func (k *Keeper) MustMarshalConsensusState(consensusState exported.ConsensusState) []byte {
4141
return types.MustMarshalConsensusState(k.cdc, consensusState)
4242
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
var _ types.QueryServer = (*Keeper)(nil)
2626

2727
// ClientState implements the Query/ClientState gRPC method
28-
func (k Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
28+
func (k *Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
2929
if req == nil {
3030
return nil, status.Error(codes.InvalidArgument, "empty request")
3131
}
@@ -56,7 +56,7 @@ func (k Keeper) ClientState(c context.Context, req *types.QueryClientStateReques
5656
}
5757

5858
// ClientStates implements the Query/ClientStates gRPC method
59-
func (k Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) {
59+
func (k *Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequest) (*types.QueryClientStatesResponse, error) {
6060
if req == nil {
6161
return nil, status.Error(codes.InvalidArgument, "empty request")
6262
}
@@ -100,7 +100,7 @@ func (k Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequ
100100
}
101101

102102
// ConsensusState implements the Query/ConsensusState gRPC method
103-
func (k Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) {
103+
func (k *Keeper) ConsensusState(c context.Context, req *types.QueryConsensusStateRequest) (*types.QueryConsensusStateResponse, error) {
104104
if req == nil {
105105
return nil, status.Error(codes.InvalidArgument, "empty request")
106106
}
@@ -147,7 +147,7 @@ func (k Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState
147147
}
148148

149149
// ConsensusStates implements the Query/ConsensusStates gRPC method
150-
func (k Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) {
150+
func (k *Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStatesRequest) (*types.QueryConsensusStatesResponse, error) {
151151
if req == nil {
152152
return nil, status.Error(codes.InvalidArgument, "empty request")
153153
}
@@ -191,7 +191,7 @@ func (k Keeper) ConsensusStates(c context.Context, req *types.QueryConsensusStat
191191
}
192192

193193
// ConsensusStateHeights implements the Query/ConsensusStateHeights gRPC method
194-
func (k Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) {
194+
func (k *Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsensusStateHeightsRequest) (*types.QueryConsensusStateHeightsResponse, error) {
195195
if req == nil {
196196
return nil, status.Error(codes.InvalidArgument, "empty request")
197197
}
@@ -230,7 +230,7 @@ func (k Keeper) ConsensusStateHeights(c context.Context, req *types.QueryConsens
230230
}
231231

232232
// ClientStatus implements the Query/ClientStatus gRPC method
233-
func (k Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) {
233+
func (k *Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequest) (*types.QueryClientStatusResponse, error) {
234234
if req == nil {
235235
return nil, status.Error(codes.InvalidArgument, "empty request")
236236
}
@@ -248,7 +248,7 @@ func (k Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ
248248
}
249249

250250
// ClientParams implements the Query/ClientParams gRPC method
251-
func (k Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) {
251+
func (k *Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsRequest) (*types.QueryClientParamsResponse, error) {
252252
ctx := sdk.UnwrapSDKContext(c)
253253
params := k.GetParams(ctx)
254254

@@ -258,7 +258,7 @@ func (k Keeper) ClientParams(c context.Context, _ *types.QueryClientParamsReques
258258
}
259259

260260
// UpgradedClientState implements the Query/UpgradedClientState gRPC method
261-
func (k Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) {
261+
func (k *Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedClientStateRequest) (*types.QueryUpgradedClientStateResponse, error) {
262262
if req == nil {
263263
return nil, status.Error(codes.InvalidArgument, "empty request")
264264
}
@@ -293,7 +293,7 @@ func (k Keeper) UpgradedClientState(c context.Context, req *types.QueryUpgradedC
293293
}
294294

295295
// UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method
296-
func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
296+
func (k *Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) {
297297
if req == nil {
298298
return nil, status.Error(codes.InvalidArgument, "empty request")
299299
}
@@ -325,7 +325,7 @@ func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgrad
325325
// VerifyMembership implements the Query/VerifyMembership gRPC method
326326
// NOTE: Any state changes made within this handler are discarded by leveraging a cached context. Gas is consumed for underlying state access.
327327
// This gRPC method is intended to be used within the context of the state machine and delegates to light clients to verify proofs.
328-
func (k Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMembershipRequest) (*types.QueryVerifyMembershipResponse, error) {
328+
func (k *Keeper) VerifyMembership(c context.Context, req *types.QueryVerifyMembershipRequest) (*types.QueryVerifyMembershipResponse, error) {
329329
if req == nil {
330330
return nil, status.Error(codes.InvalidArgument, "empty request")
331331
}

0 commit comments

Comments
 (0)