Skip to content

Commit

Permalink
Add Enable/Disable controller/host on-chain params (#566)
Browse files Browse the repository at this point in the history
* add ica params

Add new Params type to ICA. A single test is added to check defaults and validation.
Usage within the ICA keepers is still needed

* regenerate params proto into host and controller submodules

* split params implementation into host/controller

* add keeper params logic

* Apply suggestions from code review

Co-authored-by: Damian Nolan <damiannolan@gmail.com>

* add host genesis init/export params test case

* add genesis validation for controller and host params

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
colin-axner and damiannolan authored Dec 1, 2021
1 parent e6a5583 commit d681c0d
Show file tree
Hide file tree
Showing 25 changed files with 1,129 additions and 57 deletions.
2 changes: 2 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ ControllerGenesisState defines the interchain accounts controller genesis state
| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | |
| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | |
| `ports` | [string](#string) | repeated | |
| `params` | [ibc.applications.interchain_accounts.controller.v1.Params](#ibc.applications.interchain_accounts.controller.v1.Params) | | |



Expand Down Expand Up @@ -369,6 +370,7 @@ HostGenesisState defines the interchain accounts host genesis state
| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | |
| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | |
| `port` | [string](#string) | | |
| `params` | [ibc.applications.interchain_accounts.host.v1.Params](#ibc.applications.interchain_accounts.host.v1.Params) | | |



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesi
for _, acc := range state.InterchainAccounts {
keeper.SetInterchainAccountAddress(ctx, acc.PortId, acc.AccountAddress)
}

keeper.SetParams(ctx, state.Params)
}

// ExportGenesis returns the interchain accounts controller exported genesis
Expand All @@ -35,5 +37,6 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) icatypes.ControllerGenesisSta
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
keeper.GetAllPorts(ctx),
keeper.GetParams(ctx),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v2/testing"
)
Expand Down Expand Up @@ -34,6 +35,11 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), TestPortID)
suite.Require().True(found)
suite.Require().Equal(TestAccAddress.String(), accountAdrr)

expParams := types.NewParams(false)
params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)

}

func (suite *KeeperTestSuite) TestExportGenesis() {
Expand All @@ -54,4 +60,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)

suite.Require().Equal([]string{TestPortID}, genesisState.GetPorts())

expParams := types.DefaultParams()
suite.Require().Equal(expParams, genesisState.GetParams())
}
16 changes: 13 additions & 3 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
host "github.com/cosmos/ibc-go/v2/modules/core/24-host"
)

// Keeper defines the IBC interchain accounts controller keeper
type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryCodec
storeKey sdk.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace

ics4Wrapper icatypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
Expand All @@ -32,13 +35,20 @@ type Keeper struct {

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key sdk.StoreKey,
cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
ics4Wrapper icatypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
accountKeeper icatypes.AccountKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
) Keeper {

// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
Expand Down
24 changes: 24 additions & 0 deletions modules/apps/27-interchain-accounts/controller/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/types"
)

// GetControllerEnabled retrieves the host enabled boolean from the paramstore
func (k Keeper) GetControllerEnabled(ctx sdk.Context) bool {
var res bool
k.paramSpace.Get(ctx, types.KeyControllerEnabled, &res)
return res
}

// GetParams returns the total set of the host submodule parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(k.GetControllerEnabled(ctx))
}

// SetParams sets the total set of the host submodule parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package keeper_test

import "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/types"

func (suite *KeeperTestSuite) TestParams() {
expParams := types.DefaultParams()

params := suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)

expParams.ControllerEnabled = false
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), expParams)
params = suite.chainA.GetSimApp().ICAControllerKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)
}
Loading

0 comments on commit d681c0d

Please sign in to comment.