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

chore: adding IsMiddlewareEnabled to ActiveChannel genesis type #2177

Merged
merged 9 commits into from
Sep 8, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (apps/27-interchain-accounts) [\#2146](https://github.com/cosmos/ibc-go/pull/2146) ICS27 controller now claims the channel capability passed via ibc core, and passes `nil` to the underlying app callback. The channel capability arg in `SendTx` is now ignored and looked up internally.
* (apps/27-interchain-accounts) [\#2134](https://github.com/cosmos/ibc-go/pull/2134) Adding upgrade handler to ICS27 `controller` submodule for migration of channel capabilities. This upgrade handler migrates ownership of channel capabilities from the underlying application to the ICS27 `controller` submodule.
* (apps/27-interchain-accounts) [\#2157](https://github.com/cosmos/ibc-go/pull/2157) Adding `IsMiddlewareEnabled` functionality to enforce calls to ICS27 msg server to *not* route to the underlying application.
* (apps/27-interchain-accounts) [\#2177](https://github.com/cosmos/ibc-go/pull/2177) Adding `IsMiddlewareEnabled` flag to interchain accounts `ActiveChannel` genesis type.

### Features

Expand Down
4 changes: 3 additions & 1 deletion docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1716,14 +1716,16 @@ The following parameters may be used to disable the host submodule.
<a name="ibc.applications.interchain_accounts.genesis.v1.ActiveChannel"></a>

### ActiveChannel
ActiveChannel contains a connection ID, port ID and associated active channel ID
ActiveChannel contains a connection ID, port ID and associated active channel ID, as well as boolean flag to indicate
if the channel is middleware enabled


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `connection_id` | [string](#string) | | |
| `port_id` | [string](#string) | | |
| `channel_id` | [string](#string) | | |
| `is_middleware_enabled` | [bool](#bool) | | |



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGe

for _, ch := range state.ActiveChannels {
keeper.SetActiveChannelID(ctx, ch.ConnectionId, ch.PortId, ch.ChannelId)

if ch.IsMiddlewareEnabled {
keeper.SetMiddlewareEnabled(ctx, ch.PortId, ch.ChannelId)
}
}

for _, acc := range state.InterchainAccounts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
genesisState := genesistypes.ControllerGenesisState{
ActiveChannels: []genesistypes.ActiveChannel{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
IsMiddlewareEnabled: true,
},
},
InterchainAccounts: []genesistypes.RegisteredInterchainAccount{
Expand All @@ -34,6 +35,9 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
suite.Require().True(found)
suite.Require().Equal(ibctesting.FirstChannelID, channelID)

isMiddlewareEnabled := suite.chainA.GetSimApp().ICAControllerKeeper.IsMiddlewareEnabled(suite.chainA.GetContext(), TestPortID, ibctesting.FirstChannelID)
suite.Require().True(isMiddlewareEnabled)

accountAdrr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID)
suite.Require().True(found)
suite.Require().Equal(TestAccAddress.String(), accountAdrr)
Expand All @@ -56,6 +60,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {

suite.Require().Equal(path.EndpointA.ChannelID, genesisState.ActiveChannels[0].ChannelId)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.ActiveChannels[0].PortId)
suite.Require().True(genesisState.ActiveChannels[0].IsMiddlewareEnabled)

suite.Require().Equal(TestAccAddress.String(), genesisState.InterchainAccounts[0].AccountAddress)
suite.Require().Equal(path.EndpointA.ChannelConfig.PortID, genesisState.InterchainAccounts[0].PortId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChann
keySplit := strings.Split(string(iterator.Key()), "/")

ch := genesistypes.ActiveChannel{
ConnectionId: keySplit[2],
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
ConnectionId: keySplit[2],
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
IsMiddlewareEnabled: k.IsMiddlewareEnabled(ctx, keySplit[1], string(iterator.Value())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, I think it'd probably be wise to set these key splits/iterator values to variables for readability purposes. I don't think it needs to change as this is a problem throughout our codebase (keysplit should probably be a parse func)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! :)

}

activeChannels = append(activeChannels, ch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

expectedChannels := []genesistypes.ActiveChannel{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
ChannelId: path.EndpointA.ChannelID,
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
ChannelId: path.EndpointA.ChannelID,
IsMiddlewareEnabled: true,
},
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: expectedPortID,
ChannelId: expectedChannelID,
ConnectionId: ibctesting.FirstConnectionID,
PortId: expectedPortID,
ChannelId: expectedChannelID,
IsMiddlewareEnabled: false,
},
}

Expand Down
137 changes: 91 additions & 46 deletions modules/apps/27-interchain-accounts/genesis/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ message HostGenesisState {
ibc.applications.interchain_accounts.host.v1.Params params = 4 [(gogoproto.nullable) = false];
}

// ActiveChannel contains a connection ID, port ID and associated active channel ID
// ActiveChannel contains a connection ID, port ID and associated active channel ID, as well as a boolean flag to indicate
// if the channel is middleware enabled
message ActiveChannel {
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
string port_id = 2 [(gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""];
string connection_id = 1 [(gogoproto.moretags) = "yaml:\"connection_id\""];
string port_id = 2 [(gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""];
bool is_middleware_enabled = 4 [(gogoproto.moretags) = "yaml:\"is_middleware_enabled\""];
}

// RegisteredInterchainAccount contains a connection ID, port ID and associated interchain account address
Expand Down