Skip to content

Commit

Permalink
refactor: start using KVStoreService for interchaintxs module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Nov 4, 2024
1 parent 6d86125 commit 0733242
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 25 deletions.
6 changes: 2 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(

appKeepers.FeeRefunderKeeper = feerefunderkeeper.NewKeeper(
appCodec,
appKeepers.keys[feetypes.StoreKey],
appKeepers.memKeys[feetypes.MemStoreKey],
runtime.NewKVStoreService(appKeepers.keys[feetypes.StoreKey]),
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down Expand Up @@ -381,8 +380,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(

appKeepers.InterchainTxsKeeper = interchaintxskeeper.NewKeeper(
appCodec,
appKeepers.keys[interchaintxstypes.StoreKey],
appKeepers.memKeys[interchaintxstypes.MemStoreKey],
runtime.NewKVStoreService(appKeepers.keys[interchaintxstypes.StoreKey]),
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.ICAControllerKeeper,
icacontrollerkeeper.NewMsgServerImpl(appKeepers.ICAControllerKeeper),
Expand Down
4 changes: 2 additions & 2 deletions testutil/interchaintxs/keeper/interchaintxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
metrics2 "cosmossdk.io/store/metrics"
adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types"
db2 "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/runtime"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"cosmossdk.io/store"
Expand Down Expand Up @@ -45,8 +46,7 @@ func InterchainTxsKeeper(

k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
runtime.NewKVStoreService(storeKey),
channelKeeper,
icaControllerKeeper,
icaControllerMsgServer,
Expand Down
6 changes: 5 additions & 1 deletion x/interchaintxs/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
var err error
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.Params, err = k.GetParams(ctx)
if err != nil {
panic(err)
}

return genesis
}
7 changes: 6 additions & 1 deletion x/interchaintxs/keeper/grpc_query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types
}
ctx := sdk.UnwrapSDKContext(c)

return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
params, err := k.GetParams(ctx)
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}

return &types.QueryParamsResponse{Params: params}, err
}
11 changes: 4 additions & 7 deletions x/interchaintxs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package keeper
import (
"fmt"

"cosmossdk.io/core/store"
"cosmossdk.io/log"

storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -23,8 +23,7 @@ const (
type (
Keeper struct {
Codec codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
storeService store.KVStoreService
channelKeeper types.ChannelKeeper
feeKeeper types.FeeRefunderKeeper
icaControllerKeeper types.ICAControllerKeeper
Expand All @@ -38,8 +37,7 @@ type (

func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
storeService store.KVStoreService,
channelKeeper types.ChannelKeeper,
icaControllerKeeper types.ICAControllerKeeper,
icaControllerMsgServer types.ICAControllerMsgServer,
Expand All @@ -51,8 +49,7 @@ func NewKeeper(
) *Keeper {
return &Keeper{
Codec: cdc,
storeKey: storeKey,
memKey: memKey,
storeService: storeService,
channelKeeper: channelKeeper,
icaControllerKeeper: icaControllerKeeper,
icaControllerMsgServer: icaControllerMsgServer,
Expand Down
2 changes: 1 addition & 1 deletion x/interchaintxs/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (k Keeper) SubmitTx(goCtx context.Context, msg *ictxtypes.MsgSubmitTx) (*ic
return nil, errors.Wrapf(ictxtypes.ErrNotContract, "%s is not a contract address", msg.FromAddress)
}

params := k.GetParams(ctx)
params, _ := k.GetParams(ctx)
if uint64(len(msg.Msgs)) > params.GetMsgSubmitTxMaxMessages() {
k.Logger(ctx).Debug("SubmitTx: provided MsgSubmitTx contains more messages than allowed",
"msg", msg,
Expand Down
3 changes: 2 additions & 1 deletion x/interchaintxs/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ func TestSubmitTx(t *testing.T) {
require.Nil(t, resp)
require.ErrorContains(t, err, "is not a contract address")

params := icak.GetParams(ctx)
params, err := icak.GetParams(ctx)
require.NoError(t, err)
maxMsgs := params.GetMsgSubmitTxMaxMessages()
submitMsg.Msgs = make([]*codectypes.Any, maxMsgs+1)
wmKeeper.EXPECT().HasContractInfo(ctx, contractAddress).Return(true)
Expand Down
17 changes: 10 additions & 7 deletions x/interchaintxs/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import (
)

// GetParams get all parameters as types.Params.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params, err error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParamsKey)
if err != nil {
return params, err
}
if bz == nil {
return params
return params, nil
}

k.Codec.MustUnmarshal(bz, &params)
return params
err = k.Codec.Unmarshal(bz, &params)
return params, err
}

// SetParams set the params.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
store := k.storeService.OpenKVStore(ctx)
bz, err := k.Codec.Marshal(&params)
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion x/interchaintxs/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ func TestGetParams(t *testing.T) {
err := k.SetParams(ctx, params)
require.NoError(t, err)

require.EqualValues(t, params, k.GetParams(ctx))
keeperParams, err := k.GetParams(ctx)
require.NoError(t, err)

require.EqualValues(t, params, keeperParams)
}

0 comments on commit 0733242

Please sign in to comment.