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 types.ControllerGenesisSt
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) types.ControllerGenesisState
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,21 +2,22 @@ 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/types"
"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"
)

func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := types.ControllerGenesisState{
ActiveChannels: []types.ActiveChannel{
genesisState := icatypes.ControllerGenesisState{
ActiveChannels: []icatypes.ActiveChannel{
{
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []types.RegisteredInterchainAccount{
InterchainAccounts: []icatypes.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand All @@ -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())
}
62 changes: 36 additions & 26 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ 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/types"
"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 types.ICS4Wrapper
channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
accountKeeper types.AccountKeeper
ics4Wrapper icatypes.ICS4Wrapper
channelKeeper icatypes.ChannelKeeper
portKeeper icatypes.PortKeeper
accountKeeper icatypes.AccountKeeper

scopedKeeper capabilitykeeper.ScopedKeeper

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,
ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
accountKeeper types.AccountKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
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 All @@ -50,13 +60,13 @@ func NewKeeper(

// Logger returns the application logger, scoped to the associated module
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", host.ModuleName, types.ModuleName))
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", host.ModuleName, icatypes.ModuleName))
}

// GetAllPorts returns all ports to which the interchain accounts controller module is bound. Used in ExportGenesis
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PortKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.PortKeyPrefix))
defer iterator.Close()

var ports []string
Expand All @@ -72,7 +82,7 @@ func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
// BindPort stores the provided portID and binds to it, returning the associated capability
func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyPort(portID), []byte{0x01})
store.Set(icatypes.KeyPort(portID), []byte{0x01})

return k.portKeeper.BindPort(ctx, portID)
}
Expand All @@ -96,7 +106,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
// GetActiveChannelID retrieves the active channelID from the store keyed by the provided portID
func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyActiveChannel(portID)
key := icatypes.KeyActiveChannel(portID)

if !store.Has(key) {
return "", false
Expand All @@ -106,16 +116,16 @@ func (k Keeper) GetActiveChannelID(ctx sdk.Context, portID string) (string, bool
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []types.ActiveChannel {
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.ActiveChannelKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix))
defer iterator.Close()

var activeChannels []types.ActiveChannel
var activeChannels []icatypes.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := types.ActiveChannel{
ch := icatypes.ActiveChannel{
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}
Expand All @@ -129,13 +139,13 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []types.ActiveChannel {
// SetActiveChannelID stores the active channelID, keyed by the provided portID
func (k Keeper) SetActiveChannelID(ctx sdk.Context, portID, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyActiveChannel(portID), []byte(channelID))
store.Set(icatypes.KeyActiveChannel(portID), []byte(channelID))
}

// DeleteActiveChannelID removes the active channel keyed by the provided portID stored in state
func (k Keeper) DeleteActiveChannelID(ctx sdk.Context, portID string) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.KeyActiveChannel(portID))
store.Delete(icatypes.KeyActiveChannel(portID))
}

// IsActiveChannel returns true if there exists an active channel for the provided portID, otherwise false
Expand All @@ -147,7 +157,7 @@ func (k Keeper) IsActiveChannel(ctx sdk.Context, portID string) bool {
// GetInterchainAccountAddress retrieves the InterchainAccount address from the store keyed by the provided portID
func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyOwnerAccount(portID)
key := icatypes.KeyOwnerAccount(portID)

if !store.Has(key) {
return "", false
Expand All @@ -157,15 +167,15 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str
}

// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []types.RegisteredInterchainAccount {
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredInterchainAccount {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.OwnerKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix))

var interchainAccounts []types.RegisteredInterchainAccount
var interchainAccounts []icatypes.RegisteredInterchainAccount
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

acc := types.RegisteredInterchainAccount{
acc := icatypes.RegisteredInterchainAccount{
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}
Expand All @@ -179,5 +189,5 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []types.RegisteredInte
// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated portID
func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, portID string, address string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyOwnerAccount(portID), []byte(address))
store.Set(icatypes.KeyOwnerAccount(portID), []byte(address))
}
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