Skip to content

Commit

Permalink
Merge branch 'interchain-accounts' into colin/569-controller-host-grp…
Browse files Browse the repository at this point in the history
…c-params
  • Loading branch information
colin-axner committed Dec 1, 2021
2 parents 209b27f + eedb0cb commit a54a911
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 9 deletions.
17 changes: 17 additions & 0 deletions modules/apps/27-interchain-accounts/controller/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"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"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
Expand Down Expand Up @@ -42,6 +43,10 @@ func (im IBCModule) OnChanOpenInit(
counterparty channeltypes.Counterparty,
version string,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
return types.ErrControllerSubModuleDisabled
}

if err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version); err != nil {
return err
}
Expand Down Expand Up @@ -78,6 +83,10 @@ func (im IBCModule) OnChanOpenAck(
channelID string,
counterpartyVersion string,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
return types.ErrControllerSubModuleDisabled
}

if err := im.keeper.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion); err != nil {
return err
}
Expand Down Expand Up @@ -130,6 +139,10 @@ func (im IBCModule) OnAcknowledgementPacket(
acknowledgement []byte,
relayer sdk.AccAddress,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
return types.ErrControllerSubModuleDisabled
}

// call underlying app's OnAcknowledgementPacket callback.
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
}
Expand All @@ -140,6 +153,10 @@ func (im IBCModule) OnTimeoutPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
return types.ErrControllerSubModuleDisabled
}

if err := im.keeper.OnTimeoutPacket(ctx, packet); err != nil {
return err
}
Expand Down
17 changes: 14 additions & 3 deletions modules/apps/27-interchain-accounts/controller/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"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"
clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
Expand Down Expand Up @@ -117,6 +118,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenInit() {
{
"success", func() {}, true,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
},
{
"ICA OnChanOpenInit fails - UNORDERED channel", func() {
channel.Ordering = channeltypes.UNORDERED
Expand Down Expand Up @@ -251,6 +257,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenAck() {
{
"success", func() {}, true,
},
{
"controller submodule disabled", func() {
suite.chainA.GetSimApp().ICAControllerKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(false))
}, false,
},
{
"ICA OnChanOpenACK fails - invalid version", func() {
path.EndpointB.ChannelConfig.Version = "invalid|version"
Expand Down Expand Up @@ -460,15 +471,15 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
packet := channeltypes.NewPacket(
[]byte("empty packet data"),
suite.chainA.SenderAccount.GetSequence(),
path.EndpointB.ChannelConfig.PortID,
path.EndpointB.ChannelID,
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
path.EndpointB.ChannelConfig.PortID,
path.EndpointB.ChannelID,
clienttypes.NewHeight(0, 100),
0,
)

ack := cbs.OnRecvPacket(suite.chainA.GetContext(), packet, TestAccAddress)
ack := cbs.OnRecvPacket(suite.chainB.GetContext(), packet, TestAccAddress)
suite.Require().Equal(tc.expPass, ack.Success())
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"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 {
// IsControllerEnabled retrieves the host enabled boolean from the paramstore.
// True is returned if the controller submodule is enabled.
func (k Keeper) IsControllerEnabled(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))
return types.NewParams(k.IsControllerEnabled(ctx))
}

// SetParams sets the total set of the host submodule parameters.
Expand Down
10 changes: 10 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// ICA Controller sentinel errors
var (
ErrControllerSubModuleDisabled = sdkerrors.Register(ModuleName, 2, "controller submodule is disabled")
)
13 changes: 13 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v2/modules/core/exported"
Expand Down Expand Up @@ -49,6 +50,10 @@ func (im IBCModule) OnChanOpenTry(
version,
counterpartyVersion string,
) error {
if !im.keeper.IsHostEnabled(ctx) {
return types.ErrHostSubModuleDisabled
}

return im.keeper.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version, counterpartyVersion)
}

Expand All @@ -68,6 +73,10 @@ func (im IBCModule) OnChanOpenConfirm(
portID,
channelID string,
) error {
if !im.keeper.IsHostEnabled(ctx) {
return types.ErrHostSubModuleDisabled
}

return im.keeper.OnChanOpenConfirm(ctx, portID, channelID)
}

Expand Down Expand Up @@ -96,6 +105,10 @@ func (im IBCModule) OnRecvPacket(
packet channeltypes.Packet,
_ sdk.AccAddress,
) ibcexported.Acknowledgement {
if !im.keeper.IsHostEnabled(ctx) {
return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled.Error())
}

ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})

if err := im.keeper.OnRecvPacket(ctx, packet); err != nil {
Expand Down
16 changes: 16 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
Expand Down Expand Up @@ -136,6 +137,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
{
"success", func() {}, true,
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
}, false,
},
{
"success: ICA auth module callback returns error", func() {
// mock module callback should not be called on host side
Expand Down Expand Up @@ -252,6 +258,11 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() {
{
"success", func() {}, true,
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
}, false,
},
{
"success: ICA auth module callback returns error", func() {
// mock module callback should not be called on host side
Expand Down Expand Up @@ -386,6 +397,11 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
{
"success", func() {}, true,
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
}, false,
},
{
"success with ICA auth module callback failure", func() {
suite.chainB.GetSimApp().ICAAuthModule.IBCApp.OnRecvPacket = func(
Expand Down
7 changes: 4 additions & 3 deletions modules/apps/27-interchain-accounts/host/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/types"
)

// GetHostEnabled retrieves the host enabled boolean from the paramstore
func (k Keeper) GetHostEnabled(ctx sdk.Context) bool {
// IsHostEnabled retrieves the host enabled boolean from the paramstore.
// True is returned if the host submodule is enabled.
func (k Keeper) IsHostEnabled(ctx sdk.Context) bool {
var res bool
k.paramSpace.Get(ctx, types.KeyHostEnabled, &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.GetHostEnabled(ctx))
return types.NewParams(k.IsHostEnabled(ctx))
}

// SetParams sets the total set of the host submodule parameters.
Expand Down
10 changes: 10 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// ICA Host sentinel errors
var (
ErrHostSubModuleDisabled = sdkerrors.Register(ModuleName, 2, "host submodule is disabled")
)

0 comments on commit a54a911

Please sign in to comment.