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

refactor: standardise sub keeper usage in core ibc #6081

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,12 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
// test if the ics4 wrapper is the channel keeper initially
ics4Wrapper := suite.chainA.GetSimApp().ICAControllerKeeper.GetICS4Wrapper()

_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

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

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {

_, isFeeKeeper := ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().True(isFeeKeeper)
_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

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

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)

_, isFeeKeeper = ics4Wrapper.(ibcfeekeeper.Keeper)
suite.Require().False(isFeeKeeper)
}
5 changes: 2 additions & 3 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
// test if the ics4 wrapper is the channel keeper initially
ics4Wrapper := suite.chainA.GetSimApp().IBCFeeKeeper.GetICS4Wrapper()

_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
_, isFeeKeeper := ics4Wrapper.(keeper.Keeper)
suite.Require().False(isFeeKeeper)

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

_, isFeeKeeper = ics4Wrapper.(keeper.Keeper)
suite.Require().True(isFeeKeeper)
_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)
}
10 changes: 5 additions & 5 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
{
"success",
func() {
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
},
nil,
},
{
"panics with nil underlying app",
func() {
_ = ibccallbacks.NewIBCMiddleware(nil, channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
_ = ibccallbacks.NewIBCMiddleware(nil, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, maxCallbackGas)
},
fmt.Errorf("underlying application does not implement %T", (*types.CallbacksCompatibleModule)(nil)),
},
{
"panics with nil contract keeper",
func() {
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, nil, maxCallbackGas)
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, nil, maxCallbackGas)
},
fmt.Errorf("contract keeper cannot be nil"),
},
Expand All @@ -61,7 +61,7 @@ func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
{
"panics with zero maxCallbackGas",
func() {
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, channelkeeper.Keeper{}, simapp.ContractKeeper{}, uint64(0))
_ = ibccallbacks.NewIBCMiddleware(ibcmock.IBCModule{}, &channelkeeper.Keeper{}, simapp.ContractKeeper{}, uint64(0))
},
fmt.Errorf("maxCallbackGas cannot be zero"),
},
Expand Down Expand Up @@ -89,7 +89,7 @@ func (s *CallbacksTestSuite) TestWithICS4Wrapper() {
cbsMiddleware.WithICS4Wrapper(s.chainA.App.GetIBCKeeper().ChannelKeeper)
ics4Wrapper := cbsMiddleware.GetICS4Wrapper()

s.Require().IsType(channelkeeper.Keeper{}, ics4Wrapper)
s.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
}

func (s *CallbacksTestSuite) TestSendPacket() {
Expand Down
5 changes: 2 additions & 3 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,12 @@ func (suite *KeeperTestSuite) TestWithICS4Wrapper() {
// test if the ics4 wrapper is the channel keeper initially
ics4Wrapper := suite.chainA.GetSimApp().TransferKeeper.GetICS4Wrapper()

_, isChannelKeeper := ics4Wrapper.(channelkeeper.Keeper)
_, isChannelKeeper := ics4Wrapper.(*channelkeeper.Keeper)
suite.Require().False(isChannelKeeper)

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

_, isChannelKeeper = ics4Wrapper.(channelkeeper.Keeper)
suite.Require().True(isChannelKeeper)
suite.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)
}
4 changes: 2 additions & 2 deletions modules/core/02-client/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// InitGenesis initializes the ibc client submodule's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, gs types.GenesisState) {
if err := gs.Params.Validate(); err != nil {
panic(fmt.Errorf("invalid ibc client genesis state parameters: %v", err))
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
// ExportGenesis returns the ibc client submodule's exported genesis.
// NOTE: the export process is not optimized, it will iterate three
// times over the 02-client sub-store.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) types.GenesisState {
genClients := k.GetAllGenesisClients(ctx)
clientsMetadata, err := k.GetAllClientMetadata(ctx, genClients)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// client identifier. The light client module is responsible for setting any client-specific data in the store
// via the Initialize method. This includes the client state, initial consensus state and any associated
// metadata. The generated client identifier will be returned if a client was successfully initialized.
func (k Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, consensusState []byte) (string, error) {
func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, consensusState []byte) (string, error) {
if clientType == exported.Localhost {
return "", errorsmod.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientType)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func (k Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, co
}

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

// UpgradeClient upgrades the client to a new client state if this new client was committed to
// by the old client at the specified upgrade height
func (k Keeper) UpgradeClient(
func (k *Keeper) UpgradeClient(
ctx sdk.Context,
clientID string,
upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof []byte,
Expand Down Expand Up @@ -167,7 +167,7 @@ func (k Keeper) UpgradeClient(
// is responsible for validating the parameters of the substitute (ensuring they match the subject's parameters)
// as well as copying the necessary consensus states from the substitute to the subject client store.
// The substitute must be Active and the subject must not be Active.
func (k Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error {
func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error {
if status := k.GetClientStatus(ctx, subjectClientID); status == exported.Active {
return errorsmod.Wrapf(types.ErrInvalidRecoveryClient, "cannot recover %s subject client", exported.Active)
}
Expand Down
12 changes: 6 additions & 6 deletions modules/core/02-client/keeper/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ import (

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

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

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

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

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

// MustMarshalConsensusState attempts to encode an ConsensusState object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalConsensusState(consensusState exported.ConsensusState) []byte {
func (k *Keeper) MustMarshalConsensusState(consensusState exported.ConsensusState) []byte {
return types.MustMarshalConsensusState(k.cdc, consensusState)
}
20 changes: 10 additions & 10 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
var _ types.QueryServer = (*Keeper)(nil)

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

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

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

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

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

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

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

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

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

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