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

Add Enable/Disable controller/host on-chain params #566

Merged
merged 10 commits into from
Dec 1, 2021
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"
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
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)
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
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