Skip to content

Commit

Permalink
feat: added check for wildcard * to allow all message types (cosmos#1512
Browse files Browse the repository at this point in the history
)

* added check for wildcard * to allow all message types

* update docs

* nit
  • Loading branch information
charleenfei committed Jun 9, 2022
1 parent 2c76973 commit 08d91ad
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware.
* (modules/apps/29-fee) [\#1230](https://github.com/cosmos/ibc-go/pull/1230) Adding CLI command for getting incentivized packets for a specific channel-id.
* (modules/apps/transfer) [\#1416](https://github.com/cosmos/ibc-go/pull/1416) Adding gRPC endpoint for getting an escrow account for a given port-id and channel-id.
* (modules/apps/27-interchain-accounts) [\#1512](https://github.com/cosmos/ibc-go/pull/1512) Allowing ICA modules to handle all message types with "*".

### Bug Fixes

Expand Down
8 changes: 8 additions & 0 deletions docs/apps/interchain-accounts/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ For example, a Cosmos SDK based chain that elects to provide hosted Interchain A
"host_enabled": true,
"allow_messages": ["/cosmos.staking.v1beta1.MsgDelegate", "/cosmos.gov.v1beta1.MsgVote"]
}
```
There is also a special wildcard `"*"` message type which allows any type of message to be executed by the interchain account. This must be the only message in the `allow_messages` array.

```
"params": {
"host_enabled": true,
"allow_messages": ["*"]
}
```
39 changes: 39 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
malleate func()
expPass bool
}{
{
"interchain account successfully executes an arbitrary message type using the * (allow all message types) param",
func() {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

// Populate the gov keeper in advance with an active proposal
testProposal := &govtypes.TextProposal{
Title: "IBC Gov Proposal",
Description: "tokens for all!",
}

proposal, err := govtypes.NewProposal(testProposal, govtypes.DefaultStartingProposalID, time.Now(), time.Now().Add(time.Hour))
suite.Require().NoError(err)

suite.chainB.GetSimApp().GovKeeper.SetProposal(suite.chainB.GetContext(), proposal)
suite.chainB.GetSimApp().GovKeeper.ActivateVotingPeriod(suite.chainB.GetContext(), proposal)

msg := &govtypes.MsgVote{
ProposalId: govtypes.DefaultStartingProposalID,
Voter: interchainAccountAddr,
Option: govtypes.OptionYes,
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []sdk.Msg{msg})
suite.Require().NoError(err)

icaPacketData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{"*"})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
{
"interchain account successfully executes banktypes.MsgSend",
func() {
Expand Down
5 changes: 5 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const (

// ContainsMsgType returns true if the sdk.Msg TypeURL is present in allowMsgs, otherwise false
func ContainsMsgType(allowMsgs []string, msg sdk.Msg) bool {
// check that wildcard * option for allowing all message types is the only string in the array, if so, return true
if len(allowMsgs) == 1 && allowMsgs[0] == "*" {
return true
}

for _, v := range allowMsgs {
if v == sdk.MsgTypeURL(msg) {
return true
Expand Down

0 comments on commit 08d91ad

Please sign in to comment.